LSTM Error in Index in array bounds

2 次查看(过去 30 天)
Yossi
Yossi 2019-2-24
评论: Jan 2019-2-28
Hello,
I'm trying to run LSTM , but it seems that the code is exceed the boundtry (.mat file attached).
close all; clear all
load aapl.mat
date=(AAPL{:,1});
Low=(AAPL{:,4})';
closeP=(AAPL{:,6})';
data={Low closeP}';
%data=[closeP]';
figure
plot(date,closeP)
xlabel("Month")
ylabel("Value")
title("S&P500")
numTimeStepsTrain = floor(0.80*length(data{1}));
for i=1:numel(data)
dataTrain{i} = data{i}(1:numTimeStepsTrain+1);
dataTest{i} = data{i}(numTimeStepsTrain+1:end);
end
for i=1:numel(dataTrain)
mu_train{i} = mean(dataTrain{i},2);
sig_train{i} = std(dataTrain{i});
dataTrainStandardized{i}=(dataTrain{i}-mu_train{i})./sig_train{i};
end
for i=1:numel(dataTrainStandardized)
XTrain{i} = dataTrainStandardized{i}(:,1:end-1);
YTrain{i} = dataTrainStandardized{2}(:,2:end);
end
numFeatures = 1;
numResponses = 1;
numHiddenUnits = 200;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(XTrain,YTrain,layers,options);
for i=1:numel(dataTest)
%mu_test{i} = mean(dataTest{i},2);
%sig_test{i} = std(dataTest{i});
dataTestStandardized{i}=(dataTest{i}-mu_train{i})./sig_train{i};
end
for i=1:numel(dataTestStandardized)
XTest{i} = dataTestStandardized{i}(:,1:end-1);
YTest{i}=dataTestStandardized{i}(:,2:end);
YTestReg{i}=dataTestStandardized{i}(:,end);
end
%XTest = dataTestStandardized(:,1:end-1);
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTestReg);
numTimeStepsTest = numel(XTest);
%for j=1:numel(dataTestStandardized)
for i = 2:251
[net,YPred(:,1)] = predictAndUpdateState(net,YPred(:,i-1),'ExecutionEnvironment','cpu');
end
  1 个评论
Jan
Jan 2019-2-28
"it seems that the code is exceed the boundtry" does not help to understand the error. Prefer to post a copy of the complete error message.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by