Interval prediction | MATLAB implements QRCNN convolutional neural network quantile regression time series interval prediction

Interval prediction | MATLAB implements QRCNN convolutional neural network quantile regression time series interval prediction

List of effects

1
2
3

basic introduction

Interval prediction | MATLAB implements QRCNN convolutional neural network quantile regression time series interval prediction
1. Matlab realizes the time series interval prediction model based on QRCNN quantile regression convolutional neural network;
2. Multi-image output, multi-indicator output (MAE , RMSE, MSE, R2), multiple input and single output, including different confidence interval maps and probability density maps;
3. data is a data set, a power data set, using variables from the past period of time to predict the target, the target is the last column, and also Applicable to load forecasting and wind speed forecasting; MainQRCNNTS is the main program, and the rest are function files, no need to run;
4. The code is of high quality, with clear comments, including data preprocessing, and handling missing values. If it is nan, replace it with the previous line, Kernel density estimation is also included.

Model description

QRCNN is a convolutional neural network (CNN) based quantile regression model for time series interval forecasting. Its full name is Quantile Regression Convolutional Neural Network. This model can be used to predict different quantiles of time series data, such as predicting the upper and lower limits of stock prices, the extreme value of wind speed, etc. Since QRCNN adopts the structure of convolutional neural network, it can effectively capture the local and global characteristics of time series data, thereby improving the prediction accuracy.
The main idea of ​​the QRCNN model is to decompose time series data into a series of windows and treat each window as an image. Then, feature extraction and analysis are performed on these images using a convolutional neural network, and a prediction result for each quantile is finally output. The training process of the QRCNN model employs a quantile loss function to minimize the prediction error for all quantiles.

The advantages of the QRCNN model include:
being able to effectively deal with the uncertainty and nonlinear characteristics of time series data;
being able to predict multiple quantiles at the same time, thereby providing more comprehensive prediction results; and
being able to flexibly handle time series data of different lengths.
In conclusion, the QRCNN model is a powerful tool for time series interval forecasting, which can help people better understand and apply time series data.
The formula of the QRCNN model includes input layer, convolutional layer, pooling layer, fully connected layer and output layer. The following are the main formulas of the QRCNN model:

Input layer:
Suppose the time series data is xt x_txt, then the input layer will each time step ttt 's data as an input nodext x_txt.
Convolutional layer:
Assuming the kkthThe size of k convolution kernels isdk d_kdk, then the kkthThe output of k convolutional layerszk z_kzkIt can be expressed as:

z k = σ ( W k ∗ x + b k ) z_k=\sigma(W_k * x+b_k) zk=s ( Wkx+bk)

Among them, W k W_kWkis the kkthThe weight matrix of k convolution kernels, ∗ * means convolution operation,bk b_kbkis a bias term, σ \sigmaσ is the activation function, usually using ReLU or tanh function.
Pooling layer:
Assuming thekkthThe size of k pooling operations ismk m_kmk, then the kkthThe output of k pooling layersyk y_kykIt can be expressed as:

y k = m a x p o o l ( z k ) y_k=maxpool(z_k) yk=ma x p z l ( zk)

Among them, maxpool maxpoolmax pool represents the maximum pooling operation .
Fully connected layer:
Assuming thellthThe output of l fully connected layers ishl h_lhl, then the llThe output of l fully connected layershl h_lhlIt can be expressed as:

h l = σ ( W l ∗ h l − 1 + b l ) h_l=\sigma(W_l*h_{l-1}+b_l) hl=s ( Wlhl1+bl)

Among them, W l W_lWlis the llThe weight matrix of l fully connected layers, bl b_lblis a bias term, σ \sigmaσ is the activation function.
Output layer:
suppose to predictqqq quantile,qqthThe q quantiles areτ q \tau_qtq, then the output of the output layer yq y_qyqIt can be expressed as:

yq = F τ q ( h L ) y_q=F_{\tau_q}(h_L)yq=Ftq(hL)

where, F τ q ( h L ) F_{\tau_q}(h_L)Ftq(hL) means theLLThe output of layer L h L h_LhLIn quantile τ q \tau_qtqThe cumulative distribution function (CDF) at .
Loss function:
The QRCNN model uses a quantile loss function, which is defined as:

L τ ( y , y ^ ) = ( 1 − τ ) ∣ y − y ^ ∣ ( y ≤ y ^ ) + τ ∣ y − y ^ ∣ ( y > y ^ ) L_{\tau}(y,\hat {y})=(1-\tau)|y-\hat{y}|{(y\le \hat{y})}+\tau|y-\hat{y}|{(y> \hat {and})}Lt(y,y^)=(1t ) yy^(yy^)+τyy^(y>y^)

Among them, yyy represents the actual value,y ^ \hat{y}y^Indicates the predicted value, τ \tauτ represents the quantile,∣ ⋅ ∣ ( ⋅ ) | \cdot |_{(\cdot)}()Indicates the indicator function.
Ultimately, the goal of the QRCNN model is to minimize the sum of the prediction errors for all quantiles, namely:

m i n ∑ i = 1 n ∑ q = 1 Q L τ q ( y i , y i ^ ) min \sum_{i=1}^{n}\sum_{q=1}^{Q}L_{\tau_q}(y_i,\hat{y_i}) mini=1nq=1QLtq(yi,yi^)

Among them, nnn represents the sample size,QQQ represents the number of quantiles.

programming

  • Complete program and data acquisition method: private message blogger.
% Divide the data into training and validation data sets
numTrainFiles = 90;
[imdsTrain,imdsValidation] = splitEachLabel(imds,numTrainFiles,'randomize');
% Define the convolutional neural network architecture.
layers = [
% Image Input Layer An imageInputLayer 
    imageInputLayer([64 64 1])
% Convolutional Layer 
convolution2dLayer(3,8,'Padding','same')
% Batch Normalization 
    batchNormalizationLayer
% ReLU Layer The batch
    reluLayer
% Max Pooling Layer  
    % More values means less weights
    maxPooling2dLayer(4,'Stride',4)
    %------------------------------
    convolution2dLayer(3,8,'Padding','same')
    batchNormalizationLayer
    reluLayer
    maxPooling2dLayer(5,'Stride',5)
    convolution2dLayer(3,8,'Padding','same')
    batchNormalizationLayer
    reluLayer
% Fully Connected Layer (Number of Classes) 
    fullyConnectedLayer(8)
% Softmax Layer 
    softmaxLayer
% Classification Layer The final layer 
    classificationLayer];
% Specify the training options
options = trainingOptions('sgdm', ...
    'InitialLearnRate',0.001, ...
    'MaxEpochs',20, ...
    'Shuffle','every-epoch', ...
    'ValidationData',imdsValidation, ...
    'ValidationFrequency',8, ...
    'Verbose',false, ...
    'Plots','training-progress');
% Train the network 
[net,info]= trainNetwork(imdsTrain,layers,options);

% Converting Serial Network to an Object
netobj = net.saveobj;
% Extracting Fully Connected Layer's Weights To Evolve
FullConn=netobj.Layers(13, 1).Weights;
netbias=netobj.Layers(13, 1).Bias;

%% Data for Each Weight
sizefinal=size(FullConn);
sizefinal=sizefinal(1,1);
for i=1:sizefinal
Inputs=FullConn(i,:);
Targets=Inputs;
data.Inputs=Inputs;
data.Targets=Targets;
datam{
    
    i}=JustLoad(data);
end;

————————————————
版权声明:本文为CSDN博主「机器学习之心」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/kjm13182345320/article/details/128252426

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/130577667