-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSTM_matlab_huy.m
96 lines (77 loc) · 2.43 KB
/
LSTM_matlab_huy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
% Many-to-one LSTM for oxygen uptake prediction
clear all
close all
load inputFeatures11_sorted.mat
%load LSTM_results_8.mat
% Input features for each step: speed, speedChange, step Duration
% verticalOscillations
% Input sequence length 50 steps
%input_length = 10; % 10
% LSTM net
% Layers
numFeatures = 4;
%size(XTest{1},1); % 4 input features
numHiddenUnits1 = 125;
numHiddenUnits2 = 150;
numResponses = 1; % one target feature
layers = [ ...
sequenceInputLayer(numFeatures, Normalization="rescale-symmetric")
%lstmLayer(numHiddenUnits1,'OutputMode','sequence')
%dropoutLayer(0.2)
lstmLayer(numHiddenUnits2,'OutputMode','last')
%dropoutLayer(0.2)
fullyConnectedLayer(numResponses)
regressionLayer];
% sequenceInputLayer(numFeatures)
% lstmLayer(numHiddenUnits1,'OutputMode','sequence')
% dropoutLayer(0.2)
% lstmLayer(numHiddenUnits2,'OutputMode','last')
% dropoutLayer(0.2)
% fullyConnectedLayer(numClasses)
% Options
maxEpochs = 8000;
% options = trainingOptions('adam', ...
% 'ExecutionEnvironment','cpu', ...
% 'MaxEpochs',maxEpochs, ...
% 'SequenceLength','longest', ...
% 'Shuffle','never', ...
% 'Verbose',0, ...
% 'Plots','training-progress');
options = trainingOptions("adam", ...
'ExecutionEnvironment','cpu', ...
'MaxEpochs',maxEpochs, ...
InitialLearnRate=0.005, ...
SequenceLength="shortest", ...
Plots="training-progress", ...
Verbose= false);
% one input feature
for k=1:length(XTrain)
XTrain1{k} = XTrain{k}(1:4,:);
end
for k=1:length(XTest)
XTest1{k} = XTest{k}(1:4,:);
end
% Network training
net = trainNetwork(XTrain1',TTrain',layers,options);
Ypred = predict(net, XTest1);
rmse=sqrt(mean((Ypred(:)-TTest(:)).^2));
[Tsorted idxY] = sort(TTest);
Ysorted = Ypred(idxY);
%plot(1:length(Ypred), Ypred,'or', 1:length(TTest), TTest,'*b')
plot(1:length(Ypred), Ysorted,'or', 1:length(TTest), Tsorted,'*b')
title('Oxygen uptake prediction for participant #1, LSTM with 4 input features')
legend('predicted','measured')
xlabel('steps')
ylabel('oxygen uptake, ml/min/kg')
grid
%
title('Bland-Altman plot for participant #1')
legend('VO2 difference','mean','standard deviation')
xlabel('oxygen uptake, ml/min/kg')
ylabel('measured - predicted , ml/min/kg')
grid
networkSave = net;
save ('model_11_sorted_speed_only.mat','networkSave')
Ypred = Ypred';
save ('output_11_speed_only.mat','Ypred','TTest')
save LSTM_results_11_speed_only.mat net Ypred