Table of Contents

Class RootMeanSquaredErrorLoss<T>

Namespace
AiDotNet.LossFunctions
Assembly
AiDotNet.dll

Implements the Root Mean Squared Error (RMSE) loss function.

public class RootMeanSquaredErrorLoss<T> : LossFunctionBase<T>, ILossFunction<T>

Type Parameters

T

The numeric type (float or double).

Inheritance
RootMeanSquaredErrorLoss<T>
Implements
Inherited Members
Extension Methods

Remarks

RMSE measures the square root of the average squared differences between predicted and actual values. It is particularly useful for regression problems and gives more weight to larger errors.

Formula: RMSE = sqrt(mean((predicted - actual)^2))

The derivative with respect to predicted values is: d(RMSE)/d(predicted) = (predicted - actual) / (n * RMSE) where n is the number of samples and RMSE is the loss value.

This implementation leverages the existing StatisticsHelper.CalculateRootMeanSquaredError() method for efficient and consistent calculation across the library.

Methods

CalculateDerivative(Vector<T>, Vector<T>)

Calculates the derivative of the RMSE loss with respect to predicted values.

public override Vector<T> CalculateDerivative(Vector<T> predicted, Vector<T> actual)

Parameters

predicted Vector<T>

The predicted values.

actual Vector<T>

The actual (ground truth) values.

Returns

Vector<T>

A vector of gradients for each predicted value.

Exceptions

ArgumentException

Thrown when predicted and actual vectors have different lengths.

CalculateLoss(Vector<T>, Vector<T>)

Calculates the Root Mean Squared Error loss between predicted and actual values.

public override T CalculateLoss(Vector<T> predicted, Vector<T> actual)

Parameters

predicted Vector<T>

The predicted values.

actual Vector<T>

The actual (ground truth) values.

Returns

T

The RMSE loss value.

Exceptions

ArgumentException

Thrown when predicted and actual vectors have different lengths.