Metrics (pypielm.metrics)

Evaluation metrics.

Public surface:

from pypielm.metrics import (
    rmse, mae, relative_l2, max_error, r2_score, MetricsBundle,
)
pypielm.metrics.rmse(y_pred, y_true)[source]

Root Mean Squared Error.

\[\text{RMSE} = \sqrt{\frac{1}{N} \|\hat{u} - u\|_2^2}\]
Parameters:
  • y_pred (Tensor | ndarray) – Predicted values, shape (N,) or (N, d).

  • y_true (Tensor | ndarray) – Reference values, same shape.

Return type:

float

Returns:

Scalar RMSE.

pypielm.metrics.mae(y_pred, y_true)[source]

Mean Absolute Error.

\[\text{MAE} = \frac{1}{N} \|\hat{u} - u\|_1\]
Parameters:
Return type:

float

Returns:

Scalar MAE.

pypielm.metrics.relative_l2(y_pred, y_true, eps=1e-12)[source]

Relative L₂ error (also called normalised RMSE in the benchmark).

\[\epsilon_{L_2} = \frac{\|\hat{u} - u\|_2}{\|u\|_2 + \epsilon}\]
Parameters:
  • y_pred (Tensor | ndarray) – Predicted values.

  • y_true (Tensor | ndarray) – Reference values.

  • eps (float) – Small constant to avoid division by zero.

Return type:

float

Returns:

Scalar relative L₂ error.

pypielm.metrics.max_error(y_pred, y_true)[source]

Maximum absolute pointwise error (L∞ norm).

\[\epsilon_{\infty} = \max_i |\hat{u}_i - u_i|\]
Parameters:
Return type:

float

Returns:

Scalar L∞ error.

pypielm.metrics.r2_score(y_pred, y_true)[source]

Coefficient of determination R².

\[R^2 = 1 - \frac{\text{SS}_\text{res}}{\text{SS}_\text{tot}} = 1 - \frac{\|u - \hat{u}\|_2^2}{\|u - \bar{u}\|_2^2}\]
Parameters:
Return type:

float

Returns:

Scalar R² (1.0 is perfect, can be negative for bad models).

class pypielm.metrics.MetricsBundle(y_pred, y_true)[source]

Compute and store all standard metrics in one call.

Parameters:
  • y_pred (Tensor | ndarray) – Predicted values, shape (N,) or (N, d).

  • y_true (Tensor | ndarray) – Ground truth values, same shape.

rmse

Root mean squared error.

mae

Mean absolute error.

rel_l2

Relative L₂ error.

max_err

Maximum absolute error.

r2

Coefficient of determination.

Example:

mb = MetricsBundle(model.predict(X_test), y_test)
print(mb)
to_dict()[source]

Return metrics as a plain dictionary.

Return type:

dict[str, float]

Evaluation metrics for PDE solution accuracy.

All functions operate on torch.Tensor or array-likes and return plain Python float values for easy logging and comparison.

pypielm.metrics.metrics.rmse(y_pred, y_true)[source]

Root Mean Squared Error.

\[\text{RMSE} = \sqrt{\frac{1}{N} \|\hat{u} - u\|_2^2}\]
Parameters:
  • y_pred (Tensor | ndarray) – Predicted values, shape (N,) or (N, d).

  • y_true (Tensor | ndarray) – Reference values, same shape.

Return type:

float

Returns:

Scalar RMSE.

pypielm.metrics.metrics.mae(y_pred, y_true)[source]

Mean Absolute Error.

\[\text{MAE} = \frac{1}{N} \|\hat{u} - u\|_1\]
Parameters:
Return type:

float

Returns:

Scalar MAE.

pypielm.metrics.metrics.relative_l2(y_pred, y_true, eps=1e-12)[source]

Relative L₂ error (also called normalised RMSE in the benchmark).

\[\epsilon_{L_2} = \frac{\|\hat{u} - u\|_2}{\|u\|_2 + \epsilon}\]
Parameters:
  • y_pred (Tensor | ndarray) – Predicted values.

  • y_true (Tensor | ndarray) – Reference values.

  • eps (float) – Small constant to avoid division by zero.

Return type:

float

Returns:

Scalar relative L₂ error.

pypielm.metrics.metrics.max_error(y_pred, y_true)[source]

Maximum absolute pointwise error (L∞ norm).

\[\epsilon_{\infty} = \max_i |\hat{u}_i - u_i|\]
Parameters:
Return type:

float

Returns:

Scalar L∞ error.

pypielm.metrics.metrics.r2_score(y_pred, y_true)[source]

Coefficient of determination R².

\[R^2 = 1 - \frac{\text{SS}_\text{res}}{\text{SS}_\text{tot}} = 1 - \frac{\|u - \hat{u}\|_2^2}{\|u - \bar{u}\|_2^2}\]
Parameters:
Return type:

float

Returns:

Scalar R² (1.0 is perfect, can be negative for bad models).

class pypielm.metrics.metrics.MetricsBundle(y_pred, y_true)[source]

Bases: object

Compute and store all standard metrics in one call.

Parameters:
  • y_pred (Tensor | ndarray) – Predicted values, shape (N,) or (N, d).

  • y_true (Tensor | ndarray) – Ground truth values, same shape.

rmse

Root mean squared error.

mae

Mean absolute error.

rel_l2

Relative L₂ error.

max_err

Maximum absolute error.

r2

Coefficient of determination.

Example:

mb = MetricsBundle(model.predict(X_test), y_test)
print(mb)
to_dict()[source]

Return metrics as a plain dictionary.

Return type:

dict[str, float]