필터 지우기
필터 지우기

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