How do you fill in NaN in time series using neural networks?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
bikefan
el 15 de Abr. de 2017
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.
0 comentarios
Respuesta aceptada
Greg Heath
el 16 de Abr. de 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 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!