Example #1
0
def simulate_monte_carlo(seed):
    from variables import allow_set_variable, get_variable, set_variable

    with allow_set_variable():
        set_variable('random_seed', seed)
        print(seed)
        df = simulate_individuals(skip_cache=True)
        df['run'] = seed

    return df
Example #2
0
def run_monte_carlo(scenario_name):
    from scenarios import SCENARIOS
    from variables import allow_set_variable

    for scenario in SCENARIOS:
        if scenario.id == scenario_name:
            break
    else:
        raise Exception('Scenario not found')

    with allow_set_variable():
        scenario.apply()

    print(scenario.id)
    with multiprocessing.Pool(processes=8) as pool:
        dfs = pool.map(simulate_monte_carlo, range(1000))

    df = pd.concat(dfs)
    df.index.name = 'date'
    df = df.reset_index()
    df['scenario'] = scenario.id
    df.to_csv('reina_%s.csv' % scenario.id, index=False)

    return df
Example #3
0
    with multiprocessing.Pool(processes=8) as pool:
        dfs = pool.map(simulate_monte_carlo, range(1000))

    df = pd.concat(dfs)
    df.index.name = 'date'
    df = df.reset_index()
    df['scenario'] = scenario.id
    df.to_csv('reina_%s.csv' % scenario.id, index=False)

    return df


if __name__ == '__main__':
    if False:
        from variables import allow_set_variable, get_variable, set_variable
        with allow_set_variable():
            set_variable('simulation_days', 50)
            df = simulate_individuals()
            exit()
    if False:
        from scenarios import SCENARIOS
        for scenario in SCENARIOS:
            df = run_monte_carlo(scenario.id)
            print(df[df.date == df.date.max()])
            last = df[df.date == df.date.max()]
            print(last.dead.describe(percentiles=[.25, .5, .75]))
        exit()

    if False:
        sample_model_parameters('symptom_severity', 90)
        exit()