-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQSSA_Threshold.m
56 lines (51 loc) · 1.47 KB
/
QSSA_Threshold.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
% Developer: Yun Min Song
% Input:
% - Kd: Normalized dissociation constant (dissociation constant * volume)
% - epsilon: Error tolerance
% Output:
% - AT_Bound: The minimum state of AT where the stQSSA approximate the
% stochastic QSSA within a relative error of epsilon for given Kd value.
% (i.e. when AT >= AT_thres, the relative error of the stQSSA to the
% stochastic QSSA is less than epsilon)
% - L: The minimum number of states that the slQSSA requires to
% approximate the stochastic QSSA of A (<A>) within epsilon relative
% error when AT < AT_thres for given Kd value.
% (i.e. when AT < AT_thres, the relative error of the L-state slQSSA to the
% stochastic QSSA is less than epsilon)
function [AT_thres, L] = QSSA_Threshold(Kd, epsilon)
%% Binary Search
L = 0;
R = ceil(1/(epsilon^2 * Kd)); % Upper bound of the stQSSA relative error
while L < R - 1
m = floor((L+R) / 2);
if tQerror(Kd,m) < epsilon
R = m;
else
L = m + 1;
end
end
AT_thres = R;
%% find minimum state number
A = LQSSA(AT_thres-1,AT_thres-1,Kd,AT_thres);
RA_L = Inf;
L = 1;
while RA_L > epsilon
L = L+1;
A_lq = LQSSA(AT_thres-1,AT_thres-1,Kd,L);
RA_L = abs(A_lq/A - 1);
end
end
function RA_max = tQerror(Kd, AT)
RA_max = 0;
BT = AT;
while 1
A = LQSSA(AT,BT,Kd,AT+1);
A_tq = (AT-BT-Kd + sqrt((AT-BT-Kd)^2 + 4*AT*Kd))/2;
if abs(A_tq/A - 1) >= RA_max
RA_max = abs(A_tq/A - 1);
else
break
end
BT = BT + 1;
end
end