How to Define Custom Regression Output Layer with Robust (Huber) Loss

5 visualizaciones (últimos 30 días)
Onur Kilic
Onur Kilic el 10 de Nov. de 2022
Editada: Onur Kilic el 10 de Nov. de 2022
The following example provides a framework to define a custom regression layer for MAE loss:
How can you define a similar layer for Huber loss to reduce the effects of outliers? I am specifically asking for when the feature input is a simple numeric array.
Thank you.

Respuestas (1)

Onur Kilic
Onur Kilic el 10 de Nov. de 2022
Editada: Onur Kilic el 10 de Nov. de 2022
I realized that I hadn't correctly formatted the predictions made by the network with dlarray. Below is the working regression layer based on Huber loss in case anyone needs it.
classdef huberRegressionLayer < nnet.layer.RegressionLayer ...
& nnet.layer.Acceleratable % (Optional)
methods
function layer = huberRegressionLayer(name)
% layer = huberRegressionLayer(name) creates a
% robust regression layer based on huber loss
% and specifies the layer name.
% Set layer name.
layer.Name = name;
% Set layer description.
layer.Description = 'Huber loss';
end
function loss = forwardLoss(layer,Y,T)
% loss = forwardLoss(layer, Y, T) returns the Huber loss between
% the predictions Y and the training targets T.
dlY = dlarray(Y,'CB');
loss = huber(dlY,T,"TransitionPoint",1);
end
end
end

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by