kumulant

ClassCountsStat

class ClassCountsStat(val numClasses: Int, val concurrency: Concurrency = Concurrency.None) : SeriesStat<ClassCountsResult> (source)

Series stat over discrete class-index inputs; the snapshot is a weighted per-class count vector. update(value, weight) resolves value to a class index via asClassLabel, so only a Double that is exactly an integer in [0, numClasses) counts; anything else is dropped.

Use cases: the leaf aggregate behind ClassificationTree, and standalone wherever a weighted class histogram, majority vote, or empirical class distribution is wanted over a discrete stream.

Memory: O(numClasses); one adder cell per class.

Update: O(1) per observation; one class-label resolution and a single cell add.

Concurrency: Independent striped cells with deterministic bucket assignment. Exact under every level; increments commute and racing writers on the same class share the cell.

Constructors

ClassCountsStat

constructor(numClasses: Int, concurrency: Concurrency = Concurrency.None)(source)

Properties

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

numClasses

Number of classes; value must be exactly an integer in [0, numClasses).

Functions

create

open override fun create(concurrency: Concurrency? = null): ClassCountsStat(source)

Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.

merge

open override fun merge(values: ClassCountsResult, timestampNanos: Long = currentTimeNanos())(source)

Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.

Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): ClassCountsResult(source)

Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.

Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.

reset

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

validateMerge

open override fun validateMerge(values: ClassCountsResult)(source)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

Link copied to clipboard
open fun update(value: Double, weight: Double = 1.0)

Record value with weight at the current monotonic time.

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)

Record value with weight at timestampNanos.

update

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record value with weight at timestampNanos.