コード例 #1
0
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)
コード例 #2
0
    def test_vensim_model(self):

        #instantiate a model
        wd = r'../models'
        model = VensimExampleModel(wd, "simpleModel")

        #instantiate an ensemble
        ensemble = ModelEnsemble()

        #set the model on the ensemble
        ensemble.model_structure = model

        nr_runs = 10
        experiments, outcomes = ensemble.perform_experiments(nr_runs)

        self.assertEqual(experiments.shape[0], nr_runs)
        self.assertIn('TIME', outcomes.keys())
        self.assertIn(model.outcomes[0].name, outcomes.keys())
コード例 #3
0
    def test_running_lookup_uncertainties(self):
        '''
        This is the more comprehensive test, given that the lookup
        uncertainty replaces itself with a bunch of other uncertainties, check
        whether we can successfully run a set of experiments and get results
        back. We assert that the uncertainties are correctly replaced by
        analyzing the experiments array. 
        
        '''
        if os.name != 'nt':
            return

        model = LookupTestModel(r'../models/', 'lookupTestModel')

        #model.step = 4 #reduce data to be stored
        ensemble = ModelEnsemble()
        ensemble.model_structure = model

        ensemble.perform_experiments(10)
コード例 #4
0
'''
Created on Mar 15, 2012

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
'''

from analysis import clusterer
from util import ema_logging

from core import ModelEnsemble
from test.scarcity_example import ScarcityModel

if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = ScarcityModel(r'..\..\src\test', "fluCase")

    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model)
    ensemble.parallel = True

    results = ensemble.perform_experiments(200)

    clusterer.cluster(data=results,
                      outcome='relative market price',
                      distance='gonenc',
                      cMethod='maxclust',
                      cValue=5,
                      plotDendrogram=False)
コード例 #5
0
    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__':
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = SimplePythonModel(None, 'simpleModel')  #instantiate the model
    ensemble = ModelEnsemble()  #instantiate an ensemble
    ensemble.parallel = True
    ensemble.model_structure = model  #set the model on the ensemble
    results = ensemble.perform_experiments(1000)  #run 1000 experiments