kumulant

stat.calibration

Probability calibration diagnoses how predicted probabilities differ from observed positive rates and fits a mapping to correct them. The live stats consume com.eignex.kumulant.core.PairedStat observations (prediction, label); isotonic calibration derives a curve from a reliability snapshot.

Picking a calibration method

Stat or projectionMappingReach for it when
ReliabilityStatPer-bin predicted and observed rates, plus calibration errorDiagnose calibration, plot the gaps, or retain mergeable evidence for isotonic fitting.
PlattCalibratorStatsigmoid(slope * x + intercept)Fit a smooth sigmoid with two parameters, especially when observations are scarce.
isotonicCalibrationMonotone probabilities with linear interpolation between bin midpointsFit an arbitrary monotone shape from a ReliabilityResult without a second accumulator.

The diagnostic and correction workflow

  1. Feed held-out (prediction, label) pairs to ReliabilityStat.

  2. Inspect ReliabilityResult.expectedCalibrationError and the per-bin gap.

  3. Call ReliabilityResult.isotonicCalibration to fit a monotone curve, or train PlattCalibratorStat on the pairs for a sigmoid mapping.

  4. Apply the fitted result's calibrate(rawProbability) at inference and monitor the calibrated outputs with a reliability stat.

The isotonic projection runs weighted Pool Adjacent Violators in O(numBins) time and memory. It reads the existing per-bin evidence and needs no update path or separate lifecycle.

Merge

ReliabilityStat adds per-bin sums, retaining the evidence across workers. Merge those snapshots before calling isotonicCalibration; fitting each shard and averaging curves loses the bin weights and pooling constraints. PlattCalibratorStat composes a paired-input adapter and a result projection over a one-feature logit model. It merges sample-weighted parameter vectors through its com.eignex.kumulant.stat.regression.glm.StochasticRegressionStat, an approximation to training on the combined observations.

Concurrency

ReliabilityStat uses independent atomic adds for its per-bin cells and bounds each snapshot's outcome sum by its total weight. Isotonic fitting operates on that detached snapshot. PlattCalibratorStat inherits the com.eignex.kumulant.stat.regression.glm.StochasticRegressionStat model: locked updates under com.eignex.kumulant.core.Concurrency.Strict and com.eignex.kumulant.core.Concurrency.HighWrite, asynchronous SGD under com.eignex.kumulant.core.Concurrency.Relaxed.

Types

Link copied to clipboard
@Serializable
@SerialName(value = "IsotonicCalibratorResult")
data class IsotonicCalibratorResult(val numBins: Int, val binMidpoints: DoubleArray, val probabilities: DoubleArray, val totalWeights: Double) : HasObservationCount

Isotonic calibration derived from ReliabilityResult: a non-decreasing mapping from raw score in [0, 1] to calibrated probability, derived from a binned (positives, total) histogram via Pool Adjacent Violators.

Link copied to clipboard
@Serializable
@SerialName(value = "PlattCalibratorResult")
data class PlattCalibratorResult(val slope: Double, val intercept: Double, val totalWeights: Double, val step: Long = 0) : HasObservationCount

Snapshot from PlattCalibratorStat: the learned sigmoid parameters and a helper that maps a raw classifier score to a calibrated probability.

Link copied to clipboard
@Serializable
@SerialName(value = "ReliabilityResult")
data class ReliabilityResult(val numBins: Int, val sumProbability: DoubleArray, val sumOutcome: DoubleArray, val totalWeights: DoubleArray) : Result

Per-bin reliability snapshot for a binary probabilistic classifier. Bins are equal-width over [0, 1] indexed by predicted probability. Underlying sums use weights so soft labels and importance-weighted streams compose correctly.

Link copied to clipboard
class ReliabilityStat(val numBins: Int, val concurrency: Concurrency = Concurrency.None) : PairedStat<ReliabilityResult>

Reliability diagram primitive for binary probabilistic forecasts. Paired input is (predictedProbability, outcome); predictions are bucketed into numBins equal-width bins across [0, 1]. Outcomes are typically {0, 1} but soft labels and weighted updates work uniformly.

Functions

Link copied to clipboard

Fit a monotone calibration curve to this reliability histogram using weighted Pool Adjacent Violators. Merge ReliabilityStat snapshots before fitting to retain each bin's evidence across shards.

Link copied to clipboard
fun PlattCalibratorStat(optimizer: OptimizerSpec = StatDefaults.plattOptimizer(), concurrency: Concurrency = Concurrency.None): PairedStat<PlattCalibratorResult>

Online Platt scaling: fits a one-feature logistic regression sigmoid(slope * rawScore + intercept) over paired (rawScore, label) observations where label is in {0, 1}. Use to fix the calibration of a classifier whose probability output is poorly aligned with the empirical positive rate.