mae

Contents

mae#

class braintools.fit.losses.mae(prediction, target)#

Compute the mean absolute error between two time series.

\[\mathrm{MAE} = \frac{1}{M} \sum_{i=1}^{M} |\hat y_i - y_i|.\]
Parameters:
  • prediction (Any) – Model output, e.g. of shape (n_time, n_channels).

  • target (Any) – Data of the same shape and compatible units.

Returns:

Scalar MAE; for Quantity inputs the plain magnitude in the prediction’s unit.

Return type:

Array

Raises:
  • ValueError – If the shapes differ.

  • TypeError – If only one input carries units.

  • brainunit.UnitMismatchError – If the units have different dimensions.

See also

mse, rmse

Notes

Works under jax.jit and jax.vmap; differentiable except where prediction == target (JAX uses the subgradient 0 there).

Examples

>>> import jax.numpy as jnp
>>> from braintools.fit import losses
>>> float(losses.mae(jnp.array([1., -1., 4.]), jnp.zeros(3)))
2.0