where \(y_i\) are the reference values and \(\hat{y}_i\) are the predictions.
This implementation differs from LossMSE only by a factor of 0.5. Even
though that is mostly a choice of convenience to keep the expression for the
derivative cleaner in text books, this can have a profound influence on
training results. The implementation here is consistent with the MSE in Pytorch
and RuNNer 1. It has shown significantly improved training results for 4G
charge training.
Nodes of different colours represent the following:
Solid arrows point from a submodule to the (sub)module which it is
descended from. Dashed arrows point from a module or program unit to
modules which it uses.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a submodule to the (sub)module which it is
descended from. Dashed arrows point from a module or program unit to
modules which it uses.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a derived type to the parent type which it
extends. Dashed arrows point from a derived type to the other
types it contains as a components, with a label listing the name(s) of
said component(s).
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Where possible, edges connecting nodes are
given different colours to make them easier to distinguish in
large graphs.
Computes the sum of squared differences between predictions and
reference values: ∑(pred_i - ref_i)².
self - The MSE loss function instance
batchsize - Number of samples in the batch
prediction - Predicted values for the batch
reference - Reference (target) values for the batch
Returns: Sum of squared errors (unnormalized)
Arguments
self :
class(LossMSETorch) [in]– The MSE loss function instance
batchsize :
integer [in]– Number of samples in batch
Normalize the sum of squared errors to get the final MSE value.
Converts the sum of squared errors into the final MSE by dividing
by the total number of samples. This function handles the final
normalization step for both local and MPI-collected computations.
global_sum_loss - Sum of squared errors across all processes
global_batchsize - Total number of samples across all processes
Returns: Final normalized MSE value
Arguments
global_sum_loss :
real(DP) [in]– Sum of squared errors
global_batchsize :
integer [in]– Total number of samples
Calculate the gradient of MSE with respect to predictions.
Computes the derivative of the MSE loss function:
[ \frac{\partial \text{MSE}}{\partial \hat{y}_i} = \frac{1}{n} 2 * (\hat{y}_i - y_i) ]
The derivative is linear in the prediction error, normalized by
the batch size. This provides smooth gradients suitable for
gradient-based optimization algorithms.
self - The MSE loss function instance
batchsize - Number of samples in the batch
prediction - Predicted values for the batch
reference - Reference (target) values for the batch
Returns: Gradient vector with respect to each prediction
Arguments
self :
class(LossMSETorch) [in]– The MSE loss function instance
batchsize :
integer [in]– Number of samples in batch