关于MATLAB中时间序列神经网络工具(ntstool)的问题

时间:2014-05-12 05:37:03

标签: matlab neural-network time-series

我必须使用NAR网络来训练我的项目的时间序列。为了了解时间序列工具(ntstool)如何在 MATLAB 中工作,我在matlab中使用了 ntstool 的GUI,其中包含 chickenpoxTargets的示例数据集包含一个元素的498个时间步长。在训练时,我使用了一个带有10隐藏层和delay value = 5的神经网络。 GUI生成以下代码:

% Solve an Autoregression Time-Series Problem with a NAR Neural Network
% Script generated by NTSTOOL
% Created Mon May 12 10:47:14 IST 2014
%
% This script assumes this variable is defined:
%
%   chickenpoxTargets - feedback time series.

targetSeries = chickenpoxTargets;

% Create a Nonlinear Autoregressive Network
feedbackDelays = 1:5;
hiddenLayerSize = 10;
net = narnet(feedbackDelays,hiddenLayerSize);

% Prepare the Data for Training and Simulation
% The function PREPARETS prepares timeseries data for a particular network,
% shifting time by the minimum amount to fill input states and layer states.
% Using PREPARETS allows you to keep your original time series data unchanged, while
% easily customizing it for networks with differing numbers of delays, with
% open loop or closed loop feedback modes.
[inputs,inputStates,layerStates,targets] = preparets(net,{},{},targetSeries);

% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;


% Train the Network
[net,tr] = train(net,inputs,targets,inputStates,layerStates);

% Test the Network
outputs = net(inputs,inputStates,layerStates);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)

% View the Network
view(net)

% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotresponse(targets,outputs)
%figure, ploterrcorr(errors)
%figure, plotinerrcorr(inputs,errors)

% Closed Loop Network
% Use this network to do multi-step prediction.
% The function CLOSELOOP replaces the feedback input with a direct
% connection from the outout layer.
netc = closeloop(net);
[xc,xic,aic,tc] = preparets(netc,{},{},targetSeries);
yc = netc(xc,xic,aic);
perfc = perform(net,tc,yc)

% Early Prediction Network
% For some applications it helps to get the prediction a timestep early.
% The original network returns predicted y(t+1) at the same time it is given y(t+1).
% For some applications such as decision making, it would help to have predicted
% y(t+1) once y(t) is available, but before the actual y(t+1) occurs.
% The network can be made to return its output a timestep early by removing one delay
% so that its minimal tap delay is now 0 instead of 1.  The new network returns the
% same outputs as the original network, but outputs are shifted left one timestep.
nets = removedelay(net);
[xs,xis,ais,ts] = preparets(nets,{},{},targetSeries);
ys = nets(xs,xis,ais);
closedLoopPerformance = perform(net,tc,yc)

现在我有以下三个问题:

  1. GUI中的**延迟值(d)**是什么意思。这是否意味着在训练网络时假设每个时间步长值都依赖于最后'd'时间步长的值?
  2. 在未来的时间步长预测值的语法是什么?
  3. 当我使用sim(results.net,input)模拟网络时,results.net是神经网络,输入是预测输出的输入行向量,无论输入行向量是什么,我都得到相同的输出。更具体地说,输出不同的输入向量:

    sim(results.net,[956])
    
    ans =
    
      136.8790
    
    sim(results.net,[957])
    
    ans =
    
      136.8790
    
    sim(results.net,[954,966])
    
    ans =
    
      136.8790  136.8790
    
  4. 为什么我得到相同的输出?

1 个答案:

答案 0 :(得分:0)

  1. 延迟参数表示您插入模型的时间步长

    y(t) = f(y(t-1), y(t-2), ... y(t-d))

    因此,每个时间步长取决于最后d时间步长

  2. 要预测更多时间步而不插入新数据,您必须将模型更改为closedloop模型。

    表示在脚本中显示:

    % convert from openloop to closedloop
    netc = closeloop(net);
    % prepare your data for the network (scaling!!)
    [xc,xic,aic,tc] = preparets(netc,{},{},targetSeries);
    % calculate new output
    yc = netc(xc,xic,aic);
    % get performance of network
    perfc = perform(net,tc,yc)
    
  3. 您必须在使用net之前准备输入数据(使用 preparets )。正如MATLAB Documentation sim()中所示,需要几个参数:

    [Y,Xf,Af] = sim(net,X,Xi,Ai,T)
    

    此外:

      

    ...通过将神经网络对象(网络)作为函数调用来隐式调用sim函数。

    意味着:您可以使用net(),如2.所示,与sim()

    相同

    如果没有缩放,您的输入与从中学到的网络不同。因此输出错误的数字。