predictAndUpdateState関数で時系列の予測とネットワークの更新をするときに起きた問題
Show older comments
predictAndUpdateState関数でネットワークの更新と将来の予測を行っているのですが、
[net, YT1pred]=predictAndUpdateState(net, YT1Train(end),'ExecutionEnvironment','auto');
とすると「不適切なネットワークの状態。ネットワークでは 14 のミニバッチ サイズが必要ですが、サイズ 1 のミニバッチが渡されました。」というエラーを吐き出しました。
(深層学習を使用した時系列予測というドキュメンテーションなどを参考にしました
)
一方、
[net, YT1pred]=predictAndUpdateState(net, YT1Train(end-13:end),'ExecutionEnvironment','auto');
とすると通りました。トレーニングオプションにおいてミニバッチのエポックの最大回数は変えましたがミニバッチのサイズは調整していないので上の修正で通る理由がわかりません。(上記の深層学習を使用した時系列予測とミニバッチサイズは同じ値でした)
また、predictAndUpdateState上でミニバッチサイズを調整することはできるでしょうか?predictAndUpdateState関数内の入力引数でミニバッチサイズを指定しても無理でした。
%スプレッドシート読み込み (Read the Spreadsheet)
opts = detectImportOptions('pressure_data_20190326_1.xlsx','DataRange','B5');
T1=readtable('pressure_data_20190326_1.xlsx',opts,'ReadVariableNames',false);
T1_data = T1.Variables;
%1行N列の配列へ(Convert to 1×N array)
for i=1:300
T1_array{i}=T1_data(1:end,i)';
end
%転置 (Transpose)
T1_a=(T1_array)';
%シーケンスの最初の90%で学習を行い残りの10%でテストする (Partition the training and test data. Train on the first 90% of the sequence and test on the last 10%.)
numTimeStepsTrain = floor(0.9*numel(T1_a));
T1Train = T1_a(1:numTimeStepsTrain+1);
T1Test = T1_a(numTimeStepsTrain+1:end);
%予測子と応答の準備 (Prepare Predictors and Responses)
XT1Train = T1Train(1:end-1);
YT1Train = T1Train(2:end);
%lstmアーキテクチャ定義 (Define LSTM Network Architecture)
numFeatures=1;
numResponse=1;
numHiddenUnits=200;
%LSTM層 (LSTM layers)
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(200)
fullyConnectedLayer(numResponse)
regressionLayer];
%トレーニングオプション (trainingoptions)
options = trainingOptions('adam', ...
'MaxEpochs',20, ...
'GradientThreshold',1, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',10, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress')
%LSTMネットワークの学習 (Train LSTM Network)
net = trainNetwork(XT1Train,YT1Train,layers,options);
%将来のタイムステップの予測 (Forecast Future Time Steps)
XT1Test=T1Test(1:end-1);
net=predictAndUpdateState(net,XT1Train);
[net, YT1pred]=predictAndUpdateState(net, YT1Train(end),'ExecutionEnvironment','auto');
%[net, YT1pred]=predictAndUpdateState(net, YT1Train(end-13:end),'ExecutionEnvironment','auto');
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!