Ejemplo n.º 1
0
def sim_chimes(scenarios: str, p: Parameters = None):
    """
    Run many chime simulations.

    If `params` is not None, then it is used to initialize all parameters. Any
    parameter values set to something other than None in the following
    optional args will update that parameter value. If `params` is None, then
    all additional args must be other than None. These settings are just
    for the base parameter values. We can run stuff over ranges as we see it.

    :param scenarios:
    :param params:

    :return:
    """

    base_input_params_dict = vars(p)

    # Create a range of social distances

    soc_dists = np.arange(0.05, 0.60, 0.05)
    # array([0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55, 0.6 ])

    num_scenarios = len(soc_dists)

    # We can store outputs any way we want. For this demo, just going to
    # use a master list. # This will be a list of dicts of the
    # result dataframes (+ 1 dict containing the scenario inputs)

    results_list = []

    for sd_pct in soc_dists:
        sim_scenario = '{}{:.0f}'.format(scenarios, 100 * sd_pct)

        # Update the parameters for this scenario
        p.relative_contact_rate = sd_pct
        input_params_dict = vars(p)

        # Run the model
        m = Model.SimSirModel(p)

        # Gather results
        results = gather_sim_results(m, sim_scenario, input_params_dict)

        # Append results to results list

        results_list.append(results.copy())

    return results_list
Ejemplo n.º 2
0
def sim_chimes(
    scenarios: str,
    params: Parameters = None,
    current_hospitalized: int = None,
    doubling_time: float = None,
    known_infected: int = None,
    relative_contact_rate: float = None,
    susceptible: int = None,
    hospitalized: RateLos = None,
    icu: RateLos = None,
    ventilated: RateLos = None,
    market_share: float = None,
    n_days: int = None,
    recovery_days: float = None,
):
    """
    Run many chime simulations.

    If `params` is not None, then it is used to initialize all parameters. Any
    parameter values set to something other than None in the following
    optional args will update that parameter value. If `params` is None, then
    all additional args must be other than None. These settings are just
    for the base parameter values. We can run stuff over ranges as we see it.

    :param scenarios:
    :param params:
    :param current_hospitalized:
    :param doubling_time:
    :param known_infected:
    :param relative_contact_rate:
    :param susceptible:
    :param hospitalized:
    :param icu:
    :param ventilated:
    :param market_share:
    :param n_days:
    :param recovery_days:
    :return:
    """

    if params is not None:
        params_dict = vars(params)
    else:
        params_dict = {
            "current_hospitalized": None,
            "doubling_time": None,
            "known_infected": None,
            "relative_contact_rate": None,
            "susceptible": None,
            "hospitalized": None,
            "icu": None,
            "ventilated": None,
            "market_share": None,
            "n_days": None,
            "recovery_days": None,
        }

    # Check for parameter updates passed
    vals_passed = {
        key: value
        for (key, value) in vars().items()
        if key not in ['scenario', 'params']
    }

    for key, value in vals_passed.items():
        if value is not None:
            params_dict[key] = value

    # Create Parameters object
    p = Parameters(
        current_hospitalized=params_dict['current_hospitalized'],
        doubling_time=params_dict['doubling_time'],
        known_infected=params_dict['known_infected'],
        market_share=params_dict['market_share'],
        n_days=params_dict['n_days'],
        relative_contact_rate=params_dict['relative_contact_rate'],
        susceptible=params_dict['susceptible'],
        hospitalized=params_dict['hospitalized'],
        icu=params_dict['icu'],
        ventilated=params_dict['ventilated'],
    )

    base_input_params_dict = vars(p)

    # Create a range of social distances

    soc_dists = np.arange(0.05, 0.60, 0.05)
    # array([0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 , 0.55,
    #        0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85])

    num_scenarios = len(soc_dists)

    # We can store outputs any way we want. For this demo, just going to
    # use a master list. # This will be a list of dicts of the
    # result dataframes (+ 1 dict containing the scenario inputs)

    results_list = []

    for sdpct in soc_dists:
        sim_scenario = '{}{:.0f}'.format(scenarios, 100 * sdpct)

        # Update the parameters for this scenario
        p.relative_contact_rate = sdpct
        input_params_dict = vars(p)

        # Run the model
        m = SimSirModel(p)

        # Gather results
        results = gather_sim_results(m, sim_scenario, input_params_dict)

        # Append results to results list

        results_list.append(results.copy())

    return results_list