kumulant

stat.score

Online evaluation metrics. Inputs are paired (prediction, truth) observations (or richer shapes for distributional metrics) and outputs are accuracy / discrimination / calibration / distributional summaries.

The calibration diagnostic (Reliability) and the calibration fixes live in com.eignex.kumulant.stat.calibration. This package is for the rest: regression errors, proper scoring rules, discrimination metrics, classification metrics, and distributional forecast diagnostics.

Regression errors

StatResultUse
mseLosscom.eignex.kumulant.stat.summary.WeightedMeanResultMean squared error; weights large errors quadratically.
maeLosscom.eignex.kumulant.stat.summary.WeightedMeanResultMean absolute error; robust median-error-style alternative.
pinballLosscom.eignex.kumulant.stat.summary.WeightedMeanResultQuantile (pinball) loss at quantile tau. The right pick when the model emits a quantile rather than a mean.

The losses are spec builders: each is Mean.foldPaired(score) for its per-pair score, so they compose, window and serialize like any other paired spec.

Binary proper scoring rules

StatResultUse
logLosscom.eignex.kumulant.stat.summary.WeightedMeanResultCross-entropy / log-likelihood. Log-likelihood-shaped objectives.
mseLosscom.eignex.kumulant.stat.summary.WeightedMeanResultBinary Brier score when inputs are probabilities and outcomes are in {0, 1}.

LogLoss penalises confident-wrong predictions much more harshly than Brier. Pick LogLoss when you want a likelihood-shaped objective; pick MSE on binary probability forecasts when you want the Brier score. The [0, 1] bound assumes probabilities and outcomes stay in that domain; MSE does not clamp inputs.

Discrimination

AucStat reports streaming ROC AUC over a fixed-resolution score histogram. AUC measures whether positives score higher than negatives on average and is calibration-agnostic; a perfectly-discriminative model can still be miscalibrated, and a perfectly-calibrated model can have mediocre AUC.

Classification

StatResultUse
AccuracyStatcom.eignex.kumulant.stat.summary.WeightedMeanResultWeighted classification accuracy: fraction of predicted == truth.
ConfusionMatrixStatConfusionMatrixResultK-by-K confusion matrix with per-class precision / recall / F1, macro / micro averages, multiclass MCC.

AccuracyStat is the O(1) shortcut when only the scalar accuracy matters. ConfusionMatrixStat is the full P/R/F1 surface with a per-class breakdown; reach for it when accuracy alone hides class-imbalance effects.

Both take a numClasses and resolve labels the same way: a pair is scored only if both sides are exactly an integer in [0, numClasses), and is ignored otherwise. That is what makes ConfusionMatrixResult.accuracy and AccuracyStat's mean comparable on the same stream. A fractional label such as 1.5, an out-of-range one, and NaN are all ignored by both rather than truncated into a class by one and refused by the other.

Distributional forecast diagnostics

The PIT (probability integral transform) family covers calibration of distributional forecasts:

  • pitHistogram(numBins) (factory in PitHistogram.kt): feeds PIT values into an equiprobable BucketHistogramStat over [0, 1]. Under correct distributional forecasts the histogram should be uniform; deviations diagnose under- or over-coverage and tail mis-specifications.

  • The functions in PitTests.kt run the standard PIT uniformity tests on the histogram (Kolmogorov-Smirnov-style summary statistics).

Use these when the model emits a CDF (not just a point estimate) and you want to check whether the predicted distribution matches the empirical one.

Compose patterns

  • mseLoss().windowed(window) for windowed regression error.

  • mseLoss().transformX(...) after a Platt or isotonic calibration step to score calibrated probabilities.

  • Auc + Reliability in parallel: AUC tells you discrimination, reliability tells you calibration. A pipeline that monitors both catches different failure modes.

Merge

All paired-mean-shaped metrics (the losses and Accuracy) merge via the underlying MeanStat's Chan-style parallel formula; exact across replicas. AucStat and ConfusionMatrixStat merge via cell-wise bin / matrix addition.

Concurrency

The mean-shaped metrics (AccuracyStat and the losses) inherit MeanStat's Welford-coupled model: locked under com.eignex.kumulant.core.Concurrency.Strict / com.eignex.kumulant.core.Concurrency.HighWrite. Under com.eignex.kumulant.core.Concurrency.Relaxed, coupled state can drift without a numerical error bound. AucStat and ConfusionMatrixStat use independent additive histogram / matrix cells; concurrent modes preserve per-cell updates, with JVM striped adders under HighWrite. Multi-cell reads are not atomic. Floating-point results depend on update order. com.eignex.kumulant.core.Concurrency.None uses plain cells.

Types

Link copied to clipboard
class AccuracyStat(val numClasses: Int, val concurrency: Concurrency = Concurrency.None) : PairedStat<WeightedMeanResult>

Streaming classification accuracy: paired (predictedClass, trueClass) aggregated as the weighted mean of 1[predicted == truth].

Link copied to clipboard
@Serializable
@SerialName(value = "AucResult")
data class AucResult(val auc: Double, val totalPositives: Double, val totalNegatives: Double, val positives: DoubleArray, val negatives: DoubleArray, val lowerBound: Double, val upperBound: Double) : Result

AUC snapshot with the per-bin counts needed for merge. auc is NaN until at least one positive and one negative have been observed; consult totalPositives / totalNegatives to detect that case.

Link copied to clipboard
class AucStat(val numBins: Int = StatDefaults.AUC_NUM_BINS, val lowerBound: Double = StatDefaults.AUC_LOWER_BOUND, val upperBound: Double = StatDefaults.AUC_UPPER_BOUND, val concurrency: Concurrency = Concurrency.None) : PairedStat<AucResult>

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).

Link copied to clipboard
@Serializable
@SerialName(value = "ConfusionMatrixResult")
data class ConfusionMatrixResult(val numClasses: Int, val counts: DoubleArray) : Result

Snapshot of a weighted K-by-K confusion matrix indexed as counts[predicted][truth].

Link copied to clipboard
class ConfusionMatrixStat(val numClasses: Int, val concurrency: Concurrency = Concurrency.None) : PairedStat<ConfusionMatrixResult>

Streaming K-by-K confusion matrix over paired (predictedClass, trueClass) observations. Class indices are resolved by asClassLabel; pairs naming anything outside [0, numClasses) are ignored.

Functions

Link copied to clipboard

Pearson chi-squared statistic for uniformity on [0, 1]. Compares the empirical bin counts against the uniform expectation total / numBins and sums (observed - expected)^2 / expected over all numBins bins.

Link copied to clipboard
fun pitHistogram(numBins: Int, concurrency: Concurrency = Concurrency.None): SeriesStat<SparseHistogramResult>

Probability Integral Transform histogram: bins F(y) (the forecast CDF evaluated at the observed truth) into numBins equal-width buckets across [0, 1]. A uniform empirical distribution indicates a well-calibrated forecaster; concentrated mass indicates miscalibration.

Link copied to clipboard

Kolmogorov-Smirnov statistic against the uniform distribution on [0, 1]. Walks every bin (including empty ones) and returns the supremum of |empCdf(x) - x| evaluated at bin upper boundaries.