Metric

interface Metric(source)

Interface for evaluation metrics that accumulate statistics over batches.

Metrics follow a stateful accumulation pattern:

  1. Call update for each batch of predictions/targets

  2. Call compute to get the accumulated metric value

  3. Call reset to start a new evaluation epoch

Example usage:

val accuracy = Accuracy()
for ((x, y) in validationData) {
val preds = model.forward(x, ctx)
accuracy.update(preds, y, ctx)
}
println("Validation accuracy: ${accuracy.compute()}")
accuracy.reset()

Inheritors

Properties

Link copied to clipboard
abstract val name: String

The name of this metric for display purposes.

Functions

Link copied to clipboard
abstract fun compute(): Double

Compute the metric value from accumulated statistics.

Link copied to clipboard
fun <T : DType, V> Metric.computeForBatch(predictions: Tensor<T, V>, targets: Tensor<out DType, *>, ctx: ExecutionContext): Double

Convenience function to compute a metric for a single batch without accumulation. Returns the metric value directly.

Link copied to clipboard
abstract fun reset()

Reset the accumulated statistics to start a fresh evaluation.

Link copied to clipboard
abstract fun <T : DType, V> update(predictions: Tensor<T, V>, targets: Tensor<out DType, *>, ctx: ExecutionContext)

Update the metric state with a batch of predictions and targets.