Пример #1
0
def run_model_mp(parameters_i):
    print(mp.current_process())

    # Calculate and save the aggregated log-likelihood - total, children and adult (median of 5 runs)
    # likelihoods = []
    # likelihoods_by_age = []
    likelihoods_by_subdist = []

    for i in range(m):
        # Run model and get results
        # model_results = model.run_coupled_model(parameters_i, parameters_v, prep_data, season)  # TODO: CHANGE BACK TO NETWORK MODEL
        model_results = model.run_coupled_model(parameters_i,
                                                parameters_v,
                                                prep_data,
                                                season,
                                                homogenous=True)

        # Calculate log likelihood
        # By clinic and age
        # log_likelihood = model.log_likelihood_influenza(model_results['lambdas'],
        #                                                 data_for_fit_i['by_clinic_age'], season=season)
        # # By age
        # log_likelihood_age = model.log_likelihood_agg_age_influenza(model_results, data_for_fit_i, season=season)

        # By subdist and age
        log_likelihood_age_subdist = model.log_likelihood_agg_by_subdist_influenza(
            model_results['lambdas'], data_for_fit_i['by_subdist'], season,
            prep_data)

        # Add to the lists
        # likelihoods.append(log_likelihood)
        # likelihoods_by_age.append(log_likelihood_age)
        likelihoods_by_subdist.append(log_likelihood_age_subdist)

    # Calculate medians
    # med_likelihood = np.argsort(np.array(likelihoods))[len(likelihoods)//2]
    # med_likelihood_age = np.argsort(np.array(likelihoods_by_age))[len(likelihoods_by_age)//2]
    med_likelihood_subdist = np.argsort(
        np.array(likelihoods_by_subdist))[len(likelihoods_by_subdist) // 2]

    # Return parameters, log-likelihoods and MSEs
    return {
        'parameters': parameters_i,
        'log_likelihood_subdist':
        likelihoods_by_subdist[med_likelihood_subdist]
    }
Пример #2
0
def run_model_mp(x):
    print(mp.current_process())

    # Run the model for all 7 seasons
    model_results_all_seasons = [model.run_coupled_model(parameters_i, parameters_v, prep_data, season) for season in model.seasons]

    # Run the model for 1 season
    # model_results = model.run_coupled_model(parameters_i, parameters_v, prep_data, season, vacc_start=vacc_start)

    # Calculate likelihood for each season
    likelihood_by_season = model.calculate_likelihood_lists_all_seasons(model_results_all_seasons, data_for_fit_i, prep_data, single=True)

    # Filter model results - keep only relevant fields
    model_results_filtered = [{'new_Is': res['new_Is'], 'new_Is_by_age': res['new_Is_by_age'], 'Is_by_clinic_age': res['Is_by_clinic_age'],
                               'new_Iv': res['new_Iv'], 'new_Iv_by_age': res['new_Iv_by_age'], 'Iv_by_clinic_age': res['Iv_by_clinic_age']}
                              for res in model_results_all_seasons]

    return {'model_results': model_results_filtered, 'likelihood_by_season': likelihood_by_season}