@@ -64,21 +64,40 @@ def __init__(self, p: Parameters):
64
64
logger .info ('Using doubling_time: %s' , p .doubling_time )
65
65
66
66
intrinsic_growth_rate = get_growth_rate (p .doubling_time )
67
-
68
67
self .beta = get_beta (intrinsic_growth_rate , gamma , self .susceptible , 0.0 )
69
68
self .beta_t = get_beta (intrinsic_growth_rate , self .gamma , self .susceptible , p .relative_contact_rate )
70
69
71
- self .i_day = 0 # seed to the full length
72
- raw = self .run_projection (p , [(self .beta , p .n_days )])
73
- self .i_day = i_day = int (get_argmin_ds (raw ["census_hospitalized" ], p .current_hospitalized ))
70
+ if p .mitigation_date is None :
71
+ self .i_day = 0 # seed to the full length
72
+ raw = self .run_projection (p , [(self .beta , p .n_days )])
73
+ self .i_day = i_day = int (get_argmin_ds (raw ["census_hospitalized" ], p .current_hospitalized ))
74
74
75
- self .raw = self .run_projection (p , self .gen_policy (p ))
75
+ self .raw = self .run_projection (p , self .gen_policy (p ))
76
+
77
+ logger .info ('Set i_day = %s' , i_day )
78
+ else :
79
+ projections = {}
80
+ best_i_day = - 1
81
+ best_i_day_loss = float ('inf' )
82
+ for i_day in range (p .n_days ):
83
+ self .i_day = i_day
84
+ raw = self .run_projection (p , self .gen_policy (p ))
85
+
86
+ # Don't fit against results that put the peak before the present day
87
+ if raw ["census_hospitalized" ].argmax () < i_day :
88
+ continue
89
+
90
+ loss = get_loss (raw ["census_hospitalized" ][i_day ], p .current_hospitalized )
91
+ if loss < best_i_day_loss :
92
+ best_i_day_loss = loss
93
+ best_i_day = i_day
94
+ self .raw = raw
95
+
96
+ self .i_day = best_i_day
76
97
77
- logger .info ('Set i_day = %s' , i_day )
78
- p .date_first_hospitalized = p .current_date - timedelta (days = i_day )
79
98
logger .info (
80
99
'Estimated date_first_hospitalized: %s; current_date: %s; i_day: %s' ,
81
- p .date_first_hospitalized ,
100
+ p .current_date - timedelta ( days = self . i_day ) ,
82
101
p .current_date ,
83
102
self .i_day )
84
103
0 commit comments