Skip to content

Metrics: Per-Channel Evaluation

Per-channel evaluation of trained predictions, mirroring the loss mask discipline: only cells the bucket mask marks as real measurements count. compute_metrics(predictions, dataset) returns one ChannelMetrics per output channel with MSE, RMSE, MAE and R^2; print_metrics renders them as a table.


ChannelMetrics

from jaxhybridmodels.metrics import ChannelMetrics  ·  also re-exported as jaxhybridmodels.ChannelMetrics

python
ChannelMetrics(
    name: 'str',
    n: "Int[Array, '']",
    mse: "Float[Array, '']",
    rmse: "Float[Array, '']",
    mae: "Float[Array, '']",
    r2: "Float[Array, '']",
) -> None

Metrics for a single output channel.

Attributes

FieldTypeDescription
namestrChannel name from dataset.output_channel_names.
nInt[Array, ""]Scalar number of observed (mask=True) cells behind the stats. It is a JAX scalar so the complete metrics result can pass through jit.
mse, rmse, maeFloat[Array, ""]Error of predicted - observed over the masked cells.
r2Float[Array, ""]1 - SS_res/SS_tot; nan when the observations are constant and SS_tot is zero.

Source


compute_metrics()

from jaxhybridmodels.metrics import compute_metrics  ·  also re-exported as jaxhybridmodels.compute_metrics

python
compute_metrics(
    predictions: "tuple[Float[Array, 'N T D'], ...]",
    dataset: 'Dataset',
) -> dict[str, ChannelMetrics]

Collapse bucketed predictions into per-channel summary stats.

Parameters

ParameterTypeDescription
predictionstuple of arrays, one per bucketFrom predict_dataset; each entry is [N_b, T_b, D] matching its BucketPayload.
datasetDatasetThe dataset that produced predictions. Read for masks, observations, and channel names.

Returns

ItemTypeDescription
dict[str, ChannelMetrics]Keyed by channel, in dataset.output_channel_names order.

Source


from jaxhybridmodels.metrics import print_metrics  ·  also re-exported as jaxhybridmodels.print_metrics

python
print_metrics(
    metrics: 'dict[str, ChannelMetrics]',
    header: 'str | None' = None,
) -> None

Print a metrics table, one row per channel.

Format::

{header}
  channel        n          MSE         RMSE          MAE       R^2
  conc          42   1.2345e-03   3.5135e-02   2.7012e-02    0.9876
  d43           17   1.4321e+00   1.1967e+00   8.9120e-01    0.4231

Scientific notation throughout, so one template stays readable across the example suite's scales, from omega ~ O(1) to nucleation rates spanning nine decades.

Source

Released under the BSD-3-Clause License.