predictAndUpdateState関数での観測値を用いたネットワークの更新について
Show older comments
深層学習を用いて時系列データの処理を行っているのですが、以下のプログラムを書いて実行したところ最後のfor文内の
[net,YT1pred(:,i)]=predictAndUpdateState(net,XT1Test(:,i),'ExecutionEnvironment','auto');
の部分でエラーを吐き、
「cell からdoubleに変換できない」と警告されました。
ネットワークのリセット以外は将来のタイムステップ予測のところでも似たようなfor文の処理
[net,YT1pred(:,i)]=predictAndUpdateState(net,YT1pred(:,i-1),'ExecutionEnvironment','auto');
を行っており、予測子YT1predを区別してみるなどでワークスペースで一つ一つ確認したところ入力引数の型(cell)は同じだと思いました。
そこで修正方法と可能であればなぜ最後のfor文でエラーを吐いたのかの原因を知りたいです。
以下ソースコード
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列の配列へ
for i=1:300
T1_array{i}=T1_data(1:end,i)';
end
%転置
T1_a=(T1_array)';
%シーケンスの最初の90%で学習を行い残りの10%でテストする
numTimeStepsTrain = floor(0.9*numel(T1_a));
T1Train = T1_a(1:numTimeStepsTrain+1);
T1Test = T1_a(numTimeStepsTrain+1:end);
%予測子と応答の準備
XT1Train = T1Train(1:end-1);
YT1Train = T1Train(2:end);
%lstmアーキテクチャ 定義
numFeatures=1;
numResponse=1;
numHiddenUnits=200;
%lstm層
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(200)
fullyConnectedLayer(numResponse)
regressionLayer];
%トレーニングオプション
options = trainingOptions('adam', ...
'MaxEpochs',20, ...
'GradientThreshold',1, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',10, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress')
net = trainNetwork(XT1Train,YT1Train,layers,options);
XT1Test=T1Test(1:end-1);
net=predictAndUpdateState(net,XT1Train,'MiniBatchSize',1);
[net, YT1pred]=predictAndUpdateState(net, YT1Train(end),'ExecutionEnvironment','auto');
numTimeStepsTest=numel(XT1Test);
for i=2:numTimeStepsTest
[net,YT1pred(:,i)]=predictAndUpdateState(net,YT1pred(:,i-1),'ExecutionEnvironment','auto');
end
%観測値によるネットワーク状態の更新
net=resetState(net);
net=predictAndUpdateState(net,XT1Train,'MiniBatchSize',1);
YT1pred=[];
numTimeStepsTest=numel(XT1Test);
%転置
XT1Test=transpose(XT1Test);
for i=1:numTimeStepsTest
[net,YT1pred(:,i)]=predictAndUpdateState(net,XT1Test(:,i),'ExecutionEnvironment','auto');
end
1 Comment
michio
on 16 Oct 2019
勝手ながらコード表示を編集させて頂きました。

赤丸の部分、もしよろしければ活用ください。
Accepted Answer
More Answers (1)
Naoto Iwaki
on 17 Oct 2019
0 votes
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!