Physical Metrics
Physical Metrics¤
neojax.metrics.physical_metrics.BoundaryConsistencyMetric
¤
Boundary consistency metric.
Evaluates the prediction alignment with the boundary condition values at the locations specified by the boundary condition mask.
where \(y_{\text{bc}}\) is the boundary values, \(\hat{y}\) is the prediction, \(M\) is the boundary mask, and \(\epsilon = 10^{-7}\) is a small regularization constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
float
|
Power of the error norm. Default is 2.0. |
2.0
|
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. - learnable_weight (
bool): Flag indicating whetherweightis learnable. - p (
float): Power of the norm.
__call__(model: equinox._module._module.Module | None = None, *, target: Float[Array, 'b c ...'] | None = None, x: Float[Array, 'b in_c ...'] | None = None, pred: Float[Array, 'b c ...'] | None = None, bc_masks: Int[Array, 'b c_bc ...'] | None = None, bc_values: Float[Array, 'b t c_bc ...'] | None = None, **kwargs: typing.Any) -> Float[Array, '']
¤
Computes the boundary consistency metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | None
|
The model being trained. Optional if |
None
|
target
|
Float[Array, 'b c ...'] | None
|
Unused in boundary consistency metric. |
None
|
x
|
Float[Array, 'b in_c ...'] | None
|
Model input array shaped (batch, in_c, d1, ..., dN). |
None
|
pred
|
Float[Array, 'b c ...'] | None
|
Model prediction array shaped (batch, t, c, d1, ..., dN).
If None, the metric computes |
None
|
bc_masks
|
Int[Array, 'b c_bc ...'] | None
|
Boundary mask array shaped (batch, c_bc, d1, ..., dN). |
None
|
bc_values
|
Float[Array, 'b t c_bc ...'] | None
|
Boundary values array shaped (batch, t, c_bc, d1, ..., dN). |
None
|
**kwargs
|
Any
|
Additional arguments. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar metric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If prediction is None and either model or x is None. |
neojax.metrics.physical_metrics.ConservationMetric
¤
Conservation law metric.
Evaluates the drift/deviation of a conserved physical quantity (like mass or energy) over a time trajectory relative to the initial state.
where the deviation at time step \(t\) is:
and \(Q_t = \text{conservation_fn}(y_t, x_{\text{coords}})\) is the quantity at time step \(t\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conservation_fn
|
Callable[[Float[Array, 'c ...'], Float[Array, 'd ...']], Float[Array, '']]
|
Callable taking |
required |
mode
|
Literal['absolute', 'relative']
|
Type of drift deviation, either |
'absolute'
|
p
|
float
|
Power of the norm. Default is 2.0. |
2.0
|
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. - learnable_weight (
bool): Flag indicating whetherweightis learnable. - conservation_fn (
Callable): Conserved quantity evaluator. - mode (
Literal["absolute", "relative"]): Drift deviation mode. - p (
float): Power of the norm.
Info
May be used to ensure the model doesn't violate conservation of energy or mass.
__call__(model: equinox._module._module.Module | None = None, *, target: Float[Array, 'b c ...'] | None = None, x: Float[Array, 'b in_c ...'] | None = None, pred: Float[Array, 'b c ...'] | None = None, coords: Float[Array, 'd ...'] | None = None, **kwargs: typing.Any) -> Float[Array, '']
¤
Computes the conservation law metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | None
|
The model being trained. Optional if |
None
|
target
|
Float[Array, 'b c ...'] | None
|
Unused in conservation metric. |
None
|
x
|
Float[Array, 'b in_c ...'] | None
|
Model input array shaped (batch, in_c, d1, ..., dN). |
None
|
pred
|
Float[Array, 'b c ...'] | None
|
Model prediction array shaped (batch, t, c, d1, ..., dN).
If None, the metric computes |
None
|
coords
|
Float[Array, 'd ...'] | None
|
Physical coordinates shaped (d, d1, ..., dN). |
None
|
**kwargs
|
Any
|
Additional arguments. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar metric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If prediction is None and either model or x is None. |
neojax.metrics.physical_metrics.ResidualMetric
¤
PDE residual metric.
Evaluates the norm of the PDE residual using the user-provided residual function.
where \(R\) is the residual evaluator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residual_fn
|
Callable[[Float[Array, 't c ...'], Float[Array, 'd ...']], Float[Array, ...]]
|
Callable taking |
required |
p
|
float
|
Power of the norm. Default is 2.0. |
2.0
|
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. - learnable_weight (
bool): Flag indicating whetherweightis learnable. - residual_fn (
Callable): Residual field evaluator. - p (
float): Power of the norm.
__call__(model: equinox._module._module.Module | None = None, *, target: Float[Array, 'b c ...'] | None = None, x: Float[Array, 'b in_c ...'] | None = None, pred: Float[Array, 'b c ...'] | None = None, coords: Float[Array, 'd ...'] | None = None, **kwargs: typing.Any) -> Float[Array, '']
¤
Computes the PDE residual metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module | None
|
The model being trained. Optional if |
None
|
target
|
Float[Array, 'b c ...'] | None
|
Unused in residual metric. |
None
|
x
|
Float[Array, 'b in_c ...'] | None
|
Model input array shaped (batch, in_c, d1, ..., dN). |
None
|
pred
|
Float[Array, 'b c ...'] | None
|
Model prediction array shaped (batch, t, c, d1, ..., dN).
If None, the metric computes |
None
|
coords
|
Float[Array, 'd ...'] | None
|
Physical coordinates shaped (d, d1, ..., dN). |
None
|
**kwargs
|
Any
|
Additional arguments. |
required |
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar metric. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If prediction is None and either model or x is None. |