Interval prediction | MATLAB implements QRBiLSTM bidirectional long-short-term memory neural network quantile regression multi-input single-output interval prediction
Table of Contents
-
- Interval prediction | MATLAB implements QRBiLSTM bidirectional long short-term memory neural network quantile regression multi-input single-output interval prediction
-
- List of effects
- basic introduction
- Model description
- programming
- References
List of effects
Basic introduction
Interval prediction | MATLAB implements QRBiLSTM bidirectional long short-term memory neural network multi-input single-output quantile regression interval prediction
QRBiLSTM is a variant of Bidirectional Long Short-Term Memory (QR-LSTM) neural network for quantile regression time series interval forecasting. The model predicts values for different quantiles of the time series and can provide information such as confidence intervals and risk estimates.
QR-LSTM is a quantile regression method based on the LSTM model, which can predict the values of different quantiles by learning the quantile regression loss function. QRBiLSTM adds a two-way transmission structure based on QR-LSTM, which can capture more time series information.
Model description
The input of the QRBiLSTM model includes historical data and external variables, and the output is quantile value and confidence interval. Typically, you use training data to fit model parameters and test data to evaluate the model’s predictive performance.
In short, QRBiLSTM is a very useful time series forecasting model, which can be applied in many fields, such as finance, stock, meteorology, etc. It can provide more comprehensive time series forecasting information and help improve the accuracy of decision-making.
-
The specific formula of the QRBiLSTM model is given below, where
x
\textbf{X}
X represents the input sequence,
Y
\textbf{Y}
Y represents the output sequence,
h
\textbf{H}
H represents the hidden state,
C
\textbf{C}
C represents the memory state,
f
θ
f_{\theta}
fθ? represents the neural network model,
q
q
q represents the quantile:
-
Forward propagation:
h
t
f
,
C
t
f
=
L
S
T
m
θ
(
x
t
,
h
t
?
1
f
,
C
t
?
1
f
)
\textbf{H}^{f}_{t},\textbf{C}^{f}_{t} = LSTM_{\theta}(\textbf{X}_{t},\ textbf{H}^{f}_{t-1},\textbf{C}^{f}_{t-1})
Htf?,Ctf?=LSTMθ?(Xt?,Ht?1f?,Ct?1f?)
h
t
b
,
C
t
b
=
L
S
T
m
θ
(
x
t
,
h
t
+
1
b
,
C
t
+
1
b
)
\textbf{H}^{b}_{t},\textbf{C}^{b}_{t} = LSTM_{\theta}(\textbf{X}_{t},\ textbf{H}^{b}_{t + 1},\textbf{C}^{b}_{t + 1})
Htb?,Ctb?=LSTMθ?(Xt?,Ht + 1b?,Ct + 1b?)
Y
^
t
q
=
f
θ
(
[
h
t
f
,
h
t
b
]
)
\hat{Y}^{q}_{t} = f_{\theta}([\textbf{H}^{f}_{t},\textbf{H}^{b}_{ t}])
Y^tq?=fθ?([Htf?,Htb?])
?
^
t
q
=
Y
t
q
?
Y
^
t
q
\hat{\epsilon}^{q}_{t} = Y^{q}_{t} – \hat{Y}^{q}_{t}
?^tq?=YtqY^tq?
σ
^
t
q
=
median
{
∣
?
^
t
?
τ
q
∣
:
τ
≤
lag
}
?
c
alpha
(
lag
,
no
)
\hat{\sigma}^{q}_{t} = \text{median}\{|\hat{\epsilon}^{q}_{t-\tau}|:\ \tau \leq \text{lag}\} \cdot c_{\alpha}(\text{lag},n)
σ^tq?=median{∣?^t?τq?∣:τ≤lag}?cα?(lag,n)
-
in,
h
t
f
\textbf{H}^{f}_{t}
Htf? and
C
t
f
\textbf{C}^{f}_{t}
Ctf? represent the hidden state and memory state of the forward propagation, respectively;
h
t
b
\textbf{H}^{b}_{t}
Htb? and
C
t
b
\textbf{C}^{b}_{t}
Ctb? represent the hidden state and memory state of backpropagation, respectively;
Y
^
t
q
\hat{Y}^{q}_{t}
Y^tq? represents time
t
t
The quantile at t is
q
q
the predicted value of q;
f
θ
f_{\theta}
fθ? represents the neural network model;
?
^
t
q
\hat{\epsilon}^{q}_{t}
?^tq? indicates time
t
t
The quantile at t is
q
q
the prediction error of q;
σ
^
t
q
\hat{\sigma}^{q}_{t}
σ^tq? represents time
t
t
The quantile at t is
q
q
The confidence interval for the forecast error of q, where
c
alpha
(
lag
,
no
)
c_{\alpha}(\text{lag},n)
cα?(lag,n) represents the confidence coefficient.
-
The training objective of the QRBiLSTM model is to minimize the quantile loss function:
loss
θ
=
∑
t
=
1
T
∑
q
∈
Q
ρ
q
(
∣
?
t
q
∣
)
?
1
∣
Q
∣
∑
q
∈
Q
log
(
σ
^
t
q
)
\text{Loss}_{\theta}=\sum_{t=1}^{T}\sum_{q\in Q}\rho_{q}(|\epsilon^{q} _{t}|)-\frac{1}{|Q|}\sum_{q\in Q}\text{log}(\hat{\sigma}^{q}_{t })
Lossθ?=t=1∑T?q∈Q∑?ρq?(∣?tq?∣)?∣Q∣1?q∈Q∑?log(σ^tq?)
- in,
ρ
q
(
x
)
\rho_{q}(x)
ρq?(x) represents the quantile loss function:
ρ
q
(
x
)
=
{
q
x
x
≥
0
(
q
?
1
)
x
x
< 0 \rho_{q}(x)=\begin{cases}qx & amp;x\geq 0\(q-1)x & amp;x<0\end{cases} ρq?(x)={qx(q?1)x?x≥0x<0?
- The prediction goal of the QRBiLSTM model is to predict quantile values and confidence intervals, namely
Y
^
t
q
\hat{Y}^{q}_{t}
Y^tq? and
σ
^
t
q
\hat{\sigma}^{q}_{t}
σ^tq?.
Programming
- Complete program and data acquisition method 1, subscribe to “LSTM long-term short-term memory neural network” (private message me after data subscription): MATLAB implements QRBiLSTM bidirectional long-term short-term memory neural network quantile regression multi-input single-output interval prediction, only outside the column Get the program.
- Complete program and data acquisition method 2, (download from resources): MATLAB implements QRBiLSTM bidirectional long short-term memory neural network quantile multi-input single-output regression interval prediction
% build model numFeatures = size(XTrain,1); % input feature number numHiddenUnits = 200; % number of hidden units numQuantiles = 1; % number of quantiles layers = [... sequenceInputLayer(numFeatures) bilstmLayer(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); % training model % test model YPred = predict(net,XTest); % prediction output quantiles = [0.1,0.5,0.9]; % quantiles for i = 1:length(quantiles) q = quantiles(i); epsilon = YTest - YPred(:,i); % prediction error lag = 10; % number of lag periods sigma = median(abs(epsilon(max(1,end-lag + 1):end))) * 1.483; % confidence interval lb = YPred(:,i) - sigma * norminv(1-q/2,0,1); % lower bound of confidence interval ub = YPred(:,i) + sigma * norminv(1-q/2,0,1); % upper limit of confidence interval 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