Beispiel #1
0
optimtool = OptimTool(params,
    mu_r = r,           # <-- radius for numerical derivatve.  CAREFUL not to go too small with integer parameters
    sigma_r = r/10.,    # <-- stdev of radius
    center_repeats=1, # <-- Number of times to replicate the center (current guess).  Nice to compare intrinsic to extrinsic noise
    samples_per_iteration=1000 # was 32  # <-- Samples per iteration, includes center repeats.  Actual number of sims run is this number times number of sites.
)


# cb.add_reports(BaseVectorStatsReport(type='ReportVectorStats', stratify_by_species=1))
add_filtered_report(cb, start=365*throwaway)

calib_manager = CalibManager(name=expname,    # <-- Please customize this name
                             config_builder=cb,
                             map_sample_to_model_input_fn=map_sample_to_model_input,
                             sites=sites,
                             next_point=optimtool,
                             sim_runs_per_param_set=1,  # <-- Replicates
                             max_iterations=max_iterations,   # <-- Iterations
                             plotters=plotters)


run_calib_args = {
    "calib_manager":calib_manager
}

if __name__ == "__main__":
    SetupParser.init()
    cm = run_calib_args["calib_manager"]
    cm.run_calibration()
Beispiel #2
0
                                    num_params * math.log(r))

optimtool = OptimTool(
    params,
    constrain_sample,  # <-- Will not be saved in iteration state
    #mu_r = r,      # <-- Mean percent of parameter range for numerical derivatve.  CAREFUL with integer parameters!
    mu_r=0.3,
    sigma_r=r / 10.,  # <-- stdev of above
    samples_per_iteration=500,  # 700 is real size, 10 is testing
    center_repeats=10,  # 10 is real size, 2 is testing
    rsquared_thresh=
    0.5  # <-- Linear regression goodness of fit threshold.  Above this, regression is used.  Below, use best point.
)

calib_manager = CalibManager(
    name='Rakai_calibration_run4',
    config_builder=config_builder,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=sites,
    next_point=optimtool,
    sim_runs_per_param_set=3,  # <-- Replicates, none needed for example
    max_iterations=100,  # limited for example
    plotters=plotters)

# REQUIRED variable name: run_calib_args .
run_calib_args = {'calib_manager': calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    calib_manager.run_calibration()
Beispiel #3
0
if calib_stage == 1:
    sigma_r = 0.2
elif calib_stage >= 2:
    sigma_r = 0.05

if calib_stage != 0:
    optimtool = OptimTool(params,
                          samples_per_iteration=samples_per_iteration,
                          center_repeats=1,
                          sigma_r=sigma_r)

    calib_manager = CalibManager(
        name=COMPS_calib_exp_name,
        config_builder=mozamb_exp.cb,
        map_sample_to_model_input_fn=map_sample_to_model_input,
        sites=sites,
        next_point=optimtool,
        sim_runs_per_param_set=sim_runs_per_param_set,
        max_iterations=max_iterations,
        plotters=plotters)

    run_calib_args = {"calib_manager": calib_manager}

if __name__ == "__main__":
    if parser_location == "LOCAL":
        SetupParser.init("LOCAL")

    else:
        SetupParser.init()

        SetupParser.set("HPC", "priority", priority)
Beispiel #4
0
name = "Example_Optimization_PBnB" # <-- Please customize this name

optimtool_PBnB = OptimTool_PBnB(params,
                                s_running_file_name=name,
                                s_problem_type="deterministic",  # deterministic or noise
                                f_delta=par.f_delta,  # <-- to determine the quantile for the target level set
                                f_alpha=par.f_alpha,  # <-- to determine the quality of the level set approximation
                                i_k_b=par.i_k_b,  # <-- maximum number of inner iterations
                                i_n_branching=par.i_n_branching,  # <-- number of branching subregions
                                i_c=par.i_c,  # <--  increasing number of sampling points ofr all
                                i_replication=par.i_replication,  # <-- initial number of replication
                                i_stopping_max_k=par.i_stopping_max_k,  # <-- maximum number of outer iterations
                                i_max_num_simulation_per_run=par.i_max_num_simulation_per_run,
                                # <-- maximum number of simulations per iteration
                                f_elite_worst_sampling_para=par.f_elite_worst_sampling_para)  # <-- parameters that determine the number of simulation runs for elite and worst subregions

calib_manager = CalibManager(name=name,
                             config_builder=cb,
                             map_sample_to_model_input_fn=map_sample_to_model_input,
                             sites=sites,
                             next_point=optimtool_PBnB,
                             sim_runs_per_param_set=1,  # <-- Replicates
                             max_iterations=30,  # <-- Iterations
                             plotters=plotters)

run_calib_args = {'calib_manager': calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    calib_manager.run_calibration()
        cb.set_param('Serialized_Population_Filenames',sample_dimension_values['Serialized_Population_Filenames'])

    tags = {'Prevalence_date':sample_dimension_values['Prevalence_date'],
            'Prevalence_threshold': sample_dimension_values['Prevalence_threshold'],
            'Serialization': sample_dimension_values['New_Duration'] if sample_dimension_values['NodeIDs'] else
            sample_dimension_values['Serialization']}

    tags.update(cb.set_param('Run_Number', sample_dimension_values['Run_Number']))

    return tags

# sp.override_block('LOCAL')
calib_manager = CalibManager(name=sim_name,
                             config_builder=cb,
                             map_sample_to_model_input_fn=sample_point_fn,
                             sites=sites,
                             next_point=GenericIterativeNextPoint(initial_state),
                             sim_runs_per_param_set=1,
                             max_iterations=1,
                             plotters=[])

run_calib_args = {}

if __name__ == "__main__":
    # The following line would resume from iteration 0 at the step analyze
    # The available steps are: commission, analyze, next_point
    # calib_manager.resume_from_iteration(iteration=0, iter_step='analyze')
    # For now cleanup automatically
    calib_manager.cleanup()
    calib_manager.run_calibration()
# The default plotters used in an Optimization with OptimTool
plotters = [LikelihoodPlotter(combine_sites=True),
            SiteDataPlotter(num_to_plot=5, combine_sites=True),
            OptimToolPlotter()  # OTP must be last because it calls gc.collect()
            ]
# Use OptimTool as next-point-algorithm
# optimtool = burnin_optimtool(params,
optimtool = OptimTool(params,
                      samples_per_iteration=samples_per_iteration,
                      center_repeats=1,
                      sigma_r=sigma_r)

calib_manager = CalibManager(name=experiment_name,
                             config_builder=cb,
                             map_sample_to_model_input_fn=map_sample_to_model_input,
                             sites=sites,
                             next_point=optimtool,
                             max_iterations=max_iterations,
                             plotters=plotters)

run_calib_args = {
    "calib_manager": calib_manager
}


if __name__ == "__main__":
    SetupParser.init()
    SetupParser.set("HPC", "priority", priority)
    SetupParser.set("HPC", "node_group", coreset)

    cm = run_calib_args["calib_manager"]
Beispiel #7
0
    params,
    constrain_sample,  # <-- WILL NOT BE SAVED IN ITERATION STATE
    mu_r=
    r,  # <-- radius for numerical derivatve.  CAREFUL not to go too small with integer parameters
    sigma_r=r / 10.,  # <-- stdev of radius
    center_repeats=
    2,  # <-- Number of times to replicate the center (current guess).  Nice to compare intrinsic to extrinsic noise
    samples_per_iteration=
    4  # 32 # <-- Samples per iteration, includes center repeats.  Actual number of sims run is this number times number of sites.
)

calib_manager = CalibManager(
    name='ExampleOptimization_cramer',  # <-- Please customize this name
    config_builder=cb,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=sites,
    next_point=optimtool,
    sim_runs_per_param_set=3,  # <-- Replicates
    max_iterations=3,  # <-- Iterations
    plotters=plotters)

# *******************************************************************
# Resampling specific code
# *******************************************************************

# Define the resamplers to run (one or more) in list order.
resample_steps = [
    # can pass kwargs directly to the underlying resampling routines if needed
    RandomPerturbationResampler(N=8),
    CramerRaoResampler(num_of_pts=10)
]
        elif p["Name"] == "initial_I_A04":
            cb.set_species("I-A04", int(value))

        # Add this change to our tags
        tags[p["Name"]] = value

    return tags


optimtool = OptimTool(params,
                      constrain_sample,
                      samples_per_iteration=25,
                      center_repeats=1)

calib_manager = CalibManager(
    name='ExampleOptimizationCMS',
    config_builder=cb,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=sites,
    next_point=optimtool,
    sim_runs_per_param_set=1,
    max_iterations=3,
    plotters=plotters)

run_calib_args = {"calib_manager": calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    cm = run_calib_args["calib_manager"]
    cm.run_calibration()
Beispiel #9
0
optimtool = OptimTool(
    params,
    lambda p: p,
    mu_r=
    r,  # <-- radius for numerical derivatve.  CAREFUL not to go too small with integer parameters
    sigma_r=r / 10.,  # <-- stdev of radius
    center_repeats=
    1,  # <-- Number of times to replicate the center (current guess).  Nice to compare intrinsic to extrinsic noise
    samples_per_iteration=
    100  # <-- Samples per iteration, includes center repeats.  Actual number of sims run is this number times number of sites.
)

calib_name = "CHIKV_Calib_Habitat_Decay_Imports_SingleNode_%s" % site_name
calib_manager = CalibManager(name=calib_name,
                             config_builder=cb,
                             map_sample_to_model_input_fn=sample_point_fn,
                             sites=sites,
                             next_point=optimtool,
                             sim_runs_per_param_set=4,
                             max_iterations=10,
                             plotters=plotters)

#run_calib_args = {'selected_block': "LOCAL"}
run_calib_args = {}

if __name__ == "__main__":
    SetupParser.init(selected_block=SetupParser.default_block)
    #run_calib_args.update(dict(location='HPC'))
    #calib_manager.cleanup()
    calib_manager.run_calibration()  #(**run_calib_args)
    for sample_dimension_name, sample_dimension_value in sample_point.items():
        # Apply specific logic to convert sample-point dimensions into simulation configuration parameters
        if '_LOG' in sample_dimension_name:
            param_name = sample_dimension_name.replace('_LOG', '')
            params_to_update[param_name] = pow(10, sample_dimension_value)
        else:
            params_to_update[sample_dimension_name] = sample_dimension_value

    return cb.update_params(params_to_update)


next_point_kwargs = dict(initial_samples=4,
                         samples_per_iteration=2,
                         n_resamples=100)

calib_manager = CalibManager(name='FullCalibrationExample',
                             config_builder=cb,
                             map_sample_to_model_input_fn=sample_point_fn,
                             sites=sites,
                             next_point=IMIS(prior, **next_point_kwargs),
                             sim_runs_per_param_set=1,
                             max_iterations=2,
                             plotters=plotters)

run_calib_args = {'calib_manager': calib_manager}

if __name__ == "__main__":
    SetupParser.init(selected_block=SetupParser.default_block)
    calib_manager.run_calibration()
Beispiel #11
0
optimtool = OptimTool(
    params,
    constrain_sample,  # <-- Will not be saved in iteration state
    #mu_r = r,      # <-- Mean percent of parameter range for numerical derivatve.  CAREFUL with integer parameters!
    mu_r=0.3,
    sigma_r=r / 10.,  # <-- stdev of above
    samples_per_iteration=10,  # 700 is real size, 10 is testing
    center_repeats=2,  # 10 is real size, 2 is testing
    rsquared_thresh=
    0.20  # <-- Linear regression goodness of fit threshold.  Above this, regression is used.  Below, use best point.
)

calib_manager = CalibManager(
    name=
    'ExampleCalibrationIngest',  # ZimbabweOptimization_Testing ZimbabweOptimization_IncreasedSampling ZimbabweOptimization
    config_builder=config_builder,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=sites,
    next_point=optimtool,
    sim_runs_per_param_set=1,  # <-- Replicates, none needed for example
    max_iterations=3,  # limited for example
    plotters=plotters)

# REQUIRED variable name: run_calib_args .
run_calib_args = {'calib_manager': calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    calib_manager.run_calibration()
Beispiel #12
0
        'gambiae': {
            'TEMPORARY_RAINFALL': 1.5e8 * sample["Temporary_Habitat"],
            'CONSTANT': 5.5e6 * sample["Constant_Habitat"]
        }
    }
    set_larval_habitat(cb, hab)

    return sample


optimtool = OptimTool(params, center_repeats=1, samples_per_iteration=25)
calib_manager = CalibManager(
    name=exp_name,
    config_builder=cb,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=[PointPrevalenceSite(site)],
    next_point=optimtool,
    sim_runs_per_param_set=1,
    max_iterations=3,
    plotters=[OptimToolPlotter()])

add_summary_report(
    cb,
    description='AnnualAverage')  ## add summary report of annual prevalence
run_calib_args = {"calib_manager": calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    cm = run_calib_args["calib_manager"]
    cm.run_calibration()
optimtool = OptimTool(
    params,
    mu_r=
    r,  # <-- radius for numerical derivatve.  CAREFUL not to go too small with integer parameters
    sigma_r=r / 10.,  # <-- stdev of radius
    center_repeats=
    1,  # <-- Number of times to replicate the center (current guess).  Nice to compare intrinsic to extrinsic noise
    samples_per_iteration=
    32  # 32 # <-- Samples per iteration, includes center repeats.  Actual number of sims run is this number times number of sites.
)

# cb.add_reports(BaseVectorStatsReport(type='ReportVectorStats', stratify_by_species=1))

calib_manager = CalibManager(
    name='MozambiqueEntoCalibTest1_%s' %
    specs[0],  # <-- Please customize this name
    config_builder=cb,
    map_sample_to_model_input_fn=map_sample_to_model_input,
    sites=sites,
    next_point=optimtool,
    sim_runs_per_param_set=1,  # <-- Replicates
    max_iterations=8,  # <-- Iterations
    plotters=plotters)

run_calib_args = {"calib_manager": calib_manager}

if __name__ == "__main__":
    SetupParser.init()
    cm = run_calib_args["calib_manager"]
    cm.run_calibration()
    can be encoded in a similar fashion using custom functions rather than the generic "set_param".
    '''
    sample_point = prior.to_dict(sample_dimension_values)
    params_to_update = dict()
    params_to_update['Simulation_Duration'] = 365
    for sample_dimension_name, sample_dimension_value in sample_point.items():
        param_name = sample_dimension_name.replace('_LOG', '')
        params_to_update[param_name] = pow(10, sample_dimension_value)

    return cb.update_params(params_to_update)


next_point_kwargs = dict(initial_samples=3,
                         samples_per_iteration=3,
                         n_resamples=100)

calib_manager = CalibManager(name='test_dummy_calibration',
                             setup=SetupParser(),
                             config_builder=cb,
                             map_sample_to_model_input_fn=sample_point_fn,
                             sites=sites,
                             next_point=IMIS(prior, **next_point_kwargs),
                             sim_runs_per_param_set=1,
                             max_iterations=2,
                             plotters=plotters)

run_calib_args = {}

if __name__ == "__main__":
    calib_manager.run_calibration(**run_calib_args)