public override compute(outputs as NDArray<T>, targets as NDArray<T>, gradientScale as Double = 1.0) as LossResult<T>
Computes MSE and a same-shaped, independent output derivative. Targets must have the output shape; a [samples] target vector is also accepted for single-coordinate outputs [samples, 1]. Non-finite inputs are rejected. A mathematically overflowing loss may return infinity, and a scaled gradient may overflow its storage; fit() rejects non-finite losses and applies its existing FP16 scaling policy.
| Parameter | Description |
|---|---|
outputs | Floating tensor with a batch axis and output dimensions. |
targets | Same-precision tensor of matching shape, or a scalar vector. |
gradientScale | Finite positive multiplier applied only to derivatives. |
Unscaled mean error and scaled mean-reduced output derivative.
result = MeanSquaredError<Double>().compute(NDArray<Double>([[2.0], [4.0]]), NDArray<Double>([1.0, 2.0]))