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

4 次查看(过去 30 天)
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.

回答(1 个)

Onur Kilic
Onur Kilic 2022-11-10
编辑:Onur Kilic 2022-11-10
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

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by