MSE = mean((prediction - target)^2).
More...
#include <mse_loss.hpp>
MSE = mean((prediction - target)^2).
- Note
- Not a Module subclass. Losses are the seed point relevance/gradient propagation starts from, not something a
propagate_relevance rule is defined for – LRP explains a model's prediction, not the loss function used to train it. Deliberate scope decision (see mission_conv2d_losses.md's Objective 1), not an oversight.
◆ MSELoss()
Constructs an MSE loss.
- Parameters
-
| backend | Backend to compute through. Not owned; must outlive this loss. |
◆ backward()
| Tensor pulsatrix::MSELoss::backward |
( |
| ) |
const |
Computes the gradient w.r.t. the prediction: (2/n) * (prediction - target).
- Returns
- Gradient tensor, same shape as the prediction passed to forward().
- Note
- Must be called after forward() – uses the cached prediction/target.
-
Device-generic; the gradient is on the prediction's device.
◆ forward()
| float pulsatrix::MSELoss::forward |
( |
const Tensor & |
prediction, |
|
|
const Tensor & |
target |
|
) |
| |
Computes the loss value and caches prediction/target for backward().
- Parameters
-
| prediction | Model output. |
| target | Ground truth. Must match prediction's shape. |
- Returns
- The scalar MSE value.
- Exceptions
-
| std::invalid_argument | if prediction and target are on different devices. |
- Note
- Device-generic: runs on Cpu, Cuda or Hip tensors (GPU-native-kernels Mission 1).
The documentation for this class was generated from the following file: