필터 지우기
필터 지우기

Is it possible to apply upper and lower bounds to predictions in an LSTM?

조회 수: 5 (최근 30일)
James McBrearty
James McBrearty 2023년 2월 28일
답변: Ben 2023년 3월 13일
My predictions, which have been running very well as late, have hit an issue, where they are forecasting well below what should be the minimum possible value, i.e. forecasting at ~200, when the minimum should be 0. Is there anyway of simply applying a constraint/bounds, or indeed using the historical data to apply this?

답변 (1개)

Ben
Ben 2023년 3월 13일
I believe the default LSTM has outputs bounded in (-1,1) due to the activation functions used.
In any case you can try using activations to add constraints to your model, e.g. a tanhLayer has outputs bounded in (-1,1) and you can add a fixed linear transform to modify that to an arbitrary interval (a,b) as follows:
a = 0; b = 10;
% since tanh(x) is in (-1,1), (tanh(x) + 1)/2 is in (0,1).
% then scale to (0,b-a) and translate to (a,b);
boundToIntervalLayer = functionLayer(@(x) a + (b-a)*(tanh(x)+1)/2);
layers = [
sequenceInputLayer(1)
lstmLayer(1)
fullyConnectedLayer(1)
boundToIntervalLayer];
net = dlnetwork(layers);
% test it out
seqLen = 10;
x = dlarray(randn(1,seqLen),"CT");
y = forward(net,x);
% you can check y is in (a,b)
Alternatively if you use a custom training loop you could add a "soft constraint" by adding a penalty term to the loss function that is large when the network predicts values outside of your bounds.

카테고리

Help CenterFile Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by