Class MeanSquaredErrorLoss4D
- Namespace
- NeuralNetworks.Losses
- Assembly
- NeuralNetworks.dll
Mean Squared Error (MSE) loss function for 4D tensors.
public class MeanSquaredErrorLoss4D : Loss<float[,,,]>
- Inheritance
-
MeanSquaredErrorLoss4D
- Inherited Members
Remarks
Input: The predicted values (ŷ) and the target values (y) as 4D 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 for 4D tensors measures the average squared difference between predicted and target values. This variant operates on 4D tensors typically structured as [batch, channels, height, width], making it suitable for convolutional neural networks (CNNs) in tasks like image reconstruction, denoising autoencoders, super-resolution, and other pixel-wise regression problems.
Remarks: Functionally identical to MeanSquaredErrorLoss but designed for 4D tensor operations typical in CNNs. Commonly used in autoencoding tasks where the network must reconstruct input images, or in image-to-image translation problems. The 4D implementation enables efficient batch processing of multi-channel image data. Like its 2D counterpart, it is sensitive to outliers and provides strong gradients for large errors. For perceptual quality in image generation tasks, combining MSE with perceptual losses (e.g., feature-based losses from pretrained networks) often yields better results than MSE alone. The reduction parameter controls aggregation across all four dimensions of the tensor.
Constructors
MeanSquaredErrorLoss4D(MseReduction)
Mean Squared Error (MSE) loss function for 4D tensors.
public MeanSquaredErrorLoss4D(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 4D 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 for 4D tensors measures the average squared difference between predicted and target values. This variant operates on 4D tensors typically structured as [batch, channels, height, width], making it suitable for convolutional neural networks (CNNs) in tasks like image reconstruction, denoising autoencoders, super-resolution, and other pixel-wise regression problems.
Remarks: Functionally identical to MeanSquaredErrorLoss but designed for 4D tensor operations typical in CNNs. Commonly used in autoencoding tasks where the network must reconstruct input images, or in image-to-image translation problems. The 4D implementation enables efficient batch processing of multi-channel image data. Like its 2D counterpart, it is sensitive to outliers and provides strong gradients for large errors. For perceptual quality in image generation tasks, combining MSE with perceptual losses (e.g., feature-based losses from pretrained networks) often yields better results than MSE alone. The reduction parameter controls aggregation across all four dimensions of the tensor.
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.