Skip to content

mod_loss_rmse

Lines: 67 | Visibility: private

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:

\[ \text{RMSE} = \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2} \]

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.

author: Alexander Knoll

Dependencies

Uses

module~~mod_loss_rmse~~UsesGraph module~mod_loss_rmse mod_loss_rmse module~mod_loss_abstract mod_loss_abstract module~mod_loss_rmse->module~mod_loss_abstract module~mod_precision mod_precision module~mod_loss_rmse->module~mod_precision module~mod_loss_abstract->module~mod_precision module~mod_mpi mod_mpi module~mod_loss_abstract->module~mod_mpi iso_c_binding iso_c_binding module~mod_precision->iso_c_binding iso_fortran_env iso_fortran_env module~mod_precision->iso_fortran_env module~mod_mpi->module~mod_precision mpi_f08 mpi_f08 module~mod_mpi->mpi_f08

Used By

module~~mod_loss_rmse~~UsedByGraph module~mod_loss_rmse mod_loss_rmse module~mod_lossfunctions mod_lossfunctions module~mod_lossfunctions->module~mod_loss_rmse module~mod_abstract_kalman_filter mod_abstract_kalman_filter module~mod_abstract_kalman_filter->module~mod_lossfunctions module~mod_adam mod_adam module~mod_adam->module~mod_lossfunctions module~mod_gradient_descent mod_gradient_descent module~mod_gradient_descent->module~mod_lossfunctions module~mod_initialize mod_initialize module~mod_initialize->module~mod_lossfunctions module~mod_optimizers mod_optimizers module~mod_initialize->module~mod_optimizers module~mod_nada_opt mod_nada_opt module~mod_nada_opt->module~mod_lossfunctions module~mod_stochastic_gradient_descent mod_stochastic_gradient_descent module~mod_stochastic_gradient_descent->module~mod_lossfunctions module~mod_train_mode mod_train_mode module~mod_train_mode->module~mod_lossfunctions module~mod_train_mode->module~mod_initialize module~mod_train_loop_4g_charges mod_train_loop_4g_charges module~mod_train_mode->module~mod_train_loop_4g_charges module~mod_train_loop_atomic_property mod_train_loop_atomic_property module~mod_train_mode->module~mod_train_loop_atomic_property module~mod_train_loop_short_range mod_train_loop_short_range module~mod_train_mode->module~mod_train_loop_short_range module~mod_write_outfiles_training mod_write_outfiles_training module~mod_train_mode->module~mod_write_outfiles_training program~runner RuNNer program~runner->module~mod_lossfunctions program~runner->module~mod_initialize program~runner->module~mod_train_mode module~mod_predict_mode mod_predict_mode program~runner->module~mod_predict_mode module~mod_kalman_filter mod_kalman_filter module~mod_kalman_filter->module~mod_abstract_kalman_filter module~mod_kalman_filter_std mod_kalman_filter_std module~mod_kalman_filter_std->module~mod_abstract_kalman_filter module~mod_optimizers->module~mod_adam module~mod_optimizers->module~mod_gradient_descent module~mod_optimizers->module~mod_nada_opt module~mod_optimizers->module~mod_stochastic_gradient_descent module~mod_optimizers->module~mod_kalman_filter module~mod_optimizers->module~mod_kalman_filter_std module~mod_predict_mode->module~mod_initialize module~mod_write_outfiles mod_write_outfiles module~mod_predict_mode->module~mod_write_outfiles module~mod_runner_interface_bindings mod_runner_interface_bindings module~mod_runner_interface_bindings->module~mod_initialize module~mod_train_energy_multiple_structures mod_train_energy_multiple_structures module~mod_train_energy_multiple_structures->module~mod_initialize module~mod_train_forces_multiple_structures mod_train_forces_multiple_structures module~mod_train_forces_multiple_structures->module~mod_initialize module~mod_train_forces_multiple_structures->module~mod_train_energy_multiple_structures module~mod_train_loop_4g_charges->module~mod_initialize module~mod_cost_calculator mod_cost_calculator module~mod_train_loop_4g_charges->module~mod_cost_calculator module~mod_output_files_and_cost_4g_charges mod_output_files_and_cost_4g_charges module~mod_train_loop_4g_charges->module~mod_output_files_and_cost_4g_charges module~mod_train_loop_atomic_property->module~mod_initialize module~mod_train_loop_atomic_property->module~mod_cost_calculator module~mod_output_files_and_cost mod_output_files_and_cost module~mod_train_loop_atomic_property->module~mod_output_files_and_cost module~mod_train_loop_short_range->module~mod_initialize module~mod_train_loop_short_range->module~mod_train_energy_multiple_structures module~mod_train_loop_short_range->module~mod_train_forces_multiple_structures module~mod_train_loop_short_range->module~mod_cost_calculator module~mod_train_loop_short_range->module~mod_output_files_and_cost module~mod_output_files_and_cost_4g_short_range mod_output_files_and_cost_4g_short_range module~mod_train_loop_short_range->module~mod_output_files_and_cost_4g_short_range module~mod_write_outfiles->module~mod_initialize module~mod_lammps_interface mod_lammps_interface module~mod_lammps_interface->module~mod_runner_interface_bindings module~mod_write_outfiles_training->module~mod_write_outfiles module~mod_cost_calculator->module~mod_write_outfiles_training module~mod_output_files_and_cost->module~mod_cost_calculator module~mod_output_files_and_cost_4g_charges->module~mod_cost_calculator module~mod_output_files_and_cost_4g_short_range->module~mod_cost_calculator

Module Variables

  • RMSE_IDX : integer

Derived Types Summary

Name Description
LossRMSE Root mean squared error loss function.

Procedures Summary

Name Type Description
constructor_rmse Function Construct a new RMSE loss function object. Creates and initializes a new Root Mean Squared...
loss_rmse Function Calculate the sum of squared errors for a batch. Computes the sum of squared differences...
collect_rmse Function Normalize and take square root to get the final RMSE value. Converts the sum of squared errors...
first_derivative_loss_rmse Function Calculate the gradient of RMSE with respect to predictions. Computes the derivative of the RMSE...

Derived Types Details

type LossRMSE

Root mean squared error loss function.

Components

Type-Bound Procedures

Name Attributes Binding
value public ⇒ loss_value
value_child public ⇒ loss_rmse
first_derivative public ⇒ first_derivative_loss_rmse
collect_child public ⇒ collect_rmse

Inherits

type~~lossrmse~~InheritsGraph type~lossrmse LossRMSE type~abstractlossfunction AbstractLossFunction type~lossrmse->type~abstractlossfunction

Interface Details

interface LossRMSE


Procedure Details

function constructor_rmse

function constructor_rmse( &
    collect &
)

Construct a new RMSE loss function object.

Creates and initializes a new Root Mean Squared Error loss function instance with the specified MPI collection behavior.

collect - Whether to collect and average loss across MPI processes Returns: Polymorphic pointer to the constructed RMSE loss function

Arguments

  • collect : logical [in]– Whether to average across MPI process batches

Called By

proc~~constructor_rmse~~CalledByGraph proc~constructor_rmse mod_loss_rmse::constructor_rmse interface~lossrmse mod_loss_rmse::LossRMSE interface~lossrmse->proc~constructor_rmse

function loss_rmse

function loss_rmse( &
    self, &
    batchsize, &
    prediction, &
    reference &
)

Calculate the sum of squared errors for a batch.

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
  • prediction : real(DP) (dim: (batchsize)) [in]– Predicted values
  • reference : real(DP) (dim: (batchsize)) [in]– Reference values

Called By

proc~~loss_rmse~~CalledByGraph proc~loss_rmse mod_loss_rmse::LossRMSE%loss_rmse proc~first_derivative_loss_rmse mod_loss_rmse::LossRMSE%first_derivative_loss_rmse proc~first_derivative_loss_rmse->proc~loss_rmse

function collect_rmse

function collect_rmse( &
    global_sum_loss, &
    global_batchsize &
)

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

function first_derivative_loss_rmse

function first_derivative_loss_rmse( &
    self, &
    batchsize, &
    prediction, &
    reference &
)

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
  • prediction : real(DP) (dim: (batchsize)) [in]– Predicted values
  • reference : real(DP) (dim: (batchsize)) [in]– Reference values