mse#
- class braintools.fit.losses.mse(prediction, target)#
Compute the mean squared error between two time series.
\[\mathrm{MSE} = \frac{1}{M} \sum_{i=1}^{M} (\hat y_i - y_i)^2,\]averaged over all
Melements (time on axis 0, any trailing shape).- Parameters:
- Returns:
Scalar MSE. For Quantity inputs it is the plain magnitude in the prediction’s unit squared (the target is converted first).
- Return type:
Array- Raises:
ValueError – If the shapes differ.
TypeError – If only one input carries units.
brainunit.UnitMismatchError – If the units have different dimensions.
Notes
Removing an initial transient is left to the caller (
Fitterdoes it). Works underjax.jitandjax.vmapand is differentiable.Examples
>>> import brainunit as u >>> import jax.numpy as jnp >>> from braintools.fit import losses >>> float(losses.mse(jnp.array([1., 2., 3.]), jnp.array([1., 2., 5.]))) 1.3333333730697632 >>> >>> float(losses.mse(jnp.ones(3) * u.mV, jnp.zeros(3) * u.volt)) 1.0