Lp-Metrics
Lp-Metrics¤
The standard approach for training Neural Operators is using continuous \(L^p\) norms.
LpMetric: Computes the standard \(L^p\) norm of the error over the spatial domain.RelativeLpMetric: Computes the \(L^p\) error normalized by the \(L^p\) norm of the true target function. This is standard practice in operator learning because physical data often ranges across different magnitudes, and a relative metric ensures stable gradients across samples.
neojax.metrics.lp_metrics.LpMetric
¤
General \(L^{p}\)-metric.
Computes
where \(y\) is the ground truth and \(\hat{y}\) is the model prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Union[float, int, Literal['inf']]
|
Power of the norm. Can be a number or "inf" (representing L-infinity norm). |
required |
weight
|
float
|
(Learnable) scalar weight coefficient of the metric.
The metric is computed as 'metric * weight'. Default is 1.0.
If |
1.0
|
learnable_weight
|
bool
|
Optional flag indicating whether |
False
|
Internal Attributes
These fields store the internal state of the metric.
- weight (
Float[Array, ""]): Learnable metric weight. Filter during training to prevent updates. - p (
float | int | Literal["inf"]): Power of the norm. - learnable_weight (
bool): Flag indicating whetherweightis learnable. - is_p_inf (
bool): Flag indicating ifpis infinity.
__call__(model: equinox._module._module.Module | None = None, *, target: Float[Array, 'b c ...'], x: PyTree[Float[Array, 'b ...']] | None = None, pred: Float[Array, 'b c ...'] | None = None, **kwargs: typing.Any) -> Float[Array, '']
¤
Computes the \(L^{p}\)-metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | None
|
The model being trained. Optional if |
None
|
target
|
Float[Array, 'b c ...']
|
Ground truth array shaped (batch, c, d1, ..., dN). |
required |
x
|
PyTree[Float[Array, 'b ...']] | None
|
Model input array shaped (batch, in_c, d1, ..., dN). |
None
|
pred
|
Float[Array, 'b c ...'] | None
|
Model prediction array.
If None, the metric computes |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar metric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
neojax.metrics.lp_metrics.RelativeLpMetric
¤
General relative \(L^{p}\)-metric.
Computes
where \(y\) is the ground truth and \(\hat{y}\) is the model prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Union[float, int, Literal['inf']]
|
Power of the norm. Can be a number or "inf" (representing L-infinity norm). |
required |
weight
|
float
|
(Learnable) scalar weight coefficient of the metric.
The metric is computed as 'metric * weight'. Default is 1.0.
If |
1.0
|
learnable_weight
|
bool
|
Optional flag indicating whether |
False
|
Internal Attributes
These fields store the internal state of the metric.
- weight (
Float[Array, ""]): Learnable metric weight. Filter during training to prevent updates. - p (
float | int | Literal["inf"]): Power of the norm. - learnable_weight (
bool): Flag indicating whetherweightis learnable. - is_p_inf (
bool): Flag indicating ifpis infinity.
__call__(model: equinox._module._module.Module | None = None, *, target: Float[Array, 'b c ...'], x: PyTree[Float[Array, 'b ...']] | None = None, pred: Float[Array, 'b c ...'] | None = None, **kwargs: typing.Any) -> Float[Array, '']
¤
Computes relative \(L^{p}\)-metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | None
|
The model being trained. Optional if |
None
|
target
|
Float[Array, 'b c ...']
|
Ground truth array shaped (batch, c, d1, ..., dN). |
required |
x
|
PyTree[Float[Array, 'b ...']] | None
|
Model input array shaped (batch, in_c, d1, ..., dN). |
None
|
pred
|
Float[Array, 'b c ...'] | None
|
Model prediction array.
If None, the metric computes |
None
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar metric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |