@@ -85,31 +85,25 @@ def __init__(self, p: Parameters):
85
85
elif p .date_first_hospitalized is not None and p .doubling_time is None :
86
86
# Fitting spread parameter to observed hospital census (dates of 1 patient and today)
87
87
self .i_day = (p .current_date - p .date_first_hospitalized ).days
88
+ self .current_hospitalized = p .current_hospitalized
88
89
logger .info (
89
- 'Using date_first_hospitalized: %s; current_date: %s; i_day: %s' ,
90
+ 'Using date_first_hospitalized: %s; current_date: %s; i_day: %s, current_hospitalized: %s ' ,
90
91
p .date_first_hospitalized ,
91
92
p .current_date ,
92
- self .i_day )
93
- min_loss = 2.0 ** 99
94
- dts = np .linspace (1 , 15 , 29 )
95
- losses = np .full (dts .shape [0 ], np .inf )
96
- self .current_hospitalized = p .current_hospitalized
97
- for i , i_dt in enumerate (dts ):
98
- intrinsic_growth_rate = get_growth_rate (i_dt )
99
- self .beta = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , 0.0 )
100
- self .beta_t = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , p .relative_contact_rate )
93
+ self .i_day ,
94
+ p .current_hospitalized ,
95
+ )
101
96
102
- self .run_projection (p , self .gen_policy (p ))
97
+ # Make an initial coarse estimate
98
+ dts = np .linspace (1 , 15 , 29 )
99
+ min_loss = self .get_argmin_doubling_time (p , dts )
103
100
104
- # Skip values the would put the fit past peak
105
- peak_admits_day = self .admits_df .hospitalized .argmax ()
106
- if peak_admits_day < 0 :
107
- continue
101
+ # Refine the coarse estimate
102
+ dts = np .linspace (dts [min_loss - 1 ], dts [min_loss + 1 ], 29 )
103
+ min_loss = self .get_argmin_doubling_time (p , dts )
108
104
109
- loss = self .get_loss ()
110
- losses [i ] = loss
105
+ p .doubling_time = dts [min_loss ]
111
106
112
- p .doubling_time = dts [pd .Series (losses ).argmin ()]
113
107
logger .info ('Estimated doubling_time: %s' , p .doubling_time )
114
108
intrinsic_growth_rate = get_growth_rate (p .doubling_time )
115
109
self .beta = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , 0.0 )
@@ -151,6 +145,26 @@ def __init__(self, p: Parameters):
151
145
self .daily_growth_rate = get_growth_rate (p .doubling_time )
152
146
self .daily_growth_rate_t = get_growth_rate (self .doubling_time_t )
153
147
148
+ def get_argmin_doubling_time (self , p : Parameters , dts ):
149
+ losses = np .full (dts .shape [0 ], np .inf )
150
+ for i , i_dt in enumerate (dts ):
151
+ intrinsic_growth_rate = get_growth_rate (i_dt )
152
+ self .beta = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , 0.0 )
153
+ self .beta_t = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , p .relative_contact_rate )
154
+
155
+ self .run_projection (p , self .gen_policy (p ))
156
+
157
+ # Skip values the would put the fit past peak
158
+ peak_admits_day = self .admits_df .hospitalized .argmax ()
159
+ if peak_admits_day < 0 :
160
+ continue
161
+
162
+ loss = self .get_loss ()
163
+ losses [i ] = loss
164
+
165
+ min_loss = pd .Series (losses ).argmin ()
166
+ return min_loss
167
+
154
168
def gen_policy (self , p : Parameters ) -> Sequence [Tuple [float , int ]]:
155
169
if p .mitigation_date is not None :
156
170
mitigation_day = - (p .current_date - p .mitigation_date ).days
0 commit comments