kumulant

AucStat

class AucStat(val numBins: Int = 256, val lowerBound: Double = 0.0, val upperBound: Double = 1.0, val concurrency: Concurrency = Concurrency.None) : PairedStat<AucResult> (source)

Streaming binary ROC-AUC by score-binning. Each update is paired (score, label) with label in {0, 1} (soft labels work too via the convex split into pos/neg weights).

Scores are bucketed into numBins equal-width buckets across [lowerBound, upperBound]; out-of-range scores clamp to the edge bin. Per read the bins are swept high-to-low and AUC is the trapezoidal area under the resulting (FPR, TPR) curve. O(numBins) per read, two atomic adds per update.

Default range is [0, 1], suitable for calibrated probability scores. For raw classifier margins, pass a wider range or pre-sigmoid the score.

Use cases: binary classifier discrimination monitoring; ranking quality independent of threshold choice. Pair with BrierScoreStat or LogLossStat for proper-scoring complements.

Memory: O(numBins); two parallel Long arrays for positives and negatives.

Update: O(1) per paired observation (one atomic add per bin slot). read() is O(numBins) for the trapezoidal sweep.

Concurrency: Two independent striped atomic adds per update. Lock-free and exact under every Concurrency level; bin assignment is deterministic per score and increments commute. The AUC computation at read() is a single-threaded sweep of the bin snapshot.

Constructors

Link copied to clipboard
constructor(numBins: Int = 256, lowerBound: Double = 0.0, upperBound: Double = 1.0, concurrency: Concurrency = Concurrency.None)

Properties

Link copied to clipboard
open override val concurrency: Concurrency

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Link copied to clipboard

Inclusive lower bound on the score range; out-of-range scores clamp to the edge bin.

Link copied to clipboard

Number of histogram bins covering [lowerBound, upperBound].

Link copied to clipboard

Inclusive upper bound on the score range; out-of-range scores clamp to the edge bin.

Functions

Link copied to clipboard
open override fun create(concurrency: Concurrency? = null): AucStat

Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.

Link copied to clipboard
open override fun merge(values: AucResult)

Fold another accumulator's snapshot into this one. The unit of merge is the immutable Result; not a live Stat; which is what lets the merge cross a process boundary. Many workers track slices of the same stream, call read periodically, ship snapshots to a coordinator, and the coordinator merges them in.

Link copied to clipboard
open override fun read(timestampNanos: Long = currentTimeNanos()): AucResult

Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.

Link copied to clipboard
open override fun reset()

Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.

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

Record an (x, y) observation with the given weight at the current time.

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

Record an (x, y) observation at timestampNanos with the given weight.

AucStat

constructor(numBins: Int = 256, lowerBound: Double = 0.0, upperBound: Double = 1.0, concurrency: Concurrency = Concurrency.None)(source)

concurrency

open override val concurrency: Concurrency(source)

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Picked at construction; immutable after.

create

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

Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.

The returned stat is independent: its state starts at the configured baseline, not at the source's current state. Each modality subtype narrows the return type so chaining doesn't lose the modality.

lowerBound

Inclusive lower bound on the score range; out-of-range scores clamp to the edge bin.

merge

open override fun merge(values: AucResult)(source)

Fold another accumulator's snapshot into this one. The unit of merge is the immutable Result; not a live Stat; which is what lets the merge cross a process boundary. Many workers track slices of the same stream, call read periodically, ship snapshots to a coordinator, and the coordinator merges them in.

Most stat families implement merge exactly (Chan-style parallel formulas for Welford, cell-wise additions for histograms, cell-wise max for HLL). SGD-based regressors merge approximately; they have no second-moment information for the principled combine. Each stat's KDoc documents its merge semantics.

numBins

Number of histogram bins covering [lowerBound, upperBound].

read

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

Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.

Snapshot consistency depends on the configured Concurrency. Under Concurrency.Strict / Concurrency.HighWrite a read locks against writers so coupled cells stay consistent. Under Concurrency.Relaxed the cells race and the snapshot may drift by ULPs of the workload under heavy contention; the drift is bounded and the read never throws.

timestampNanos is the read timestamp. Stats that don't care about time silently drop it; stats that do (rates, decay families, recency, windowed wrappers) use it as the ordering signal.

reset

open override fun reset()(source)

Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.

update

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

Record an (x, y) observation at timestampNanos with the given weight.

upperBound

Inclusive upper bound on the score range; out-of-range scores clamp to the edge bin.