Exemplo n.º 1
0
def compute_inertia(k, mean_exposed, mean_infectious, rho0, rho1, delta):
    assert mean_exposed > 0 and mean_infectious > 0 and k > 0 and rho0 > 0
    E_dist = lockdown.gamma_dist(k, mean_exposed/k, n = 10)
    I_dist = lockdown.gamma_dist(k, mean_infectious/k, n = 10)
    EI_dist = lockdown.product_dist(E_dist, I_dist)
    sir = lockdown.SEIR_nonMarkov(rho0, EI_dist, '2020-03-16', 67e6)
    sir.calibrate(10, .05, np.array([[1, 1]]))
    sir.run_up_to_lockdown(verbose = False)
    EIR_lockdown = 1-sir.Z[0]
    sir.change_contact_rate(rho1)
    sir.run(delta)
    EIR_delta = 1-sir.Z[0]
    return EIR_delta/EIR_lockdown
 def prepare_sir(self,
                 EI_dist,
                 p_ref,
                 ref_event='Hospital deaths',
                 verbose=True):
     assert ref_event in self.events
     init_phase = self.fits[0].name
     self.sir = fit_lockdown.SEIR_nonMarkov(
         self.rates[init_phase], EI_dist,
         self.datetime_lockdown.strftime(self.date_format), self.size)
     self.fit_delays()
     self.compute_probas(p_ref, ref_event)
     if verbose:
         print('Mean delays in ' + self.name)
         for (i, event) in enumerate(self.events):
             print(event +
                   ': %.3f' % np.prod(self.param_delays[event].values))
     if not hasattr(self, 'dates_of_change'):
         self.dates_of_change = {}
         for (i, fit) in enumerate(self.fits):
             if i > 0:
                 self.dates_of_change[fit.name] = fit.start
#mode1 = np.zeros(np.shape(beta))
#mode1[:,0] = modes[0,0] + modes[0,1]*(beta[:,0]-.5)
#mode1[:,1] = modes[0,2]*beta[:,1]
#mode2 = np.zeros(np.shape(beta))
#mode2[:,0] = modes[1,0] + modes[1,1]*(beta[:,0]-.5)
#mode2[:,1] = modes[1,2]*beta[:,1]
#I_dist = np.vstack((mode1, mode2))

EI_dist = np.array([[3, 7, .8], [3, 14, .2]])

g = np.sum(EI_dist[:, 2] * EI_dist[:, 1])
e = np.sum(EI_dist[:, 2] * EI_dist[:, 0])

#sir = lockdown.SEIR_lockdown_mixed_delays(N_GE, fit_idf.r, fit_idf.rE, f, g, e, delays)
#sir = lockdown.SIR_nonMarkov(N_idf, fit_idf.r, fit_idf.rE, f, np.array([[7, .8], [14, .2]]), delays)
sir = lockdown.SEIR_nonMarkov(N_idf, fit_idf.r, fit_idf.rE, f, EI_dist, delays)
sir.calibrate(fit_idf.deaths_at_lockdown(), '2020-03-16')
#sir.run(300, record = True)
sir.run_full(lockdown_length, 100, R0_after)
#sir.plot(S = True)
#sir.ax.set_title('Predicted epidemic in Ile de France\ncase fatality rate: %.1f%%' % (100*sir.f))
sir.compute_deaths()
sir.plot_deaths_fit(fit_idf.data)
sir.fig.suptitle('Predicted and observed deaths in Ile de France')
#sir.dfit_axs[1].set_yscale('log')
#sir.dfit_axs[1].plot(sir.times, sir.daily_deaths[-1]*np.exp(fit_idf.rE*(sir.times-sir.times[-1])))
'''
NordEst = deaths[GrandEst + HautsdeFrance].sum(axis = 1)
fit_NordEst = lockdown.Fitter(NordEst, '2020-03-18', 23)
fit_NordEst.fit_init('2020-03-18', '2020-03-25')
fit_NordEst.fit_lockdown('2020-05-10')
Exemplo n.º 4
0
lockdown_length = 55

delay = 15
delay_dist = np.array([[delay, 1]])

EI_dist = lockdown.EI_dist_covid(.8, fixed_E=False, n=20)
I_dist = EI_dist[:, 1:]
incubation_time = np.sum(EI_dist[:, 0] * EI_dist[:, 2])
generation_time = np.sum(EI_dist[:, 1] * EI_dist[:, 2])

#sir_markov = lockdown.SIR_lockdown_mixed_delays(N, r, rE, f, generation_time, delay_dist)
seir_markov = lockdown.SEIR_lockdown_mixed_delays(N, r, rE, f, generation_time,
                                                  incubation_time, delay_dist)
#sir_nonmarkov = lockdown.SIR_nonMarkov(N, r, rE, f, I_dist, delay_dist)
seir_nonmarkov = lockdown.SEIR_nonMarkov(N, r, rE, f, EI_dist, delay_dist)

models = [seir_markov, seir_nonmarkov]
names = ['Markovian SEIR', 'non-Markovian SEIR']
lstyles = ['dashdot', 'solid']

for (i, m) in enumerate(models):
    print(names[i])
    m.calibrate(deaths_at_lockdown, '2020-03-16')
    m.run_full(lockdown_length, 0, 1)
    m.compute_deaths()

fig, axs = plt.subplots(1, 2, dpi=200, figsize=(13, 4.5))

for (i, m) in enumerate(models):
    axs[0].plot(m.times_death, m.deaths, label=names[i], linestyle=lstyles[i])
Exemplo n.º 5
0
#I_dist = np.array([[3, .2], [5, .4], [10, .4]])

# EI_beta = lockdown.product_dist(E_dist, I_dist)

l = 4
E_dist = lockdown.gamma_dist(incub / 2, 2, 300)
I_dist = lockdown.gamma_dist(infect / l, l, 300)

EI_gamma = lockdown.product_dist(E_dist, I_dist)

EI_fix = np.array([[incub, infect, 1]])

# EI_bimod = np.array([[4, 2, .5], [4, 14, .5]])

# sir_beta = lockdown.SEIR_nonMarkov(10, 1, 1, .1, EI_beta, np.array([[1, 1]]))
sir_gamma = lockdown.SEIR_nonMarkov(.2, EI_gamma, '2020-03-16', 10)
sir_markov = lockdown.SEIR_lockdown(.2, infect, incub, '2020-03-16', 10)
sir_fix = lockdown.SEIR_nonMarkov(.2, EI_fix, '2020-03-16', 10)
sir_covid = lockdown.SEIR_nonMarkov(.2, EI_covid, '2020-03-16', 10)
# sir_bimod = lockdown.SEIR_nonMarkov(10, 1, 1, .1, EI_bimod, np.array([[1, 1]]))

S = [sir_markov, sir_fix, sir_covid, sir_gamma]
names = [
    'Markovian SEIR model', 'SEIR model with fixed durations',
    'non-Markovian SEIR model (COVID-19)', 'non-Markovian SEIR model (Gamma)'
]

plt.figure(dpi=200)

contact_rates = np.zeros(np.size(rho))