matlab narxnet,Nonlinear autoregressive neural network with external input

Train a nonlinear autoregressive with external input (NARX) neural network and predict on new time series data. Predicting a sequence of values in a time series is also known as multistep prediction. Closed-loop networks can perform multistep predictions. When external feedback is missing, closed-loop networks can continue to predict by using internal feedback. In NARX prediction, the future values of a time series are predicted from past values of that series, the feedback input, and an external time series.

Load the simple time series prediction data.

[X,T] = simpleseries_dataset;

Partition the data into training data XTrain and TTrain, and data for prediction XPredict. Use XPredict to perform prediction after you create the closed-loop network.

XTrain = X(1:80);

TTrain = T(1:80);

XPredict = X(81:100);

Create a NARX network. Define the input delays, feedback delays, and size of the hidden layers.

net = narxnet(1:2,1:2,10);

Prepare the time series data using preparets. This function automatically shifts input and target time series by the number of steps needed to fill the initial input and layer delay states.

[Xs,Xi,Ai,Ts] = preparets(net,XTrain,{},TTrain);

A recommended practice is to fully create the network in an open loop, and then transform the network to a closed loop for multistep-ahead prediction. Then, the closed-loop network can predict as many future values as you want. If you simulate the neural network in closed-loop mode only, the network can perform as many predictions as the number of time steps in the input series.

Train the NARX network. The train function trains the network in an open loop (series-parallel architecture), including the validation and testing steps.

net = train(net,Xs,Ts,Xi,Ai);

Display the trained network.

view(net)

d2f502855f4cffa87a56c2f8757ce637.png

Calculate the network output Y, final input states Xf, and final layer states Af of the open-loop network from the network input Xs, initial input states Xi, and initial layer states Ai.

[Y,Xf,Af] = net(Xs,Xi,Ai);

Calculate the network performance.

perf = perform(net,Ts,Y)

perf =

0.0153

To predict the output for the next 20 time steps, first simulate the network in closed-loop mode. The final input states Xf and layer states Af of the open-loop network net become the initial input states Xic and layer states Aic of the closed-loop network netc.

[netc,Xic,Aic] = closeloop(net,Xf,Af);

Display the closed-loop network.

view(netc)

a86c3c5100ac733c5169943a4dd7e55e.png

Run the prediction for 20 time steps ahead in closed-loop mode.

Yc = netc(XPredict,Xic,Aic)

Yc =

1x20 cell array

Columns 1 through 5

{[-0.0156]} {[0.1133]} {[-0.1472]} {[-0.0706]} {[0.0355]}

Columns 6 through 10

{[-0.2829]} {[0.2047]} {[-0.3809]} {[-0.2836]} {[0.1886]}

Columns 11 through 15

{[-0.1813]} {[0.1373]} {[0.2189]} {[0.3122]} {[0.2346]}

Columns 16 through 20

{[-0.0156]} {[0.0724]} {[0.3395]} {[0.1940]} {[0.0757]}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值