コード例 #1
0
This file illustrated the use the EMA classes for a contrived vensim
example


.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
                chamarat <c.hamarat (at) tudelft (dot) nl>
'''
from __future__ import (division, unicode_literals, absolute_import, 
                        print_function)

from ema_workbench import (TimeSeriesOutcome, perform_experiments,
                           RealParameter, ema_logging)

from ema_workbench.connectors.vensim import VensimModel

if __name__ == "__main__":
    #turn on logging
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    #instantiate a model
    wd = r'./models/vensim example'
    vensimModel = VensimModel("simpleModel", wd=wd,
                              model_file=r'\model.vpm')
    vensimModel.uncertainties = [RealParameter("x11", 0, 2.5),
                                 RealParameter("x12", -2.5, 2.5)]
    
    vensimModel.outcomes = [TimeSeriesOutcome('a')]
    
    results = perform_experiments(vensimModel, 1000, parallel=True)
    
コード例 #2
0
This file illustrated the use the EMA classes for a contrived vensim
example


.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
                chamarat <c.hamarat (at) tudelft (dot) nl>
'''
from __future__ import (division, unicode_literals, absolute_import,
                        print_function)

from ema_workbench import (TimeSeriesOutcome, perform_experiments,
                           RealParameter, ema_logging)

from ema_workbench.connectors.vensim import VensimModel

if __name__ == "__main__":
    # turn on logging
    ema_logging.log_to_stderr(ema_logging.INFO)

    # instantiate a model
    wd = r'./models/vensim example'
    vensimModel = VensimModel("simpleModel", wd=wd,
                              model_file=r'\model.vpm')
    vensimModel.uncertainties = [RealParameter("x11", 0, 2.5),
                                 RealParameter("x12", -2.5, 2.5)]

    vensimModel.outcomes = [TimeSeriesOutcome('a')]

    results = perform_experiments(vensimModel, 1000, parallel=True)
コード例 #3
0
'''
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)

import numpy as np

from ema_workbench import (RealParameter, TimeSeriesOutcome, ema_logging,
                           ScalarOutcome, perform_experiments)
from ema_workbench.em_framework.parameters import Policy
from ema_workbench.connectors.vensim import VensimModel

if __name__ == '__main__':
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel("fluCase",
                        wd=r'./models/flu',
                        model_file=r'FLUvensimV1basecase.vpm')

    #outcomes
    model.outcomes = [
        TimeSeriesOutcome('deceased population region 1'),
        TimeSeriesOutcome('infected fraction R1'),
        ScalarOutcome('max infection fraction',
                      variable_name='infected fraction R1',
                      function=np.max)
    ]

    #Plain Parametric Uncertainties
    model.uncertainties = [
        RealParameter('additional seasonal immune population fraction R1', 0,
                      0.5),
コード例 #4
0
    def test_added_uncertainties(self):
        '''
        the lookup uncertainty replaces itself with a set of other 
        uncertainties. Here we test whether this works correctly for
        each of the options provided by the lookup uncertainty
        
        
        '''
        if os.name != 'nt':
            return


        # categories
        msi = VensimModel('', 'test')
 
        lookup_type = 'categories'
        name = 'test'
        values = [[(0.0, 0.05), (0.25, 0.15), (0.5, 0.4), (0.75, 1), (1, 1.25)], 
                  [(0.0, 0.1), (0.25, 0.25), (0.5, 0.75), (1, 1.25)],
                  [(0.0, 0.0), (0.1, 0.2), (0.3, 0.6), (0.6, 0.9), (1, 1.25)]]
        LookupUncertainty(lookup_type, values, name, msi)
         
        self.assertEqual(len(msi.uncertainties), 1)
        self.assertTrue(isinstance(msi.uncertainties[0], 
                                   CategoricalUncertainty))


        # hearne1
        msi = VensimModel('', 'test')
        msi.uncertainties = []
 
        lookup_type = 'hearne1'
        name = 'test'
        values = [(0,1),(0,1),(0,1),(0,1)]
        LookupUncertainty(lookup_type, values, name, msi)
         
        self.assertEqual(len(msi.uncertainties), 4)
        for unc in msi.uncertainties:
            self.assertTrue(isinstance(unc, 
                                   RealParameter))


        # hearne2
        msi = VensimModel('', 'test')
        msi.uncertainties = []
        
        lookup_type = 'hearne2'
        name = 'test'
        values = [(0,1),(0,1),(0,1),(0,1),(0,1),(0,1)]
        LookupUncertainty(lookup_type, values, name, msi)
         
        self.assertEqual(len(msi.uncertainties), 6)
        for unc in msi.uncertainties:
            self.assertTrue(isinstance(unc, 
                                   RealParameter))


        # approximation
        msi = VensimModel('', 'test')
        msi.uncertainties = []
        
        lookup_type = 'approximation'
        name = 'test'
        values = [(0,1),(0,1),(0,1),(0,1),(0,1),(0,1)]
        LookupUncertainty(lookup_type, values, name, msi)
         
        self.assertEqual(len(msi.uncertainties), 5)
        for unc in msi.uncertainties:
            self.assertTrue(isinstance(unc, RealParameter))
コード例 #5
0
                epruyt <e.pruyt (at) tudelft (dot) nl>
'''
from __future__ import (division, unicode_literals, print_function, 
                        absolute_import)

import numpy as np

from ema_workbench import (RealParameter,TimeSeriesOutcome, ema_logging,
                           ScalarOutcome, perform_experiments)
from ema_workbench.em_framework.parameters import Policy
from ema_workbench.connectors.vensim import VensimModel 

if __name__ == '__main__':
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel("fluCase", wd=r'./models/flu',
                        model_file = r'FLUvensimV1basecase.vpm')
            
    #outcomes
    model.outcomes = [TimeSeriesOutcome('deceased population region 1'),
                      TimeSeriesOutcome('infected fraction R1'),
                      ScalarOutcome('max infection fraction', 
                                    variable_name='infected fraction R1', 
                                    function=np.max)]
    
    #Plain Parametric Uncertainties 
    model.uncertainties = [
        RealParameter('additional seasonal immune population fraction R1', 0, 0.5),
        RealParameter('additional seasonal immune population fraction R2', 0, 0.5),
        RealParameter('fatality ratio region 1', 0.0001, 0.1),
        RealParameter('fatality rate region 2', 0.0001, 0.1),
        RealParameter('initial immune fraction of the population of region 1', 0, 0.5),
levers = [
    RealParameter("Lever Social Distance I", 0.00001, 1),
    RealParameter("Lever Social Distance II", 0.00001, 1),
    RealParameter("Lever Social Distance III", 0.00001, 1),
    RealParameter("Lever Public Info", 0.00001, 1),
    RealParameter("Lever Public Edu", 0.00001, 1),
    RealParameter("Lever Facemasks", 0.00001, 1),
    RealParameter("Lever Tracing", 0.00001, 1),
    RealParameter("Lever Case Isolation", 0.00001, 1),
    RealParameter("Lever Voluntary or Involuntary Vaccination", 0.00001, 1),
    RealParameter("Lever Vaccination", 0.00001, 1),
    RealParameter("Lever Medical Care I", 0.00001, 1),
    RealParameter("Lever Medical Care II", 0.00001, 1)
]

mdl = VensimModel('Immunization',
                  model_file=r'./models/03_SEIR_SIR_ActionsAsLevers.vpm')
mdl.uncertainties = uncertainties
mdl.outcomes = outcomes
mdl.constants = constants
mdl.levers = levers
mdl.robustness = robustness
mdl.time_horizon = 360

n_scenarios = 50
scenarios = sample_uncertainties(mdl, n_scenarios)
nfe = 1000

with SequentialEvaluator(mdl) as evaluator:
    robust_results = evaluator.robust_optimize(mdl.robustness,
                                               scenarios,
                                               nfe=nfe,
from ema_workbench import (RealParameter, TimeSeriesOutcome, ema_logging,
                           perform_experiments, MultiprocessingEvaluator)

from ema_workbench.connectors.vensim import VensimModel

if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel(
        "PredPrey", wd='.', model_file='PredPrey.vpmx'
    )  # CANNOT MAKE A VPM FILE, SO THIS CONNECTOR CANNOT BE USED?

    # outcomes
    model.outcomes = [
        TimeSeriesOutcome('predators'),
        TimeSeriesOutcome('prey')
    ]

    # Plain Parametric Uncertainties
    model.uncertainties = [
        RealParameter('prey birth rate', 0.015, 0.35),
        RealParameter('predation rate', 0.0005, 0.003),
        RealParameter('predator efficiency', 0.001, 0.004),
        RealParameter('predator loss rate', 0.04, 0.08),
    ]

    nr_experiments = 10
    with MultiprocessingEvaluator(model) as evaluator:
        results = perform_experiments(model,
                                      nr_experiments,
                                      evaluator=evaluator)
コード例 #8
0
from ema_workbench.em_framework.parameters import Policy, create_parameters

from ema_workbench.connectors.vensim import VensimModel


def time_of_max(infected_fraction, time):
    index = np.where(infected_fraction == np.max(infected_fraction))
    timing = time[index][0]
    return timing


if __name__ == '__main__':
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel("fluCase",
                        wd=r'./models/flu',
                        model_file=r'/FLUvensimV1basecase.vpm')

    #outcomes
    model.outcomes = [
        TimeSeriesOutcome('deceased population region 1'),
        TimeSeriesOutcome('infected fraction R1'),
        ScalarOutcome('max infection fraction',
                      variable_name='infected fraction R1',
                      function=np.max),
        ScalarOutcome('time of max',
                      variable_name=['infected fraction R1', 'TIME'],
                      function=time_of_max)
    ]

    #create uncertainties based on csv
コード例 #9
0
def get_model_for_problem_formulation(problem_formulation_idea):
    disease_model = VensimModel("multidisease",
                                wd=r'.\models',
                                model_file='disease_model.vpm')

    disease_model.uncertainties = [
        # Sanitation Unknowns
        IntegerParameter('desire for improved sanitation', 10, 100),
        # Water Supply Unknowns
        IntegerParameter('Cost of well repair', 660, 1800),
        # Water Quality Unknowns
        IntegerParameter('use HWT', 10, 100),
        # Hygiene Unknowns
        IntegerParameter('Intensity of hygiene campaign', 10, 100),
        # Vaccination Unknowns
        IntegerParameter('Reliability of vaccine supply', 10, 100),
        # Treatment Unknowns
        IntegerParameter('seeking treatment', 10, 100),
        # Other Unknowns
        IntegerParameter('percent willing to accept MDA', 10, 100),
        # RealParameter('Childbearing years', 9, 14), #N.B. huge impact
    ]

    disease_model.constants = [
        Constant('Length latrine program', 10),
        Constant('Length GW supply program', 10),
        Constant('Length of water quality program', 10),
        Constant("Duration of hygiene campaign", 10),
        Constant("Length of ORT subsidy", 10),
        Constant("Years of MDA campaign", 10)
    ]

    disease_model.levers = [
        # Sanitation Levers
        IntegerParameter("Number of new latrines to build", 0, 9000),
        IntegerParameter("Number of latrines to maintain", 0, 4000),
        # Water Supply Levers
        IntegerParameter("Number of new wells to drill", 0, 2000),
        IntegerParameter("Number of wells to repair", 0, 2000),
        # Water Quality Levers
        IntegerParameter("Availability HWT", 0, 100),
        # Hygiene Promotion Levers
        IntegerParameter("HW stations to build", 0, 8000),
        # Vaccination Levers
        IntegerParameter("percentage of infants to vaccinate", 0, 100),
        # Treatment Levers
        IntegerParameter("Access to tmt", 0, 100),
        # MDA levers
        IntegerParameter("percent adults given MDA", 0, 100),
        IntegerParameter("percent youth given Albendazole", 0, 100),
    ]

    # add policies
    disease_model.policies = [
        Policy(
            'LatrineProgram', **{
                "Number of new latrines to build": 5000,
                "Number of latrines to maintain": 4000,
                "Length latrine program": 10,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'GWsupply', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 1000,
                "Number of wells to repair": 100,
                "Length GW supply program": 10,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'ORT', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 100,
                "Length of ORT subsidy": 10,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'Hygiene', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 1000,
                "Duration of hygiene campaign": 10,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'Vaccin', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 100,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'DrinkingWater', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 100,
                "Length of water quality program": 10,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
        Policy(
            'MDA', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 100,
                "percent youth given Albendazole": 100,
                "Years of MDA campaign": 10,
            }),
        Policy(
            'DoNothing', **{
                "Number of new latrines to build": 0,
                "Number of latrines to maintain": 0,
                "Length latrine program": 0,
                "Number of new wells to drill": 0,
                "Number of wells to repair": 0,
                "Length GW supply program": 0,
                "Availability HWT": 0,
                "Length of water quality program": 0,
                "HW stations to build": 0,
                "Duration of hygiene campaign": 0,
                "percentage of infants to vaccinate": 0,
                "Access to tmt": 0,
                "Length of ORT subsidy": 0,
                "percent adults given Albendazole": 0,
                "percent youth given Albendazole": 0,
                "Years of MDA campaign": 0,
            }),
    ]
    # Problem formulations:
    direction = ScalarOutcome.MINIMIZE
    if problem_formulation_idea == 1:  ##PF1: Minimum child (<5 yo) deaths due to Rotavirus
        disease_model.name = 'Minimize Child <5 Rotavirus infections by 2030'
        disease_model.outcomes.clear()
        disease_model.outcomes = [
            ScalarOutcome(
                'Mortality',  #Deaths due to Rotavirus
                variable_name=[
                    'children under 5 deaths[Rota]', 'ts until 2020',
                    'ts at 2030'
                ],
                function=avg_over_period,
                kind=direction,
                expected_range=(10000, 250000)),
            ScalarOutcome(
                'Morbidity',  #Rota DALYs children
                variable_name=[
                    "Years Lost to Disability in Children[Rota]",
                    'ts until 2020', 'ts at 2030'
                ],
                function=avg_over_period,
                kind=direction,
                expected_range=(6000, 9000)),
            ScalarOutcome(
                'Timeliness',  #Delta child infections 2030
                variable_name=[
                    "Number of Children Infected[Rota]", 'ts until 2020',
                    'ts at 2030'
                ],
                function=change_over_period,
                kind=direction,
                expected_range=(-0.9, 0.1)),
            ScalarOutcome(
                'CapEx',
                variable_name=['Upfront Cost', 'ts until 2020', 'ts at 2040'],
                function=total_over_period,
                kind=direction,
                expected_range=(0, 3000000000000)),
            ScalarOutcome(
                'OpEx',  #Recurring Cost
                variable_name=[
                    'Recurring Cost', 'ts until 2020', 'ts at 2040'
                ],
                function=total_over_period,
                kind=direction,
                expected_range=(0, 2000000000000)),
        ]

    elif problem_formulation_idea == 2:  ##PF2: Minimum prevalence of ascariasis in Youth (Infants, PreSACs, and SACs) in 5 years
        disease_model.name = 'Minimize Ascariasis in Youth by 2025'
        disease_model.outcomes.clear()
        disease_model.outcomes = [
            ScalarOutcome('Mortality',
                          variable_name=[
                              'Youth Mortality[Ascar]', 'ts until 2020',
                              'ts at 2025'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(1000, 20000)),
            ScalarOutcome('Morbidity',
                          variable_name=[
                              'Years Lost to Disability in Youth[Ascar]',
                              'ts until 2020', 'ts at 2025'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(20000, 160000)),
            ScalarOutcome(
                'Timeliness',  #Change in prevalence of ascariasis in youth by 2025
                variable_name=[
                    'Number of Youth Infected[Ascar]', 'ts until 2020',
                    'ts at 2025'
                ],
                function=change_over_period,
                kind=direction,
                expected_range=(-1, 0)),
            ScalarOutcome(
                'CapEx',  #Upfront Cost
                variable_name=['Upfront Cost', 'ts until 2020', 'ts at 2040'],
                function=total_over_period,
                kind=direction,
                expected_range=(0, 3000000000000)),
            ScalarOutcome(
                'OpEx',  #Recurring Cost
                variable_name=[
                    'Recurring Cost', 'ts until 2020', 'ts at 2040'
                ],
                function=total_over_period,
                kind=direction,
                expected_range=(0, 2000000000000)),
        ]
    elif problem_formulation_idea == 3:  #PF3: Minimum Child (<5 yo) mortality, all diseases, w/in one year
        disease_model.name = 'Immediately minimize Child <5 burden from all causes'
        disease_model.outcomes.clear()
        disease_model.outcomes = [
            ScalarOutcome('Mortality',
                          variable_name=[
                              'Total children under 5 deaths', 'ts until 2020',
                              'ts at 2021'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(50000, 400000)),
            ScalarOutcome('Morbidity',
                          variable_name=[
                              'morbidity in children', 'ts until 2020',
                              'ts at 2021'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(40000, 100000)),
            ScalarOutcome(
                'Timeliness',  #Delta child infections 2021
                variable_name=[
                    'Total children w gastroenteric infection',
                    'ts until 2020', 'ts at 2021'
                ],
                function=change_over_period,
                kind=direction,
                expected_range=(-0.5, 0)),
            ScalarOutcome(
                'CapEx',  #Upfront Cost
                variable_name=['Upfront Cost', 'ts until 2020', 'ts at 2040'],
                function=total_over_period,
                kind=direction,
                expected_range=(5000000, 3000000000000)),
            ScalarOutcome(
                'OpEx',  #Recurring Cost
                variable_name=[
                    'Recurring Cost', 'ts until 2020', 'ts at 2040'
                ],  #bc no rec cost will show up in 1 yr
                function=total_over_period,
                kind=direction,
                expected_range=(50000000000, 2000000000000)),
        ]
    elif problem_formulation_idea == 4:  #PF4: Minimum number infected, all diseases, sustainably
        disease_model.name = 'Minimize number infected all diseases by 2040'
        disease_model.outcomes.clear()
        disease_model.outcomes = [
            ScalarOutcome('Mortality',
                          variable_name=[
                              'Total lives lost', 'ts until 2020', 'ts at 2040'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(50000, 250000)),
            ScalarOutcome('Morbidity',
                          variable_name=[
                              'disability burden', 'ts until 2020',
                              'ts at 2040'
                          ],
                          function=avg_over_period,
                          kind=direction,
                          expected_range=(100000, 900000)),
            ScalarOutcome(
                'Timeliness',  #delta infections 2040
                variable_name=[
                    'Total number of gastroenteric infection', 'ts until 2020',
                    'ts at 2040'
                ],
                function=change_over_period,
                kind=direction,
                expected_range=(-1, -.45)),
            ScalarOutcome(
                'CapEx',  #Upfront Cost
                variable_name=['Upfront Cost', 'ts until 2020', 'ts at 2040'],
                function=total_over_period,
                kind=direction,
                expected_range=(20000000000, 3000000000000)),
            ScalarOutcome(
                'OpEx',  #Recurring Cost
                variable_name=[
                    'Recurring Cost', 'ts until 2020', 'ts at 2040'
                ],
                function=total_over_period,
                kind=direction,
                expected_range=(20000000000, 2000000000000)),
            ##recurring costs divided by 20 years
        ]

    else:
        raise TypeError('unknown problem identifier')
    return disease_model
コード例 #10
0
    fig.set_size_inches(12, 8)
    fig.subplots_adjust(bottom=0.3)
    plt.savefig("Sobol_n{}_Emissions.png".format(n),
                dpi=600,
                bbox_inches='tight')
    return fig


ema_logging.log_to_stderr(ema_logging.INFO)
ema_logging.log_to_stderr(ema_logging.DEBUG)

if __name__ == '__main__':
    directory = 'H:/MyDocuments/IIASA-Felix/Model files/Parallel_NatCom2/'

    vensimModel = VensimModel("FelixModel",
                              wd=directory,
                              model_file=r'FeliX3_Sibel_v16_NoExcel.vpm')

    #df_unc = pd.read_excel(directory+'Uncertainties_v3.xlsx', sheet_name='UncertaintiesNov2018')

    #vensimModel.outcomes = [TimeSeriesOutcome('Population')]
    df_unc = pd.read_excel(directory + 'ScenarioFramework.xlsx',
                           sheet_name='Uncertainties')
    #     df_drop = pd.read_csv(directory+'toremove_n2500_sc0.csv')
    #     df_drop.set_index('Parameter', inplace=True)
    #     print(df_drop.index)
    #     for p in df_drop.index:
    #         df_unc = df_unc[df_unc['Uncertainties'] != p]
    #     print(df_unc.shape)
    df_out = pd.read_excel(directory + 'ScenarioFramework.xlsx',
                           sheet_name='Outcomes')
コード例 #11
0
from ema_workbench.em_framework.parameters import Policy, create_parameters

from ema_workbench.connectors.vensim import VensimModel
from ema_workbench.em_framework.evaluators import MultiprocessingEvaluator


def time_of_max(infected_fraction, time):
    index = np.where(infected_fraction == np.max(infected_fraction))
    timing = time[index][0]
    return timing


if __name__ == '__main__':
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel("fluCase", wd=r'./models/flu',
                        model_file=r'/FLUvensimV1basecase.vpm')

    # outcomes
    model.outcomes = [TimeSeriesOutcome('deceased population region 1'),
                      TimeSeriesOutcome('infected fraction R1'),
                      ScalarOutcome('max infection fraction',
                                    variable_name='infected fraction R1',
                                    function=np.max),
                      ScalarOutcome('time of max',
                                    variable_name=[
                                        'infected fraction R1', 'TIME'],
                                    function=time_of_max)]

    # create uncertainties based on csv
    model.uncertainties = create_parameters(
        './models/flu/flu_uncertainties.csv')
コード例 #12
0
instead of coding the model in Python. The underlying case
is the same as used in fluExample

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
                epruyt <e.pruyt (at) tudelft (dot) nl>
"""
from __future__ import division, unicode_literals, print_function, absolute_import

from ema_workbench import RealParameter, TimeSeriesOutcome, ema_logging, perform_experiments

from ema_workbench.connectors.vensim import VensimModel

if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = VensimModel("fluCase", wd="./models/flu", model_file="FLUvensimV1basecase.vpm")

    # outcomes
    model.outcomes = [TimeSeriesOutcome("deceased population region 1"), TimeSeriesOutcome("infected fraction R1")]

    # Plain Parametric Uncertainties
    model.uncertainties = [
        RealParameter("additional seasonal immune population fraction R1", 0, 0.5),
        RealParameter("additional seasonal immune population fraction R2", 0, 0.5),
        RealParameter("fatality ratio region 1", 0.0001, 0.1),
        RealParameter("fatality rate region 2", 0.0001, 0.1),
        RealParameter("initial immune fraction of the population of region 1", 0, 0.5),
        RealParameter("initial immune fraction of the population of region 2", 0, 0.5),
        RealParameter("normal interregional contact rate", 0, 0.9),
        RealParameter("permanent immune population fraction R1", 0, 0.5),
        RealParameter("permanent immune population fraction R2", 0, 0.5),