Beispiel #1
0
    # FOR TESTING ONLY:
    if mode == 'fast':
        cb.set_param('x_Temporary_Larval_Habitat', 0)
        cb.set_param('x_Regional_Migration', 0)

    return sample


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__":
Beispiel #2
0
                      "Vector_Species_Names": [species]
                      })

# Just for fun, let the numerical derivative baseline scale with the number of dimensions
volume_fraction = 0.01   # desired fraction of N-sphere area to unit cube area for numerical derivative (automatic radius scaling with N)
num_params = len([p for p in params if p['Dynamic']])

#Change radius
r = math.exp(1/float(num_params)*(math.log(volume_fraction) + gammaln(num_params/2.+1) - num_params/2.*math.log(math.pi)))
#r = 0.5
#r *= 0.5


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)
Beispiel #3
0
num_params = len([p for p in params if p['Dynamic']])
r = math.exp(1 / float(num_params) *
             (math.log(volume_fraction) + gammaln(num_params / 2. + 1) -
              num_params / 2. * math.log(math.pi)))

# Check, here's the formula for the volume of a N-sphere
computed_volume_fraction = math.exp(num_params / 2. * math.log(math.pi) -
                                    gammaln(num_params / 2. + 1) +
                                    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)
Beispiel #4
0
def create_DTK():
    ''' Create an OptimTool instance '''

    # Overwrite default repr with something more informative
    def new_repr(self):
        return sc.prepr(self)

    def gather_results(self, randseed=None, results=None):
        if randseed is not None:
            pl.seed(randseed)
        if results is None:
            results = pl.rand(len(self.data['Results']))
        self.data['Results'][-len(results):] = results
        return results

    OptimTool.__repr__ = new_repr
    OptimTool.gather_results = gather_results

    params = [
        {
            'Name': 'Clinical Fever',
            'Dynamic': True,
            #'MapTo': 'Clinical_Fever_Threshold_High', # <-- DEMO: Custom mapping, see map_sample_to_model_input below
            'Guess': 1.75,
            'Min': 0.5,
            'Max': 2.5
        },
        {
            'Name': 'MSP1 Merozoite',
            'Dynamic': False,  # <-- NOTE: this parameter is frozen at Guess
            'MapTo': 'MSP1_Merozoite_Kill_Fraction',
            'Guess': 0.65,
            'Min': 0.4,
            'Max': 0.7
        },
        {
            'Name': 'Falciparum',
            'Dynamic': True,
            'MapTo': 'Falciparum_PfEMP1_Variants',
            'Guess': 1500,
            'Min': 1,  # 900 [0]
            'Max': 5000  # 1700 [1e5]
        },
        {
            'Name': 'Min Days',
            'Dynamic': False,  # <-- NOTE: this parameter is frozen at Guess
            'MapTo': 'Min_Days_Between_Clinical_Incidents',
            'Guess': 25,
            'Min': 1,
            'Max': 50
        },
    ]

    num_params = len([p for p in params if p['Dynamic']])

    volume_fraction = 0.01  # desired fraction of N-sphere area to unit cube area for numerical derivative (automatic radius scaling with N)
    r = OptimTool.get_r(num_params, volume_fraction)
    OT = 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=
        0,  # <-- Number of times to replicate the center (current guess).  Nice to compare intrinsic to extrinsic noise
        samples_per_iteration=
        10  # 32 # <-- Samples per iteration, includes center repeats.  Actual number of sims run is this number times number of sites.
    )

    return OT
        # Replace the (species S 100) with the correct number coming from our sample
        if p["Name"] == "initial_S_A04":
            cb.set_species("S-A04", int(value))

        # Replaces the (species I 100) with the correct number coming from our sample
        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__":
Beispiel #6
0
})


def map_sample_to_model_input(cb, sample):
    hab = {
        '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}
                    funest_rescale *
                    sample['b{}_vector_mult'.format(int(bairro_num))],
                    start_day=0)

    # FOR TESTING ONLY:
    if mode == 'fast':
        cb.set_param('x_Temporary_Larval_Habitat', 0)
        cb.set_param('x_Regional_Migration', 0)

    return sample


if calib_stage != 0:
    optimtool = OptimTool(
        params,
        samples_per_iteration=samples_per_iteration,
        center_repeats=1,
        sigma_r=0.05
    )  #increase radius of hypersphere (default is sigma_r=0.02)

    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}