Main Content

Multistep Neural Network Prediction

以开环模式设置

Dynamic networks with feedback, such asnarxnetnarnetneural networks, can be transformed between open-loop and closed-loop modes with the functionsopenloop封闭. Closed-loop networks make multistep predictions. In other words they continue to predict when external feedback is missing, by using internal feedback.

在这里,训练了一个神经网络来对磁性悬浮系统进行建模并在默认的开环模式下进行模拟。

[X,T] = maglev_dataset; net = narxnet(1:2,1:2,10); [x,xi,ai,t] = preparets(net,X,{},T); net = train(net,x,t,xi,ai); y = net(x,xi,ai); view(net)

多步闭环预测从最初的电导率itions

A neural network can also be simulated only in closed-loop form, so that given an external input series and initial conditions, the neural network performs as many predictions as the input series has time steps.

netc = closeloop(net); view(netc)

在这里,培训数据用于定义输入x,以及初始输入和层延迟状态,xiai, but they can be defined to make multiple predictions for any input series and initial states.

[x,xi,ai,t] = preparets(netc,x,{},t);yc = netc(x,xi,ai);

Multistep Closed-Loop Prediction Following Known Sequence

在开环模式下使用所有已知值的所有已知值,然后切换到闭环模式,以继续模拟未来的模拟,也可以,将训练有素的神经网络模拟当前的训练有素也很有用想要的。

Just asopenloop封闭可以用于在开环神经网络和闭环神经网络之间进行转换,它们可以转换开放环网络和闭环网络的状态。这是这些功能的完整接口。

[open_net,open_xi,open_ai] = openloop(closed_net,closed_xi,closed_ai); [closed_net,closed_xi,closed_ai] = closeloop(open_net,open_xi,open_ai);

考虑一下您可能在20个时间步长的Maglev行为记录的情况下,您想预测更多的时间步骤。

First, define the first 20 steps of inputs and targets, representing the 20 time steps where the known output is defined by the targetst. With the next 20 time steps of the input are defined, use the network to predict the 20 outputs using each of its predictions feedback to help the network perform the next prediction.

x1 = x(1:20); t1 = t(1:20); x2 = x(21:40);

The open-loop neural network is then simulated on this data.

[x,xi,ai,t] = preparets(net,x1,{},t1); [y1,xf,af] = net(x,xi,ai);

Now the final input and layer states returned by the network are converted to closed-loop form along with the network. The final input statesXF和层状态afof the open-loop network become the initial input statesxi和层状态aiof the closed-loop network.

[netc,xi,ai] = cloceLoop(net,xf,af);

Typically usepreparetsto define initial input and layer states. Since these have already been obtained from the end of the open-loop simulation, you do not needpreparets继续进行闭环网络的20个步骤预测。

[Y2,XF,AF] = NETC(X2,XI,AI);

请注意,您可以设置x2to different sequences of inputs to test different scenarios for however many time steps you would like to make predictions. For example, to predict the magnetic levitation system’s behavior if 10 random inputs are used:

x2= num2cell(rand(1,10)); [y2,xf,af] = netc(x2,xi,ai);

Following Closed-Loop Simulation with Open-Loop Simulation

如果以闭环形式模拟网络后,您可以以开环形式从那里继续模拟。在这里,闭环状态转换回开环状态。(由于您已经拥有原始的开环网络,因此您不必将网络转换回开环形式。)

[~,xi,ai] = openloop(netc,xf,af);

现在,您可以定义外部输入和开环反馈的连续性,并模拟开环网络。

x3 = num2cell(rand(2,10));y3 = net(x3,xi,ai);

In this way, you can switch simulation between open-loop and closed-loop manners. One application for this is making time-series predictions of a sensor, where the last sensor value is usually known, allowing open-loop prediction of the next step. But on some occasions the sensor reading is not available, or known to be erroneous, requiring a closed-loop prediction step. The predictions can alternate between open-loop and closed-loop form, depending on the availability of the last step’s sensor reading.