forked from fja-relouw/InflammationODE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcost_func.m
31 lines (25 loc) · 1.16 KB
/
cost_func.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
function e = cost_func(param, mode, data)
% COST_FUNC calculates the error between experimental and simulated cytokine concentrations
e = [];
for i = 1:length(mode)
x = mode(i);
% Retrieve experimental data
[t, TNF, IL6, IL10, IL1, ~, Temp, BP, HR, ~, corrTNF, corrIL6, corrIL10] = data_model(x, data);
% Simulate cytokine concentrations
[tsim, ysim] = model_code(x, param, 0, 0, 0, Temp(1), BP(1), HR(1));
% Interpolate simulated cytokine concentrations to match experimental time points
TNF_simulated = interp1(tsim, real(ysim(:,5)), t, 'spline');
IL6_simulated = interp1(tsim, real(ysim(:,7)), t, 'spline');
% Calculate squared error for TNF and IL6
TNFerror = corrTNF * ((TNF - TNF_simulated) ./ max(TNF)).^2;
IL6error = corrIL6 * ((IL6(1:7) - IL6_simulated(1:7)) ./ max(IL6)).^2;
% Calculate error for IL10 if available
if corrIL10 == 1
IL10_simulated = interp1(tsim, real(ysim(:,9)), t, 'spline');
IL10error = corrIL10 * ((IL10 - IL10_simulated) ./ max(IL10)).^2;
e = [e; TNFerror; IL6error; IL10error];
else
e = [e; TNFerror; IL6error];
end
end
end