How do you fill in NaN in time series using neural networks?

3 visualizzazioni (ultimi 30 giorni)
I am having difficulty filling in NaN values with time series data with neural networks. The simulated program is below, created using the Neural Network time series wizard. The following error appears when using yg=netc(num2cell(biomet,2)); or yg=net(num2cell(biomet,2)).
Error using network/sim (line 271) Number of inputs does not match net.numInputs.
Error in network/subsref (line 16) otherwise, v = sim(vin,subs{:});
N = 700 ; % Number of data points
biomet= 0:0.5:350;
biomet2=0:0.25:175; % Generate a random data
biomet=[cos(biomet(1:700));sin(biomet2(1:700))]';
frac_gaps = 0.3 ; % Fraction of gaps
gaps = randsample(1:N,frac_gaps*N) ; % gaps position
target=sin(1:700)';
target(gaps) = NaN ; % Replace gaps with NaN
time=1:700;
time=1:700;
%
% Solve an Autoregression Problem with External Input with a NARX Neural Network
% Script generated by Neural Time Series app
% Created 15-Apr-2017 16:27:08
%
% This script assumes these variables are defined:
%
% biomet - input time series.
% target - feedback time series.
%
X = tonndata(biomet,false,false);
T = tonndata(target,false,false);
%
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
%
% Create a Nonlinear Autoregressive Network with External Input
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize = 10;
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
%
% Prepare the Data for Training and Simulation
[x,xi,ai,t] = preparets(net,X,{},T);
%
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 60/100;
net.divideParam.valRatio = 20/100;
net.divideParam.testRatio = 20/100;
%
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
%
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y);
%
% View the Network
%view(net)
%
% Closed Loop Network
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
%view(netc)
[xc,xic,aic,tc] = preparets(netc,X,{},T);
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc);
%
% Step-Ahead Prediction Network
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
% view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
%
yg=net(num2cell(biomet,2));
%
figure(1)
clf
scatter(target,y)
%
figure(2)
clf
plot(time,target)
hold on
plot(time,y)
Thanks.

Risposta accettata

Greg Heath
Greg Heath il 16 Apr 2017
Try again using real data. Using random data for a time series makes no sense at all: It is the correlation between adjoining points that allows timeseries to be useful.
In addition to the examples used in the documentation
help narxet
doc narxnet
there are several more data sets obtainable using the command
help nndatasets.
Also, I have posted many examples in both the NEWSGROUP and ANSWERS. Just search with
greg narxnet
Hope this helps.
Thank you for formally accepting my answer
Greg
  1 Commento
bikefan
bikefan il 19 Apr 2017
Modificato: bikefan il 19 Apr 2017
Thanks, I changed the input to be actual data. However, when I try to gap fill the data (also by checking your many responses), and the neural networks preformed more expectantly.
However, I tried using y=net(x), and still had NaN in the gap filled dataset. The original 'x data' had no gaps or NaN values.
Also the resultant matrix was 2 entries shorter. How would I complete a gap fill with multiple inputs and preserve the original matrix dimensions?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by