xnn.common.benchmark.metrics#

Error metrics for benchmarking, plus prediction collection.

A name -> callable registry mirrors the model registry (see models.registry) so new metrics are added without touching the core, and user-defined metrics register the same way. The built-in metrics are MAE, MSE and RMSE; each takes two flat tensors (pred, target) and returns a Python float.

collect_predictions() runs a model over a data loader once and returns the paired prediction/target tensors for each requested target quantity (energy / forces / stress), which score() then reduces with the selected metrics. Energy is scored per atom – the same size-extensive normalization the training loss uses (see train.losses.weighted_loss).

Functions

available_metrics()

List the names of all currently registered metrics.

collect_predictions(model, loader, device, ...)

Run model over loader once, pairing predictions with targets.

get_metric(name)

Look up a registered metric by name.

load_custom_metric(name, path)

Import a module:function callable and register it under name.

mae(pred, target)

Mean absolute error, mean(|pred - target|).

mse(pred, target)

Mean squared error, mean((pred - target) ** 2).

register_metric(name)

Return a decorator registering an error metric under name.

rmse(pred, target)

Root mean squared error, sqrt(mean((pred - target) ** 2)).

score(pairs, metrics)

Reduce prediction/target pairs to a flat {target_metric: value} map.