def test_parallel_experiment(self): """ Test running an experiment in parallel Returns ------- """ from ema_workbench.connectors import PySDConnector model = PySDConnector('../models/Teacup.mdl', uncertainties_dict={'Room Temperature': (33, 120)}, outcomes_list=['Teacup Temperature']) ensemble = ModelEnsemble() # instantiate an ensemble ensemble.model_structure = model # set the model on the ensemble ensemble.parallel = True results = ensemble.perform_experiments(cases=20)
def test_add_outcomes(self): from ema_workbench.connectors import PySDConnector model = PySDConnector('../models/Teacup.mdl', uncertainties_dict={'Room Temperature': (33, 120)}, outcomes_list=['Teacup Temperature']) ensemble = ModelEnsemble() # instantiate an ensemble ensemble.model_structure = model # set the model on the ensemble ensemble.parallel = False nr_runs = 10 experiments, outcomes = ensemble.perform_experiments(nr_runs) self.assertEqual(experiments.shape[0], nr_runs) self.assertIn('TIME', outcomes.keys()) self.assertIn('Teacup Temperature', outcomes.keys())
def test_parallel_experiment(self): """ Test running an experiment in parallel Returns ------- """ relative_path_to_file = '../models/Teacup.mdl' directory = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) mdl_file = os.path.join(directory, relative_path_to_file) model = PysdModel(mdl_file=mdl_file) model.uncertainties = [RealParameter('Room Temperature', 33, 120)] model.outcomes = [TimeSeriesOutcome('Teacup Temperature')] ensemble = ModelEnsemble() # instantiate an ensemble ensemble.model_structures = model # set the model on the ensemble ensemble.parallel = True ensemble.perform_experiments(5)
def test_optimization(): if os.name != 'nt': return ema_logging.log_to_stderr(ema_logging.INFO) model = FluModel(r'../models', "fluCase") ensemble = ModelEnsemble() ensemble.model_structure = model ensemble.parallel=True pop_size = 8 nr_of_generations = 10 eps = np.array([1e-3, 1e6]) stats, pop = ensemble.perform_outcome_optimization(obj_function = obj_function_multi, algorithm=epsNSGA2, reporting_interval=100, weights=(MAXIMIZE, MAXIMIZE), pop_size=pop_size, nr_of_generations=nr_of_generations, crossover_rate=0.8, mutation_rate=0.05, eps=eps)
"susceptible to immune population delay time region 1"), ParameterUncertainty((0.5,2), "susceptible to immune population delay time region 2"), ParameterUncertainty((0.01, 5), "root contact rate region 1"), ParameterUncertainty((0.01, 5), "root contact ratio region 2"), ParameterUncertainty((0, 0.15), "infection ratio region 1"), ParameterUncertainty((0, 0.15), "infection rate region 2"), ParameterUncertainty((10, 100), "normal contact rate region 1"), ParameterUncertainty((10, 200), "normal contact rate region 2")] if __name__ == "__main__": ema_logging.log_to_stderr(ema_logging.INFO) model = FluModel(r'./models/flu', "fluCase") ensemble = ModelEnsemble() ensemble.model_structure = model ensemble.parallel = True #turn on parallel processing nr_experiments = 1000 results = ensemble.perform_experiments(nr_experiments) fh = r'./data/{} flu cases no policy.tar.gz'.format(nr_experiments) save_results(results, fh)
except KeyError: ema_logging.warning("key 'file' not found in policy") super(FluModel, self).model_init(policy, kwargs) if __name__ == "__main__": ema_logging.log_to_stderr(ema_logging.INFO) model = FluModel(r'./models/flu', "flucase") ensemble = ModelEnsemble() ensemble.model_structure = model #add policies policies = [{'name': 'no policy', 'file': r'\FLUvensimV1basecase.vpm'}, {'name': 'static policy', 'file': r'\FLUvensimV1static.vpm'}, {'name': 'adaptive policy', 'file': r'\FLUvensimV1dynamic.vpm'} ] ensemble.policies = policies #turn on parallel processing ensemble.parallel = True # run 1000 experiments nr_runs = 1000 results = ensemble.perform_experiments(nr_runs) # save the results # save_results(results, r'./data/{} flu cases.tar.gz'.format(nr_runs))
"aaa"), ParameterUncertainty((0.45,0.55), "tH"), ParameterUncertainty((0.1,0.3), "kk")] #specification of the outcomes outcomes = [Outcome("B4:B1076", time=True), #we can refer to a range in the normal way Outcome("P_t", time=True)] # we can also use named range #name of the sheet sheet = "Sheet1" #relative path to the Excel file workbook = r'\excel example.xlsx' if __name__ == "__main__": ema_logging.log_to_stderr(level=ema_logging.INFO) model = ExcelModel(r"./models/excelModel", "predatorPrey") ensemble = ModelEnsemble() ensemble.model_structure = model ensemble.parallel = True #turn on parallel computing #run 100 experiments nr_experiments = 100 results = ensemble.perform_experiments(nr_experiments)
else: atomicBehavior.append([last, steps]) last = entry steps = 0 atomicBehavior.append([last, steps]) behavior = [] behavior.append(atomicBehavior.pop(0)) for entry in atomicBehavior: if entry[0] != behavior[-1][0] and entry[1] > 2: behavior.append(entry) elif entry[1] < 2: continue else: behavior[-1][1] = +entry[1] behavior = [entry[0] for entry in behavior] return behavior if __name__ == "__main__": ema_logging.log_to_stderr(ema_logging.INFO) model = ScarcityModel(r'..\data', "scarcity") ensemble = ModelEnsemble() ensemble.set_model_structure(model) ensemble.parallel = True results = ensemble.perform_experiments(100) # determineBehavior(results)