Class MeanSquaredErrorLoss
- Namespace
- NeuralNetworks.Losses
- Assembly
- NeuralNetworks.dll
Mean Squared Error (MSE) loss function for 2D tensors.
public class MeanSquaredErrorLoss : Loss<float[,]>
- Inheritance
-
MeanSquaredErrorLoss
- Inherited Members
Remarks
Input: The predicted values (ŷ) and the target values (y) as 2D tensors.
Formula: L = (1/n) · Σ(yᵢ - ŷᵢ)² where n depends on the reduction method
Gradient Formula: ∂L/∂ŷᵢ = (2/n) · (ŷᵢ - yᵢ) where n depends on the reduction method
Description: The Mean Squared Error loss measures the average squared difference between predicted values (ŷ) and target values (y). It is the most commonly used loss function for regression tasks, where the goal is to predict continuous values. MSE heavily penalizes large errors due to the squaring operation, making it sensitive to outliers.
Remarks: MSE is differentiable everywhere and provides strong gradients for large errors, which can accelerate learning. However, this same property makes it sensitive to outliers - a single large error can dominate the loss value. The reduction parameter controls how the error is aggregated: ElementMean averages over all elements, while other reductions might sum or average differently. MSE is equivalent to L2 loss and is closely related to Euclidean distance. Common applications include Boston Housing price prediction, sine wave approximation, and other regression problems. For tasks with significant outliers, consider Huber loss or Mean Absolute Error (MAE) as alternatives.
Constructors
MeanSquaredErrorLoss(MseReduction)
Mean Squared Error (MSE) loss function for 2D tensors.
public MeanSquaredErrorLoss(MseReduction mseReduction = MseReduction.ElementMean)
Parameters
mseReductionMseReductionThe reduction method applied to compute the final loss value. Default is ElementMean.
Remarks
Input: The predicted values (ŷ) and the target values (y) as 2D tensors.
Formula: L = (1/n) · Σ(yᵢ - ŷᵢ)² where n depends on the reduction method
Gradient Formula: ∂L/∂ŷᵢ = (2/n) · (ŷᵢ - yᵢ) where n depends on the reduction method
Description: The Mean Squared Error loss measures the average squared difference between predicted values (ŷ) and target values (y). It is the most commonly used loss function for regression tasks, where the goal is to predict continuous values. MSE heavily penalizes large errors due to the squaring operation, making it sensitive to outliers.
Remarks: MSE is differentiable everywhere and provides strong gradients for large errors, which can accelerate learning. However, this same property makes it sensitive to outliers - a single large error can dominate the loss value. The reduction parameter controls how the error is aggregated: ElementMean averages over all elements, while other reductions might sum or average differently. MSE is equivalent to L2 loss and is closely related to Euclidean distance. Common applications include Boston Housing price prediction, sine wave approximation, and other regression problems. For tasks with significant outliers, consider Huber loss or Mean Absolute Error (MAE) as alternatives.
Methods
CalculateLoss()
protected override float CalculateLoss()
Returns
CalculateLossGradient()
protected override float[,] CalculateLossGradient()
Returns
- float[,]
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.