credit.metrics#
credit.metrics — verification metrics for CREDIT training and rollout.
This package hosts two metric generations:
credit.metrics.gen_1.metrics— the legacy flat-tensor metrics (LatWeightedMetricsand friends) used by the Gen 1 / LES / WRF trainers. They are re-exported here so the historical importfrom credit.metrics import LatWeightedMetricskeeps working after thecredit/metrics.pymodule was folded into this package.credit.metrics.base— the Gen 2 per-variable metrics (BaseVariableMetric/BaseCombinedMetricand the built-inRMSEMetric/MSEMetric/MAEMetric/BiasMetric) that score the postblockfull_data_dictin physical units, mirroringcredit.losses.base.BaseLoss.
Construction is config-driven via load_metric(), dispatched on
conf["metrics"]["type"] (mirroring credit.losses.load_loss()).
Submodules#
Attributes#
Functions#
|
|
|
Decorator that adds an external metric class to the metric registry. |
|
Load a metric (or combined metric) from the config. |
Package Contents#
- credit.metrics.logger#
- credit.metrics.DEFAULT_METRIC_TYPES = ('rmse', 'r2score', 'bias')#
- credit.metrics.__getattr__(name)#
- credit.metrics.register_metric(metric_type)#
Decorator that adds an external metric class to the metric registry.
The class must inherit from
credit.metrics.base.BaseVariableMetric(or otherwise accept the Gen 2full_data_dictforward contract).- Parameters:
metric_type – Key used in the config
metricssection.
Example (Python decorator):
from credit.metrics import register_metric from credit.metrics.base import BaseVariableMetric @register_metric("my_metric") class MyMetric(BaseVariableMetric): ...
Example (config
custom_objects):custom_objects: MyMetric: object_type: metric module_path: mypackage.metrics metrics: type: combined args: metrics: {rmse: {}, MyMetric: {}}
- credit.metrics.load_metric(conf, validation=False)#
Load a metric (or combined metric) from the config.
Dispatches on
conf["metrics"]["type"], mirroringcredit.losses.load_loss(). The Gen 2combinedtype returns acredit.metrics.base.BaseCombinedMetricholding one or morecredit.metrics.base.BaseVariableMetricsubclasses; any other registeredtypereturns a single metric instance. When themetricssection is omitted, the default combined metric containsrmse,r2score, andbiaswith uniform variable weighting.- Parameters:
conf (dict) –
Configuration dictionary. An optional
metricssection uses the new-style{type, args}format; when omitted,rmse,r2score, andbiasare loaded with uniform variable weighting:metrics: type: combined args: metrics: {rmse: {}, mae: {}, bias: {}} var_weighting: "inverse_variance" scaler_path: "/path/scaler.json" use_latitude_weights: true latitude_weights: "/path/static.zarr"
validation (bool, optional) – Reserved for API symmetry with
credit.losses.load_loss(). Currently unused by the metric classes (metrics are not optimized).
- Returns:
A metric instance callable as
metrics(full_data_dict) -> dict[str, float].- Return type:
torch.nn.Module
- Raises:
ValueError – If the requested metric type is not in
_METRIC_REGISTRY.