pulsatrix
Loading...
Searching...
No Matches
pulsatrix::MSELoss Class Reference

MSE = mean((prediction - target)^2). More...

#include <mse_loss.hpp>

Public Member Functions

 MSELoss (DeviceBackend *backend)
 Constructs an MSE loss.
 
float forward (const Tensor &prediction, const Tensor &target)
 Computes the loss value and caches prediction/target for backward().
 
Tensor backward () const
 Computes the gradient w.r.t. the prediction: (2/n) * (prediction - target).
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ MSELoss()

pulsatrix::MSELoss::MSELoss ( DeviceBackend *  backend)
explicit

Constructs an MSE loss.

Parameters
backendBackend to compute through. Not owned; must outlive this loss.

Member Function Documentation

◆ 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
predictionModel output.
targetGround truth. Must match prediction's shape.
Returns
The scalar MSE value.
Exceptions
std::invalid_argumentif 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: