-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimulationModel.m
More file actions
108 lines (79 loc) · 3.5 KB
/
SimulationModel.m
File metadata and controls
108 lines (79 loc) · 3.5 KB
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
classdef SimulationModel < handle
% Class to simulate the TMDD model
properties
% original values for resetting
Amount0 (1,1) double
Duration0 (1,1) double
Kon0 (1,1) double
Kel0 (1,1) double
Kdeg0 (1,1) double
Interval0 (1,1) double
end
properties ( Dependent )
ROIsBetweenThresholds (1,1) logical
end
properties ( SetAccess = private )
SimDataTable
SimData
end
properties ( Hidden )
% Leave these properties Hidden but public to enable access for any test generated
% with Copilot during workshop
DoseTable % daily dose to apply to simulate
SimFun % exported SimFunction
ThresholdValues = [20, 80] % threshold values
end
events ( NotifyAccess = public )
% Leave this notification public to enable access for any test generated
% with Copilot during workshop
DataChanged
end
methods
function obj = SimulationModel()
% load Simfunction and dosing information
load('simFunction_Dose.mat', 'simFun', 'doseTable');
obj.SimFun = simFun;
obj.DoseTable = doseTable;
% save original values to allow for resetting
obj.Kel0 = obj.SimFun.Parameters.Value(1);
obj.Kon0 = obj.SimFun.Parameters.Value(2);
obj.Kdeg0 = obj.SimFun.Parameters.Value(3);
obj.Duration0 = 119;
obj.Interval0 = obj.DoseTable.Interval;
obj.Amount0 = obj.DoseTable.Amount;
end % constructor
end
methods
function simulate(obj, parameters)
arguments
obj
parameters (1,6) double {mustBePositive} = [obj.Kel0, ...
obj.Kon0, obj.Kdeg0 ,obj.Duration0, ...
obj.Amount0, obj.Interval0]
end
cellpar = num2cell(parameters);
[kel, kon, kdeg,stopTime, amount, interval] = deal(cellpar{:});
obj.DoseTable.Amount = amount;
obj.DoseTable.Interval = interval;
sd = obj.SimFun([kel, kon, kdeg], stopTime, obj.DoseTable);
t = array2table([sd.Time, sd.Data], 'VariableNames',[{'Time'}; sd.DataNames]);
t.Properties.VariableUnits = [{'hours'}; cellfun(@(x) x.Units, sd.DataInfo, 'UniformOutput', false)];
% add dosing information to table to compute NCA parameters
t.Dose = NaN(height(t),1);
dosingTimes = interval*(0:stopTime/interval);
t.Dose(ismember(t.Time, dosingTimes)) = amount;
idxNotIncreasing = diff(t.Time)<=0; % remove duplicates
t(idxNotIncreasing,:) = [];
obj.SimData = sd;
obj.SimDataTable = t;
notify( obj, 'DataChanged' );
end % simulate
function value = get.ROIsBetweenThresholds(obj)
% logical value to check whether or not RO remains between thresholds after day 1
timeAfter24h = obj.SimDataTable.Time >= 24;
ROAfter24h = obj.SimDataTable.RO(timeAfter24h);
value = all(ROAfter24h >= obj.ThresholdValues(1)/100) && ...
all(ROAfter24h <= obj.ThresholdValues(2)/100);
end % get.ROIsBetweenThresholds()
end % public methods
end % classdef