DataPartition

class DataPartition(val numObservations: Int, cuts: IntArray)(source)

An immutable contiguous partition of sorted data into k groups, represented by the interior cut positions rather than by copying the data.

A partition of n observations into k groups is determined by k-1 interior cuts 0 < t(1) < t(2) < ... < t(k-1) < n, with group j occupying the half-open index range (t(j-1), t(j)] in 1-based terms, or indices t(j-1) until t(j) in 0-based terms, where t(0) = 0 and t(k) = n.

No observation data is held or copied. Groups are described by index ranges into the caller's sorted array, which makes a partition cheap to create, compare, and use as a cache key. This matters because the refinement loop creates many partitions that differ in only one cut.

Instances are immutable. Derived partitions are produced by the functions that return a new instance rather than by mutation.

Parameters

numObservations

the number n of observations being partitioned, must be positive

cuts

the k-1 interior cut positions, strictly increasing and within (0, n)

Constructors

Link copied to clipboard
constructor(numObservations: Int, cuts: IntArray)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

A defensive copy of the interior cut positions, in increasing order.

Link copied to clipboard

The sizes of all groups, in group order. The elements sum to the number of observations.

Link copied to clipboard

The smallest group size in the partition.

Link copied to clipboard

The number of groups in the partition. This is one more than the number of interior cuts.

Link copied to clipboard
Link copied to clipboard

The empirical group proportions, in group order. These are the natural initial mixing weights: proportion j is the fraction of the sample assigned to group j. The elements sum to 1.0.

Functions

Link copied to clipboard
fun endIndex(group: Int): Int

The exclusive ending index, into the sorted data, of the group with the supplied zero-based index.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun groupData(data: DoubleArray, group: Int): DoubleArray

Returns a copy of the observations assigned to the supplied group. This allocates, and is intended for handing a group to an estimator. Prefer the index accessors when only the range is needed.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
fun rangeKey(group: Int): Long

A stable key identifying the index range of the supplied group. Two partitions that place a group over the same range yield the same key, which is what permits a fit computed for one partition to be reused by another.

Link copied to clipboard
fun sizeOf(group: Int): Int

The number of observations assigned to the group with the supplied zero-based index.

Link copied to clipboard
fun startIndex(group: Int): Int

The inclusive starting index, into the sorted data, of the group with the supplied zero-based index.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun withCut(cutIndex: Int, newPosition: Int): DataPartition

Returns a new partition with the cut at the supplied index moved to a new position. The receiver is not modified. The resulting cut positions must remain strictly increasing and within the data, otherwise an exception is thrown.