def single_testing(pt_net, local_net, sample_pax, save_file_name, time_interval, sample_size, seed):
    start_time_int = 0
    sim_period = round(1*len(pt_net) - start_time_int)
    mu_r = _constants.mu_r
    mu_d = _constants.mu_d
    beta_I = _constants.beta_I
    beta_E = _constants.beta_E
    theta_l = _constants.theta_l
    theta_g = _constants.theta_g
    gamma = _constants.gamma

    para_dict = {'mu_r': mu_r, 'mu_d':mu_d, 'beta_I': beta_I,'beta_E': beta_E,
                 'theta_l':theta_l,'theta_g':theta_g,'gamma':gamma,'initial_I':_constants.initial_I}
    simulation_seed = 0
    sim = sim_eng.simulation(pt_net, sim_period, local_net, para_dict, sample_size,
                             time_interval, sample_pax, start_time_int, save_file_name,
                             verbal = False, random_seed = simulation_seed)
    tic = time.time()
    sim.run()
    running_time = round(time.time() - tic,1)
    df_test_info = {'test_name': [save_file_name], 'sample_size':[sample_size],'time_interval':[time_interval],
                    'sample_seed':[seed],'sim_seed':[simulation_seed],'start_time_int':[start_time_int],
                    'total_sim_period':[sim_period]}
    for para in para_dict:
        df_test_info[para] = [para_dict[para]]
    df_test_info['running_time'] = [running_time]
    df_test_info = pd.DataFrame(df_test_info)
    df_test_info.to_csv('output/simulation_para_' +  save_file_name + '.csv',index=False)
Пример #2
0
def system_test(para_hyperspace, num_of_test, sample_case_seed, iterate_all,
                time_interval, sample_size, seed):
    # get all combination
    inputdata = []
    for key in para_hyperspace:
        inputdata.append(para_hyperspace[key])
    result = list(itertools.product(*inputdata))
    if iterate_all:
        test_samples = result
    else:
        random.seed(sample_case_seed)
        test_samples = random.sample(result, num_of_test)
    print('Total sim cases', len(test_samples))
    count = 0
    for test_case in test_samples:
        count += 1
        save_file_name = 'system_test_' + str(count)
        print('==============')
        print('Current test number', count)
        start_time_int = 0
        sim_period = round(1 * len(pt_net) - start_time_int)
        mu_r = test_case[0]
        mu_d = test_case[1]
        beta_I = test_case[2]
        beta_E = 0.01 * test_case[2]
        theta_l = test_case[3]
        theta_g = test_case[4]
        gamma = test_case[5]
        initial_I = test_case[6]

        para_dict = {
            'mu_r': mu_r,
            'mu_d': mu_d,
            'beta_I': beta_I,
            'beta_E': beta_E,
            'theta_l': theta_l,
            'theta_g': theta_g,
            'gamma': gamma,
            'initial_I': initial_I
        }

        print(para_dict)

        simulation_seed = 0
        sim = sim_eng.simulation(pt_net,
                                 sim_period,
                                 local_net,
                                 para_dict,
                                 sample_size,
                                 time_interval,
                                 sample_pax,
                                 start_time_int,
                                 save_file_name,
                                 verbal=False,
                                 random_seed=simulation_seed)
        tic = time.time()
        sim.run()
        running_time = round(time.time() - tic, 1)
        df_test_info = {
            'test_name': [save_file_name],
            'sample_size': [sample_size],
            'time_interval': [time_interval],
            'sample_seed': [seed],
            'sim_seed': [simulation_seed],
            'start_time_int': [start_time_int],
            'total_sim_period': [sim_period]
        }
        for para in para_dict:
            df_test_info[para] = [para_dict[para]]
        df_test_info['running_time'] = [running_time]
        df_test_info = pd.DataFrame(df_test_info)
        df_test_info.to_csv('output/simulation_para_' + save_file_name +
                            '.csv',
                            index=False)