mean squared logarithmic error loss function

9 次查看(过去 30 天)
Hi.
I'm trying to write a MSLE regression layer with no success. Can you help me, please?
I have followed the template and suggested procedure but I can't make it work.
Thanks.
Here is my code:
classdef msleRegressionLayer < nnet.layer.RegressionLayer
% Custom regression layer with mean-squared-logarithmic-error loss.
methods
function layer = msleRegressionLayer(name)
% layer = msleRegressionLayer(name) creates a
% mean-squared-logarithmic-error regression layer and specifies the layer
% name.
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = 'Mean squared logarithmic error';
end
function loss = forwardLoss(layer, Y, T)
% loss = forwardLoss(layer, Y, T) returns the MSLE loss between
% the predictions Y and the training targets T.
% Calculate MSLE.
R = size(Y,3);
%meanAbsoluteError = sum(abs(Y-T),3)/R;
msle=sum((log10((Y+1)./(T+1))).^2,3)/R;
% Take mean over mini-batch.
N = size(Y,4);
loss = sum(msle)/N;
end
function dLdY = backwardLoss(layer, Y, T)
% Returns the derivatives of the MSLE loss with respect to the predictions Y
R = size(Y,3);
N = size(Y,4);
dLdY = 2/(N*R)*(log10(Y+1)-log10(T+1))./(Y+1)*2.3;
end
end
end

采纳的回答

Sahithi Kanumarlapudi
It is already answered here

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Regression 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by