def get_model(districts, populations, timeseries, seed = 0): units = [ModelUnit( name = district, population = populations[i], I0 = timeseries.loc[district].iloc[-1]['Hospitalized'] if not timeseries.loc[district].empty and 'Hospitalized' in timeseries.loc[district].iloc[-1] else 0, R0 = timeseries.loc[district].iloc[-1]['Recovered'] if not timeseries.loc[district].empty and 'Recovered' in timeseries.loc[district].iloc[-1] else 0, D0 = timeseries.loc[district].iloc[-1]['Deceased'] if not timeseries.loc[district].empty and 'Deceased' in timeseries.loc[district].iloc[-1] else 0, ) for (i, district) in enumerate(districts)] return Model(units, random_seed = seed)
def model(districts, populations, cases, seed) -> Model: max_ts = max([ts.index.max() for ts in cases.values()]).isoformat() units = [ ModelUnit(district, populations[i], I0 = cases[district].loc[max_ts].Hospitalized[0] if district in cases.keys() and max_ts in cases[district].index else 0, R0 = cases[district].loc[max_ts].Recovered[0] if district in cases.keys() and max_ts in cases[district].index else 0, D0 = cases[district].loc[max_ts].Deceased[0] if district in cases.keys() and max_ts in cases[district].index else 0) for (i, district) in enumerate(districts) ] return Model(units, random_seed=seed)
def model(districts, populations, cases, migratory_influx, seed) -> Model: units = [ ModelUnit(district, populations[i], I0 = cases[district].iloc[-1].Hospitalized if district in cases.keys() else 0, R0 = cases[district].iloc[-1].Recovered if district in cases.keys() else 0, D0 = cases[district].iloc[-1].Deceased if district in cases.keys() else 0) for (i, district) in enumerate(districts) ] if migratory_influx: return MigrationSpikeModel(units, introduction_time = 6, migratory_influx = migratory_influx, random_seed=seed) else: return Model(units, random_seed=seed)
def model(districts, populations, cases, seed) -> Model: units = [ ModelUnit(district, populations[i], I0=cases[district].iloc[-1].Hospitalized if district in cases.keys() else 0, R0=cases[district].iloc[-1].Recovered if district in cases.keys() else 0, D0=cases[district].iloc[-1].Deceased if district in cases.keys() else 0) for (i, district) in enumerate(districts) ] return Model(units, random_seed=seed)
import numpy as np from scipy.spatial import distance_matrix import matplotlib.pyplot as plt from adaptive.model import Model, ModelUnit from adaptive.plotting import plot_SIRD names = [f"state{i}" for i in ( 1, 2, 3, 4)] pops = [k * 1000 for k in (10, 1, 2, 2)] # inverse distance transmission matrix centroids = [(0, 0), (1, 0), (0, 1), (2, 0)] P = distance_matrix(centroids, centroids) P[P != 0] = P[P != 0] ** -1.0 # we tried inverse square but Zünd et al. suggest inverse P *= np.array(pops)[:, None] # weight by destination population P /= P.sum(axis = 0) # normalize # states units = lambda rr0: [ModelUnit(name = name, population = pop, RR0 = rr0) for (name, pop) in zip(names, pops)] # run and plot m1_9 = Model(units(1.9), P, 0).run(200) plot_SIRD(m1_9, title = "Four-State Toy Model", xlabel="Time", ylabel="S/I/R/D", subtitle="No Adaptive Controls") plt.show()
def model(wards, populations, cases, seed) -> Model: units = [ ModelUnit(ward, populations.iloc[i], I0=cases[ward].iloc[-1].cases) for (i, ward) in enumerate(wards) ] return Model(units, random_seed=seed)