フィルターのクリア

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 Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by