Implementation of the root mean squared error (RMSE) loss/cost function.
The Root Mean Squared Error (RMSE) is the square root of the Mean Squared Error (MSE),
giving a measure in the same units as the predicted values. RMSE is defined as:
where \(y_i\) are the reference values and \(\hat{y}_i\) are the predictions. RMSE
emphasizes large errors more than MAE and less than MSE, making it a compromise between
the two.
Properties:
- Provides error measure in the same units as the target variable
- Sensitive to outliers (but less then MSE)
- Has same scale as target values
Use cases:
- Standard evaluation metric for regression tasks
- When interpretability in the same units of targets is needed
- Balancing sensitivity to outliers between MSE and MAE. If a large penalty
on outliers is required MSE is a better choice.
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)². This is the unnormalized
form that will be normalized and square-rooted by the collect function.
self - The RMSE 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(LossRMSE) [in]– The RMSE loss function instance
batchsize :
integer [in]– Number of samples in batch
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.
Normalize and take square root to get the final RMSE value.
Converts the sum of squared errors into the final RMSE by dividing
by the total number of samples and taking the square root. 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 RMSE value
Arguments
global_sum_loss :
real(DP) [in]– Sum of squared errors
global_batchsize :
integer [in]– Total number of samples
Calculate the gradient of RMSE with respect to predictions.
Computes the derivative of the RMSE loss function:
[ \frac{\partial \text{RMSE}}{\partial \hat{y}_i} = \frac{\hat{y}_i - y_i}{n \cdot \text{RMSE}} ]
The derivative involves the prediction error normalized by both the batch size
and the current RMSE value. This provides gradients that adapt based on the
overall error magnitude.
self - The RMSE 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(LossRMSE) [in]– The RMSE loss function instance
batchsize :
integer [in]– Number of samples in batch