コード例 #1
0
def main(load_inter_flag=False):
    if not load_inter_flag:
        real_data = list(pd.read_csv(get_data_path(True))['adcode'].unique())
        start_date = date(2020, 1, 24)
        real_data1 = pd.read_csv(get_data_path(True))
        history_real = prepareData(real_data1)
        rerun_cities = None
        for i in range(get_seed_num()):
            total_params = pd.read_csv(
                os.path.join(os.path.dirname(__file__),
                             './params_foreign{}.csv'.format(int(i))))
            for ind, city in enumerate(real_data):
                print(i, ind, city, str(get_important_date(city)))
                x = get_params(total_params, city)
                if rerun_cities is None or city in rerun_cities:
                    run_simulation2(x,
                                    city,
                                    60,
                                    60,
                                    start_date,
                                    get_important_date(city),
                                    history_real,
                                    unob_flow_num=None,
                                    json_name='data_run_foreign{}.json'.format(
                                        int(i)))
    # choose the final parameters
    max_data, min_data, mean_data, best_data, \
    std_data, middle_data, xmin_data, xmax_data, \
    xmean_data, xstd_data = load_and_save('./data_run_foreign{}.json', './data_run_foreign_{}.json')
    """
コード例 #2
0
def load_and_save(input_format, output_format, num=None, start_ind=0):
    if num is None:
        num = get_seed_num()
    data_buffer = [
        json.load(open(input_format.format(int(i)), 'r'))
        for i in range(start_ind, num + start_ind)
    ]
    max_data, min_data, mean_data, best_data, std_data, middle_data, xmin_data, xmax_data, xmean_data, xstd_data = res_analysis(
        data_buffer)
    with open(output_format.format('min'), 'w') as f:
        f.write(json.dumps(min_data))

    with open(output_format.format('max'), 'w') as f:
        f.write(json.dumps(max_data))

    with open(output_format.format('mean'), 'w') as f:
        f.write(json.dumps(mean_data))

    with open(output_format.format('best'), 'w') as f:
        f.write(json.dumps(best_data))

    with open(output_format.format('std'), 'w') as f:
        f.write(json.dumps(std_data))

    with open(output_format.format('middle'), 'w') as f:
        f.write(json.dumps(middle_data))
    with open(output_format.format('xmin'), 'w') as f:
        f.write(json.dumps(xmin_data))
    with open(output_format.format('xmax'), 'w') as f:
        f.write(json.dumps(xmax_data))
    with open(output_format.format('xmean'), 'w') as f:
        f.write(json.dumps(xmean_data))
    with open(output_format.format('xstd'), 'w') as f:
        f.write(json.dumps(xstd_data))
    return max_data, min_data, mean_data, best_data, std_data, middle_data, xmin_data, xmax_data, xmean_data, xstd_data
コード例 #3
0
def prepare_data_china(load_inter_flag=False):
    real_data = pd.read_csv(get_data_path())['adcode'].unique()
    rerun_cities = None
    if rerun_cities is not None:
        real_data = rerun_cities.copy()
    start_date = date(2020, 1, 11)
    real_data1 = pd.read_csv(get_data_path())
    history_real = prepareData(real_data1)
    if not load_inter_flag:
        print('re-simulate the progress')
        province_travel_dict = flowHubei()
        for i in range(get_seed_num()):
            total_params = pd.read_csv(
                os.path.join(os.path.dirname(__file__),
                             './params{}.csv'.format(int(i))))
            unob_flow_num = initHubei(
                get_params(total_params, 420000),
                start_date,
                important_date=[get_important_date(420000)],
                travel_from_hubei=province_travel_dict)
            for ind, city in enumerate(real_data):
                print(i, ind, city)
                x = get_params(total_params, city)
                run_simulation2(x,
                                city,
                                90,
                                90,
                                start_date,
                                get_important_date(city),
                                history_real,
                                unob_flow_num=unob_flow_num,
                                json_name='data_run{}.json'.format(int(i)))
    else:
        print('directly load the pre-simulated data')
    for i in range(get_seed_num()):
        get_total_province('data_run{}.json'.format(int(i)))

    # choose the final parameters
    max_data, min_data, mean_data, best_data, std_data, middle_data, \
    xmin_data, xmax_data, xmean_data, xstd_data = load_and_save(
        './data_run{}.json', './data_run_{}.json')
    """
コード例 #4
0
ファイル: run.py プロジェクト: lordChipotle/ML-SIM-Improved
        lst_date = lst_date + timedelta(1)
    return unob_flow_num


if __name__ == '__main__':
    province_travel_dict = flowHubei()
    real_data = pd.read_csv(get_data_path())['adcode'].unique()
    province_code_dict = codeDict()
    training_end_date = None
    x_buffer = []

    rerun_list = None
    if rerun_list is not None:
        old_param_buffer = [
            pd.read_csv('params{}.csv'.format(int(i)))
            for i in range(get_seed_num())
        ]
    for i in range(get_seed_num()):
        global_seed(i)
        all_param = {}
        if rerun_list is None or 420000 in rerun_list:
            x = run_opt(420000,
                        200000,
                        start_date=date(2020, 1, 11),
                        important_dates=[get_important_date(420000)],
                        repeat_time=1,
                        training_date_end=training_end_date,
                        seed=i,
                        json_name='data_run{}.json'.format(int(i)))
            clear_child_process()
            all_param[420000] = x
コード例 #5
0
        f.write(json.dumps(middle_data))
    with open(output_format.format('xmin'), 'w') as f:
        f.write(json.dumps(xmin_data))
    with open(output_format.format('xmax'), 'w') as f:
        f.write(json.dumps(xmax_data))
    with open(output_format.format('xmean'), 'w') as f:
        f.write(json.dumps(xmean_data))
    with open(output_format.format('xstd'), 'w') as f:
        f.write(json.dumps(xstd_data))
    return max_data, min_data, mean_data, best_data, std_data, middle_data, xmin_data, xmax_data, xmean_data, xstd_data


if __name__ == '__main__':
    data_buffer = [
        json.load(open('./data_run_foreign{}.json'.format(int(i)), 'r'))
        for i in range(get_seed_num())
    ]
    cities = [900003, 900004, 900005, 900006, 900007, 900008, 900009, 900010]
    #data_buffer = [json.load(open('./data_run{}.json'.format(int(i)), 'r')) for i in range(get_seed_num())]
    #cities = [420000]
    max_data, min_data, mean_data, best_data, std_data, middle_data, xmin_data, xmax_data, xmean_data, xstd_data = res_analysis(
        data_buffer)
    pbnum = 3
    for iitem in cities:
        city = str(iitem)
        print(it_code_dict()[int(city)])
        x = [data_buffer[i]['x'][city] for i in range(get_seed_num())]
        final_cum = [
            data_buffer[i]['sim_cum_confirmed_deduction_s1'][city][-1]
            for i in range(get_seed_num())
        ]
コード例 #6
0
                         repeat=repeat_time, seed=seed, intermediate_freq=10000, init_samples=init_samples,
                         loss_ord=loss_ord)
    print('best_solution: x = ', x, 'y = ', y)
    simulator.set_param(x)
    run_simulation(x, city, 60, 60, start_date, get_important_date(city), unob_flow_num=unob_flow_num, json_name=json_name)
    return x


if __name__ == '__main__':
    real_data = list(pd.read_csv(get_data_path(True))['adcode'].unique())
    province_code_dict = it_code_dict()
    rerun_list = None
    old_param_buffer = None
    training_end_date = None
    if rerun_list is not None:
        old_param_buffer = [pd.read_csv('params_foreign{}.csv'.format(int(i))) for i in range(get_seed_num())]
    for i in range(get_seed_num()):
        all_param = {}
        for ind, item in enumerate(real_data):
            print(i, ind, item, province_code_dict[item])
            if rerun_list is None or item in rerun_list:
                touch_range = [0, 0.33333]
                iso_range = None
                x = run_opt(item, 80000, start_date=date(2020, 2, 4), important_dates=[get_important_date(item)],
                            infectratio_range=[0.0, 0.05], dummy_range=[0, 400], unob_flow_num=None, repeat_time=1,
                            seed=i, json_name='data_run_foreign{}.json'.format(int(i)), loss_ord=1.5, touch_range=touch_range,
                            iso_range=iso_range, training_end_date=training_end_date)
                all_param[item] = x
                clear_child_process()
            else:
                all_param[item] = list(old_param_buffer[i][str(item)])