SiaNet/Losses/MeanSquaredLogError.cs
/// <summary>
/// Backpropagation method to calculate gradient of the loss function
/// </summary>
/// <param name="preds">The predicted result.</param>
/// <param name="labels">The true result.</param>
/// <returns></returns>
Backpropagation method to calculate gradient of the loss function
Backpropagation method to calculate gradient of the loss function
public override Tensor Backward(Tensor preds, Tensor labels)
        {
            float norm = 2f / preds.Shape[0];
            var first_log = K.Log(K.Clip(preds, K.Epsilon(), float.MaxValue) + 1);
            var second_log = K.Log(K.Clip(labels, K.Epsilon(), float.MaxValue) + 1);
            return  norm * (first_log - second_log) / (K.Clip(preds, K.Epsilon(), float.MaxValue) + 1);
        }
public override Tensor Backward ( Tensor preds , Tensor labels ) { float norm = 2f / preds . Shape [ 0 ] ; var first_log = K . Log ( K . Clip ( preds , K . Epsilon ( ) , float . MaxValue ) + 1 ) ; var second_log = K . Log ( K . Clip ( labels , K . Epsilon ( ) , float . MaxValue ) + 1 ) ; return norm * ( first_log - second_log ) / ( K . Clip ( preds , K . Epsilon ( ) , float . MaxValue ) + 1 ) ; }
Backpropagation method to calculate gradient of the loss function
Backpropagation method to calculate gradient of the loss function
None
preds
Tensor
The predicted result.
The predicted result .
labels
Tensor
The true result.
The true result .