def synthetic_exp_with_seed(seed, beta, gamma, n, t, model):
    random.seed(seed)
    np.random.seed(seed)
    # origin-destination flow matrix => should be replaced by estimation from flight network
    population_0 = random_population(n)
    sir_0 = random_SIR_0(population_0)
    sir = COVID_MODELS[model](population_0, sir_0, t, beta, gamma)
    no_sir, no_pop = sir.run(no_mobility_mobility_matrix(n))
    ba_sir, ba_pop = sir.run(barabasi_albert_mobility_matrix(n, 3))
    er_sir, er_pop = sir.run(erdos_renyi_graph_mobility_matrix(n, 0.25))
    results = np.array([
        compute_global_seir(no_sir, no_pop),
        compute_global_seir(ba_sir, ba_pop),
        compute_global_seir(er_sir, er_pop)
    ])
    return results
def base_exp(e_0, i_0, r_0, beta, n, sigma, symptomatic_rate, gamma, t):
    s_0 = n - e_0 - i_0 - r_0
    seir_0 = np.array(
        [s_0, e_0, i_0 * symptomatic_rate, i_0 * (1 - symptomatic_rate), r_0])
    model2 = ClassicSEIR(np.array([n]),
                         seir_0,
                         beta=beta,
                         sigma=sigma,
                         symptomatic_rate=symptomatic_rate,
                         gamma=gamma,
                         num_days=t)
    base_seir, base_pop = model2.run()
    base = compute_global_seir(base_seir, base_pop)
    return base
def estimate_base(beta_range, n, t, sigma, gamma, tr_sir, symptomatic_rate, e_0_range, i_0_range, r_0_range):
    best_beta, best_e_0, best_i_0, best_r_0, min_error = 1, 1, 1, 1, sys.maxsize
    for beta in beta_range:
        for e_0 in e_0_range:
            for i_0 in i_0_range:
                for r_0 in r_0_range:

                    s_0 = n - e_0 - i_0 - r_0
                    seir_0 = np.array([s_0, e_0, i_0 * symptomatic_rate, i_0 * (1 - symptomatic_rate), r_0])
                    model2 = ClassicSEIR(np.array([n]), seir_0, beta=beta, sigma=sigma,
                                         symptomatic_rate=symptomatic_rate, gamma=gamma, num_days=t)
                    base_seir, base_pop = model2.run()
                    results = compute_global_seir(base_seir, base_pop)

                    error = compute_error(results[:15, 2], tr_sir[:15, 2], t)

                    if error < min_error:
                        min_error = error
                        best_beta = beta
                        best_e_0 = e_0
                        best_i_0 = i_0
                        best_r_0 = r_0

    return best_beta, best_e_0, best_i_0, best_r_0