Пример #1
0
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
Пример #2
0
    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")
Пример #3
0
                         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