TargetLoss
- class pmrf.objectives.TargetLoss(predictor: Callable[[PyTree, Frequency], jnp.ndarray], target: Any, loss: Callable[[jnp.ndarray, jnp.ndarray], jnp.ndarray], *, name: str | None = None, metadata: Any = None)
Bases:
AbstractEvaluatorComputes a loss between a model prediction and some target.
- Parameters:
predictor (Callable[[jaxtyping.PyTree, pmrf.frequency.Frequency], jax.jaxlib._jax.Array]) – The predictor (e.g. another Evaluator) that extracts model features. Can be a function or a PyTree with optional parameters.
target (numpy.ndarray) – The fixed or ‘true’ target that the loss function should compare the prediction to.
loss (Callable[[jax.jaxlib._jax.Array, jax.jaxlib._jax.Array], jax.jaxlib._jax.Array]) – The loss function that takes (y_true, y_pred) and returns a loss metric. Can be a function or a PyTree with optional parameters. See
pmrf.objectives.lossesfor common losses.
- __call__(model: PyTree, frequency: Frequency, **kwargs) Array
Evaluate the model response over the specified frequency range.
- Parameters:
model (PyTree) – The parameter PyTree to evaluate.
freq (Frequency) – The frequency object defining the evaluation points.
**kwargs (dict) – Additional keyword arguments for the evaluation process.
- Returns:
The evaluated model response.
- Return type:
jnp.ndarray
- whitened_residual(model: PyTree, frequency: Frequency, **kwargs) Array
Returns the prediction error scaled so that half its squared norm is the loss.
Mathematical Formulation
For an
pmrf.objectives.losses.MSELossaveraging uniformly over the \(N\) elements of the error \(e = y - \hat{y}\),$$r = sqrt{2/N},big[mathrm{Re}(e),mathrm{Im}(e)big], qquad tfrac{1}{2}lVert r rVert^2 = frac{1}{N}sum |e|^2,$$
with the imaginary part dropped for a real error.
- Raises:
NotImplementedError – For any other loss, which is not yet supported with a least-squares minimiser.
- loss: Callable[[Array, Array], Array]
The active loss function.
- target: ndarray
The fixed target data.