-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPred_accuracy_bytime.m
215 lines (206 loc) · 6.29 KB
/
Pred_accuracy_bytime.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
%%Pred_accuracy_bytime.m
% Script to compare the prediction accuracy of D5 using different time slots.
% With a few modifications (removing the reading process of a dataset)
% it can calculate the accuracy of different data-sets.
% The predictions change substantially to the published due to yield normalization
% for confidenciality protection.
%% Copyright
% Carlos Alberto Duran-Villalobos June 2020 University of Manchester.
% Data provided by UCL and Sutro
% Copyright (c) Future Targeted Healthcare Manufacturing Hub
% Reference: "Multivariate statistical data analysis of cell-free protein synthesis towards monitoring and control", AIChE
clear all;
%% Initialize variables
X=[]; %Matrix of PCA variables
Y=[]; %Response variables
%% Read process measurements D5
yield = xlsread('D5',1,'G2:G10'); %Read files 1st part
yield = [yield; xlsread('D5',1,'G14:G24')]; %Read files 2nd part
mon = xlsread('D5',1,'H2:H10'); %Read files 1st part
mon = [mon; xlsread('D5',1,'H14:H24')]; %Read files 2nd part
agg = xlsread('D5',1,'I2:I10'); %Read files 1st part
agg = [agg; xlsread('D5',1,'I14:I24')]; %Read files 2nd part
rtime= xlsread('D5',1,'E2:E10');
rtime = [rtime; xlsread('D5',1,'E14:E24')];
DO = xlsread('D5',2,'B2:J1072')';
DO = [DO; xlsread('D5',2,'N2:X1072')'];
pH = xlsread('D5',3,'B2:J1072')';
pH = [pH; xlsread('D5',3,'N2:X1072')'];
T = xlsread('D5',4,'B2:J1072')';
T = [T; xlsread('D5',4,'N2:X1072')'];
O2=xlsread('D5',5,'B2:J1072')';
O2 = [O2; xlsread('D5',5,'N2:X1072')'];
CO2=xlsread('D5',6,'B2:J1072')';
CO2 = [CO2; xlsread('D5',6,'N2:X1072')'];
NH3=xlsread('D5',7,'B2:J1072')';
NH3 = [NH3; xlsread('D5',7,'N2:X1072')'];
% Averaging every hour
time=17;
sampling=1071;
step=floor(sampling/time);
DO2=[];
pH2=[];
T2=[];
O22=[];
CO22=[];
NH32=[];
for i=1:step:sampling-step+1
DO2=[DO2 mean(DO(:,i:i+step-1),2) ];
pH2=[pH2 mean(pH(:,i:i+step-1),2) ];
T2=[T2 mean(T(:,i:i+step-1),2) ];
O22=[O22 mean(O2(:,i:i+step-1),2) ];
CO22=[CO22 mean(CO2(:,i:i+step-1),2) ];
NH32=[NH32 mean(NH3(:,i:i+step-1),2) ];
end
% Assign values to PLS matrices
batches=length(yield);
time=14; %number of hours
X=[];
Y=[];
for i=1:1:batches
Xn=[];
for n=1:1:time
Xn = [Xn pH2(i,n) DO2(i,n) T2(i,n) O22(i,n) NH32(i,n)];
if n>=5
Xn = [Xn CO22(i,n)]; %assign real values only
end
end
X=[X;Xn];
Yn=[];
Yn = [Yn mon(i)]; %Change to yield or agg. for different response variables
Y=[Y;Yn];
end
% calculate prediction errors
%% Using 1h
Xn=X(:,1:5);
[X2,xmean,xstd]=zscore(Xn);
[Y2,ymean,ystd]=zscore(Y);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls1=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 2h
Xn=X(:,1:10);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls2=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 3h
Xn=X(:,1:15);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls3=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 4h
Xn=X(:,1:20);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls4=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 5h
Xn=X(:,1:26);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls5=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 6h
Xn=X(:,1:32);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls6=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 7h
Xn=X(:,1:38);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls7=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 8h
Xn=X(:,1:44);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls8=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 9h
Xn=X(:,1:50);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls9=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 10h
Xn=X(:,1:56);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls10=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 11h
Xn=X(:,1:62);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls11=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Using 12h
Xn=X(:,1:68);
[X2,xmean,xstd]=zscore(Xn);
cv=plscv(X2,Y2,5,10); %10 fold cross validation
lv=cv.optLV; %Obtain the best LV
yest=[];
for i=1:1:batches
yest=[yest; predm(Xn,Y,i,batches,lv) ];
end
yieldmsepls12=100*sum(abs(Y-yest)./(0.5*(abs(Y)+abs(yest))))/batches;
%% Plot results
mse=[yieldmsepls1 yieldmsepls2 yieldmsepls3 yieldmsepls4 yieldmsepls5 yieldmsepls6 yieldmsepls7 yieldmsepls8 yieldmsepls9 yieldmsepls10 yieldmsepls11 yieldmsepls12];
figure(5)
bar(mse)
hold on;
title('Monomer % SMAPE using MPLS')
% xticklabels({'1','2','1&2 Missing Data','1&2 First 6h'})
ylabel('RMSE of prediction %');
xlabel('Time (h)');
%legend({'MLR','PLS','QPLS','ENCV'})
grid on
set(findall(gcf,'-property','FontSize'),'FontSize',28)