def perform_experiments(): logger = EMAlogging.log_to_stderr(level=EMAlogging.INFO) model = SalinizationModel(r"C:\eclipse\workspace\EMA-workbench\models\salinization", "verzilting") model.step = 4 ensemble = SimpleModelEnsemble() ensemble.set_model_structure(model) policies=[{'name': 'no policy', 'file': r'\verzilting 2.vpm'}, {'name': 'policy group 8', 'file': r'\group 8 best policy.vpm'}, {'name': 'policy other group', 'file': r'\other group best policy.vpm'}, {'name': 'policies combined', 'file': r'\best policies combined.vpm'} ] ensemble.add_policies(policies) ensemble.parallel = True nr_of_experiments = 1000 results = ensemble.perform_experiments(nr_of_experiments) return results
def model_init(self, policy, kwargs): """initializes the model""" try: self.modelFile = policy["file"] except KeyError: logging.warning("key 'file' not found in policy") super(FluModel, self).model_init(policy, kwargs) if __name__ == "__main__": logging.log_to_stderr(logging.INFO) model = FluModel(r"..\..\models\flu", "fluCase") ensemble = SimpleModelEnsemble() ensemble.set_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.add_policies(policies) ensemble.parallel = True # turn on parallel processing results = ensemble.perform_experiments(1000) save_results(results, r"../../src/analysis/1000 flu cases no policy.cPickle")
from expWorkbench import SimpleModelEnsemble, ModelStructureInterface,\ ParameterUncertainty, Outcome class SimplePythonModel(ModelStructureInterface): ''' This class represents a simple example of how one can extent the basic ModelStructureInterface in order to do EMA on a simple model coded in Python directly ''' #specify uncertainties uncertainties = [ParameterUncertainty((0.1, 10), "x1"), ParameterUncertainty((-0.01,0.01), "x2"), ParameterUncertainty((-0.01,0.01), "x3")] #specify outcomes outcomes = [Outcome('y')] def model_init(self, policy, kwargs): pass def run_model(self, case): """Method for running an instantiated model structure """ self.output[self.outcomes[0].name] = case['x1']*case['x2']+case['x3'] if __name__ == '__main__': model = SimplePythonModel(None, 'simpleModel') #instantiate the model ensemble = SimpleModelEnsemble() #instantiate an ensemble ensemble.set_model_structure(model) #set the model on the ensemble results = ensemble.perform_experiments(1000) #generate 1000 cases
''' #note that this reference to the model should be relative #this relative path will be combined with the workingDirectory modelFile = r'\model.vpm' #specify outcomes outcomes = [Outcome('a', time=True)] #specify your uncertainties uncertainties = [ParameterUncertainty((0, 2.5), "x11"), ParameterUncertainty((-2.5, 2.5), "x12")] if __name__ == "__main__": #turn on logging EMAlogging.log_to_stderr(EMAlogging.INFO) #instantiate a model vensimModel = VensimExampleModel(r"..\..\models\vensim example", "simpleModel") #instantiate an ensemble ensemble = SimpleModelEnsemble() #set the model on the ensemble ensemble.set_model_structure(vensimModel) #run in parallel, if not set, FALSE is assumed ensemble.parallel = True #perform experiments result = ensemble.perform_experiments(1000)
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__": logger = EMAlogging.log_to_stderr(level=EMAlogging.INFO) model = ExcelModel(r"..\..\models\excelModel", "predatorPrey") ensemble = SimpleModelEnsemble() ensemble.set_model_structure(model) ensemble.parallel = True # turn on parallel computing ensemble.processes = 2 # using only 2 cores # generate 100 cases results = ensemble.perform_experiments(10) lines(results) plt.show() # save results # save_results(results, r'..\..\excel runs.cPickle')