フィルターのクリア

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

4 ビュー (過去 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 Center および File ExchangeSequence 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