Interval prediction | MATLAB implements QRLSTM long short-term memory neural network quantile regression multi-input single-output interval prediction

Interval prediction | MATLAB implements QRLSTM long short-term memory neural network quantile regression multi-input single-output interval prediction

List of effects

1
2
3
4

basic introduction

MATLAB implements QRLSTM long short-term memory neural network quantile regression time series interval prediction
QRLSTM is a model based on long short-term memory (LSTM) neural network for time series interval prediction. It makes predictions using quantile regression, which means it predicts a range of possible outcomes, not just a single point prediction.
Specifically, QRLSTM uses an LSTM network to learn long-term and short-term dependencies of time series, and then uses quantile regression to predict a range of possible outcomes. Quantile regression is a very useful technique for predicting upper and lower bounds for a given confidence level, which is useful for time series forecasting.
The predictive power of the QRLSTM model is strong, especially when dealing with nonlinear time series. It has been widely used in stock market, weather forecast, traffic forecast and other fields.

Model description

The mathematical formulation of the QRLSTM model is as follows:
First, we define the hidden state and cell state in the LSTM network:

h t , c t = LSTM ( x t , h t − 1 , c t − 1 ) h_t,c_t=\text{LSTM}(x_t,h_{t-1},c_{t-1}) ht,ct=LSTM(xt,ht1,ct1)

  • Among them, xt x_txtis the time step ttThe input of t ,ht − 1 h_{t-1}ht1and ct − 1 c_{t-1}ct1are the hidden state and cell state at the previous time step, respectively.

Then, we define the loss function for quantile regression:

L τ = ∑ i = 1 n ρ τ ( yi − f θ ( xi ) ) \mathcal{L}{\tau}=\sum{i=1}^{n}\rho_{\tau}(y_i-f_ {\theta}(x_i))L sq=i=1nρt(yifi(xi))

  • Among them, τ \tauτ is the quantile level,yi y_iyiis the time series at time step iiThe true value of i ,f θ ( xi ) f_{\theta}(x_i)fi(xi) is the model at time stepiiThe predicted value of i ,ρ τ ( u ) \rho_{\tau}(u)rt( u ) is the quantile loss function:

ρ τ ( u ) = { τ u  if  u ≥ 0   ( τ − 1 ) u  if  u < 0 \rho_{\tau}(u)=\begin{cases} \tau u & \text{ if } u \geq 0 \ (\tau-1)u & \text{ if } u < 0 \end{cases} rt(u)={ you if u0 ( t 1)u if u<0

Ultimately our goal is to minimize the loss function at all quantile levels:

L = ∑ τ ∈ τ 1 , τ 2 , . . . , τ TL τ \mathcal{L}=\sum_{\tau\in{\tau_1,\tau_2,...,\tau_T}}\mathcal{L}_{\tau}L=ττ1, t2, ... , tTLt

  • Among them, τ 1 , τ 2 , . . . , τ T {\tau_1,\tau_2,...,\tau_T}t1,t2,...,tTis a set of quantile levels.

The QRLSTM model uses stochastic gradient descent or other optimization algorithms to minimize the above loss function to obtain the optimal model parameters.

programming

% 构建模型
numFeatures = size(XTrain,1); % 输入特征数
numHiddenUnits = 200; % 隐藏单元数
numQuantiles = 1; % 分位数数目
layers = [ ...
    sequenceInputLayer(numFeatures)
    lstmLayer(numHiddenUnits,'OutputMode','last')
    dropoutLayer(0.2)
    fullyConnectedLayer(numQuantiles)
    regressionLayer];
options = trainingOptions('adam', ...
    'MaxEpochs',50, ...
    'MiniBatchSize',64, ...
    'GradientThreshold',1, ...
    'Shuffle','every-epoch', ...
    'Verbose',false);
net = trainNetwork(XTrain,YTrain,layers,options); % 训练模型

% 测试模型
YPred = predict(net,XTest); % 预测输出
quantiles = [0.1,0.5,0.9]; % 分位数
for i = 1:length(quantiles)
    q = quantiles(i);
    epsilon = YTest - YPred(:,i); % 预测误差
    lag = 10; % 滞后期数
    sigma = median(abs(epsilon(max(1,end-lag+1):end))) * 1.483; % 置信区间
    lb = YPred(:,i) - sigma * norminv(1-q/2,0,1); % 置信区间下限
    ub = YPred(:,i) + sigma * norminv(1-q/2,0,1); % 置信区间上限
    disp(['Quantile:',num2str(q),' MAE:',num2str(mean(abs(epsilon))),' Width:',num2str(mean(ub-lb))]);
end

References

[1] https://blog.csdn.net/kjm13182345320/article/details/127931217
[2] https://blog.csdn.net/kjm13182345320/article/details/127418340

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/131931857