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

조회 수: 5 (최근 30일)
Onur Kilic
Onur Kilic 2022년 11월 10일
편집: Onur Kilic 2022년 11월 10일
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에서 Linear Regression에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by