예제 #1
0
class Burnout(VensimModel):
    model_file = r'\BURNOUT.vpm'
    outcomes = [TimeSeriesOutcome('Accomplishments to Date'),
                TimeSeriesOutcome('Energy Level'),
                TimeSeriesOutcome('Hours Worked Per Week'),
                TimeSeriesOutcome('accomplishments per hour')]

    def __init__(self, working_directory, name):
        super(Burnout, self).__init__(working_directory, name)

        self.uncertainties = [LookupUncertainty('hearne2', [(-1, 3), (-2, 1), (0, 0.9), (0.1, 1), (0.99, 1.01), (0.99, 1.01)],
                                                "accomplishments per hour lookup", self, 0, 1),
                              LookupUncertainty('hearne2', [(-0.75, 0.75), (-0.75, 0.75), (0, 1.5), (0.1, 1.6), (-0.3, 1.5), (0.25, 2.5)],
                                                "fractional change in expectations from perceived adequacy lookup", self, -1, 1),
                              LookupUncertainty('hearne2', [(-2, 2), (-1, 2), (0, 1.5), (0.1, 1.6), (0.5, 2), (0.5, 2)],
                                                "effect of perceived adequacy on energy drain lookup", self, 0, 10),
                              LookupUncertainty('hearne2', [(-2, 2), (-1, 2), (0, 1.5), (0.1, 1.6), (0.5, 1.5), (0.1, 2)],
                                                "effect of perceived adequacy of hours worked lookup", self, 0, 2.5),
                              LookupUncertainty('hearne2', [(-1, 1), (-1, 1), (0, 0.9), (0.1, 1), (0.5, 1.5), (1, 1.5)],
                                                "effect of energy levels on hours worked lookup", self, 0, 1.5),
                              LookupUncertainty('hearne2', [(-1, 1), (-1, 1), (0, 0.9), (0.1, 1), (0.5, 1.5), (1, 1.5)],
                                                "effect of high energy on further recovery lookup", self, 0, 1.25),
                              LookupUncertainty('hearne2', [(-2, 2), (-1, 1), (0, 100), (20, 120), (0.5, 1.5), (0.5, 2)],
                                                "effect of hours worked on energy recovery lookup", self, 0, 1.5),
                              LookupUncertainty('approximation', [(-0.5, 0.35), (3, 5), (1, 10), (0.2, 0.4), (0, 120)],
                                                "effect of hours worked on energy drain lookup", self, 0, 3),
                              LookupUncertainty('hearne1', [(0, 1), (0, 0.15), (1, 1.5), (0.75, 1.25)],
                                                "effect of low energy on further depletion lookup", self, 0, 1)]

        self._delete_lookup_uncertainties()
예제 #2
0
'''
Created on Apr 10, 2020

@author: jhkwakkel
'''
from ema_workbench import (RealParameter, TimeSeriesOutcome,
                           MultiprocessingEvaluator, SequentialEvaluator,
                           ema_logging)

from linnyr_connector import LinnyRModel  # @UnresolvedImport

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

    model = LinnyRModel(name='Smoothiemodel',
                        wd='./model',
                        model_file='simple_model.lnr')

    model.uncertainties = [
        RealParameter('Oranges:Price', 5, 20),
        RealParameter('Apples:Price', 30, 40)
    ]

    model.outcomes = [
        TimeSeriesOutcome('Apple price'),
        TimeSeriesOutcome('Orange price')
    ]

    with MultiprocessingEvaluator(model, n_processes=2) as evaluator:
        experiments, outcomes = evaluator.perform_experiments(scenarios=100)
예제 #3
0
def main():

    hybridmodel = Model('hybridmodel', function=hybridloop)

    hybridmodel.uncertainties = [
        IntegerParameter("inputpowerfactor", 15, 25),  #7 13
        IntegerParameter("inputLNGprice", 200, 1000),
        IntegerParameter("inputtransferprice", 50, 300),
        IntegerParameter("inputCapincrease", 1000, 3000),
        IntegerParameter("inputCapincreasetime", 1, 2),
        IntegerParameter("inputLNGCapincrease", 1000, 3000),
        IntegerParameter("inputLNGCapincreasetime", 1, 2),
        #                             RealParameter("DemandBalanceSupplyEnergyPrice", 0.4, 0.7),
        RealParameter("MaximumChangeinDemand", 0.4, 0.7),
        RealParameter("SupplyElasticityGas", 0.06, 0.07),
        RealParameter("SupplyElasticityOil", 0.1, 0.2),
        RealParameter("SupplyElasticityCoal", 0.1, 0.2),
        RealParameter("SupplyElasticityNuclear", 0.007, 0.017),
        RealParameter("SupplyElasticityBiofuel", 0.1, 0.2),
        RealParameter("SupplyElasticityOR", 0.15, 0.3),
        IntegerParameter("EconomicGrowthScenario", 1, 3),
        IntegerParameter("EnergyIntensityScenario", 1, 3),
        RealParameter("CO2coal", 93.46, 113.67),
        RealParameter("CO2oil", 59.58, 102.12),
        RealParameter("Variancepower", -5.0, -0.1),
        IntegerParameter("POil", 8900, 9100),
        IntegerParameter("PCoal", 2800, 3100),
        IntegerParameter("PBio", 29000, 32000),
        IntegerParameter("PNuc", 16000, 17000),
        IntegerParameter("POR", 19000, 22000),
        IntegerParameter("PGasE", 6500, 7000),
        IntegerParameter("PGasNA", 2500, 2700),
        IntegerParameter("PGasSCA", 2500, 2700),
        IntegerParameter("PGasCIS", 6500, 7000),
        IntegerParameter("PGasME", 7000, 8000),
        IntegerParameter("PGasAF", 7000, 8000),
        IntegerParameter("PGasAP", 7000, 8000)
    ]

    hybridmodel.outcomes = [
        TimeSeriesOutcome("EU_GasSup"),
        TimeSeriesOutcome("EU_GasDem"),
        TimeSeriesOutcome("EU_GasCon"),
        TimeSeriesOutcome("EU_OilSup"),
        TimeSeriesOutcome("EU_OilDem"),
        TimeSeriesOutcome("EU_OilCon"),
        TimeSeriesOutcome("EU_CoalSup"),
        TimeSeriesOutcome("EU_CoalDem"),
        TimeSeriesOutcome("EU_CoalCon"),
        TimeSeriesOutcome("EU_NucSup"),
        TimeSeriesOutcome("EU_NucDem"),
        #                         TimeSeriesOutcome("EU_NucCon"),
        TimeSeriesOutcome("EU_BioSup"),
        TimeSeriesOutcome("EU_BioDem"),
        TimeSeriesOutcome("EU_BioCon"),
        TimeSeriesOutcome("EU_ORSup"),
        TimeSeriesOutcome("EU_ORDem"),
        #                         TimeSeriesOutcome("EU_ORCon"),
        TimeSeriesOutcome("EU_EDem"),
        TimeSeriesOutcome("EU_ESup"),
        TimeSeriesOutcome("EU_GDP"),
        TimeSeriesOutcome("EU_CO2"),
        TimeSeriesOutcome("EU_RusGas"),
        TimeSeriesOutcome("EU_EUGI"),
        TimeSeriesOutcome("EU_GIC"),
        TimeSeriesOutcome("EU_RGperAG"),
        TimeSeriesOutcome("EU_RGperTES"),
        TimeSeriesOutcome("EU_RGperGC"),
        TimeSeriesOutcome("EU_GICperBBTU"),
        TimeSeriesOutcome("Oil_Price"),
        TimeSeriesOutcome("Coal_Price"),
        TimeSeriesOutcome("Bio_Price"),
        TimeSeriesOutcome("Gas_PriceE"),
        TimeSeriesOutcome("Nuc_PriceE"),
        TimeSeriesOutcome("OR_PriceE"),
        TimeSeriesOutcome("FuncpriceGas"),
        TimeSeriesOutcome("FuncpriceOil"),
        TimeSeriesOutcome("FuncpriceCoal")
    ]

    hybridmodel.levers = [
        IntegerParameter("EnergyUnion", 0, 1),
        IntegerParameter("CO2Cost", 0, 1)
    ]

    # In[ ]:

    ema_logging.log_to_stderr(ema_logging.INFO)
    with MultiprocessingEvaluator(hybridmodel) as evaluator:
        results = evaluator.perform_experiments(scenarios=1,
                                                policies=4,
                                                levers_sampling='ff')

# In[1]:

    save_results(results, r'./1000 runs V30.tar.gz')
예제 #4
0
                             categories=[1000, 0]),
        CategoricalParameter(
            name='E-boiler 4',
            variable_name='AL 50 bar fixed rate (Air Liquide):LB',
            categories=[0, 22.5]),
        CategoricalParameter(name='E-boiler 5',
                             variable_name='DA inkoop EB70 (Air Liquide):UB',
                             categories=[0, 6]),
        CategoricalParameter(name='Chlorine storage',
                             variable_name='stored CL2 (Nouryon):UB',
                             categories=[1600, 3200])
    ]

    # define the outcomes
    model.outcomes = [
        TimeSeriesOutcome(name='CF total', variable_name='CF total'),
        TimeSeriesOutcome(name='CO2 emissions', variable_name='CO2 emission')
    ]

    # generate the desired policies
    policies = [
        generate(name='no policy',
                 steam_pipe=False,
                 e_boiler=False,
                 chorine_storage=False),
        generate(name='Only Steam Pipe',
                 steam_pipe=True,
                 e_boiler=False,
                 chorine_storage=False),
        generate(name='Only E-boiler',
                 steam_pipe=False,
예제 #5
0
    model = NetLogoModel('predprey',
                         wd="./models/predatorPreyNetlogo",
                         model_file="Wolf Sheep Predation.nlogo")
    model.run_length = 100
    model.replications = 1

    model.uncertainties = [
        RealParameter("grass-regrowth-time", 1, 99),
        RealParameter("initial-number-sheep", 1, 200),
        RealParameter("initial-number-wolves", 1, 200),
        RealParameter("sheep-reproduce", 1, 20),
        RealParameter("wolf-reproduce", 1, 20),
    ]

    model.outcomes = [
        TimeSeriesOutcome('sheep'),
        TimeSeriesOutcome('wolves'),
        TimeSeriesOutcome('grass'),
        TimeSeriesOutcome('TIME')
    ]

    #perform experiments
    n = 10

    with MultiprocessingEvaluator(model) as evaluator:
        results = perform_experiments(model, n, evaluator=evaluator)

    fn = r'./data/{} runs.tar.gz'.format(n)
    save_results(results, fn)

    print "finish"
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',
예제 #7
0
'''


'''

# Created on Jul 23, 2016
#
# .. codeauthor::jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>

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

from ema_workbench.connectors.pysd_connector import PysdModel

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

    mdl_file = './models/pysd/Teacup.mdl'

    model = PysdModel(mdl_file=mdl_file)

    model.uncertainties = [RealParameter('Room Temperature', 33, 120)]
    model.outcomes = [TimeSeriesOutcome('Teacup Temperature')]

    perform_experiments(model, 100)
    ]

    # Specify Municipalties to save neighbourhood data
    multi_model.ABMsavelist = [
        '"Amsterdam"', '"Rotterdam"', '"Arnhem"', '"Zwartewaterland"'
    ]  # Double quotes needed for netlogo

    multi_model.SD_subscripted_output = [[
        'System Distributions', 'sub_mun-sys'
    ], ['Total Electricity use', 'mun_subs']]

    # subscript options implemented: ['mun_subs','sys_subs','ins_subs','sub_mun-sys']

    # FOR ABM: globals only
    multi_model.outcomes = [
        TimeSeriesOutcome('SD_Average Gas Price'),
        TimeSeriesOutcome('SD_Average Electricity Price'),
        TimeSeriesOutcome('SD_Average Heat Price'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[Natural Gas]'),
        TimeSeriesOutcome('SD_National Energy System Distribution[Green Gas]'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[LT Heating Grid]'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[MT Heating Grid]'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[HT Heating Grid]'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[Air Heat Pump]'),
        TimeSeriesOutcome(
            'SD_National Energy System Distribution[Ground Heat Pump]'),
예제 #9
0
    model.replications = 2


    #specify uncertainties
	model.uncertainties = [RealParameter("energy_demand_growth_f",-0.006, 0.013),
                            RealParameter("a",0,0.2),
                            RealParameter("market_share_base_growth_f", -0.02, 0.02),
                            IntegerParameter("u", 0,39),
                            RealParameter("c",0.03,0.733),
                            RealParameter("other_grey_share_growth_f", -0.015,0.015)
                          ]
                        	
                      	
   
    #specify outcomes 
    model.outcomes = [TimeSeriesOutcome('area_capacity_current', function=mean_over_replications),    
                    TimeSeriesOutcome('area_capacity_unused_current', function=mean_over_replications),           
                    TimeSeriesOutcome('area_TP_current', function=mean_over_replications),                       
                    TimeSeriesOutcome('area_occupancy_current', function=mean_over_replications),                
                    TimeSeriesOutcome('area_denied_infra_cap_current', function=mean_over_replications),          
                    TimeSeriesOutcome('area_denied_cap_percentage_current', function=mean_over_replications),     
                    TimeSeriesOutcome('terminal_capacity_current', function=mean_over_replications),              
                    TimeSeriesOutcome('terminal_capacity_unused_current', function=mean_over_replications),       
                    TimeSeriesOutcome('terminal_TP_current', function=mean_over_replications),                    
                    TimeSeriesOutcome('terminal_occupancy_current', function = mean_over_replications),             
                    TimeSeriesOutcome('terminal_capacity_expanded_current', function=mean_over_replications),     
                    TimeSeriesOutcome('terminal_capacity_initial_current', function=mean_over_replications),      
                    TimeSeriesOutcome('terminal_denied_infra_cap_current', function=mean_over_replications),      
                    TimeSeriesOutcome('terminal_surface_current', function=mean_over_replications),               
                    TimeSeriesOutcome('TP_without_terminal_current', function=mean_over_replications),            
                    TimeSeriesOutcome('total_TP_rdam_current', function=mean_over_replications),                  
    model.uncertainties = [
        RealParameter('clustering-resources', 0, 1),
        RealParameter('clustering-PCFs', 0, 1),
        RealParameter('clustering-SCFs', 0, 1),
        RealParameter('clustering-ECFs', 0, 1),
        RealParameter('width-distributions-resources', 0, 1),
        #RealParameter('width-distributions-PCFs', 0, 1),
        RealParameter('width-distributions-SCFs', 0, 1),
        RealParameter('width-distributions-ECFs', 0, 1),
        RealParameter('social-network-size', 2, 8),
        RealParameter('network-ratio', 0, 1)
    ]

    model.outcomes = [
        TimeSeriesOutcome('level-of-achievability'),
        TimeSeriesOutcome('personal-conversion-factor-shortage'),
        TimeSeriesOutcome('social-conversion-factor-shortage'),
        TimeSeriesOutcome('environmental-conversion-factor-shortage'),
        TimeSeriesOutcome('TIME')
    ]

    #perform experiments
    n = 100

    with MultiprocessingEvaluator(model) as evaluator:
        #results = evaluator.perform_experiments(scenarios=500)
        results = perform_experiments(model, n, evaluator=evaluator)

    fn = r'./data/{}_runs_cap_approach.tar.gz'.format(n)
    save_results(results, fn)
예제 #11
0
def outcome_spec(out_spec_name):

    if out_spec_name == 'all':
        dice_sm.outcomes = [
            TimeSeriesOutcome('Atmospheric Temperature'),
            TimeSeriesOutcome('Total Output'),
            # TimeSeriesOutcome('Population'),
            TimeSeriesOutcome('Per Capita Consumption'),
            TimeSeriesOutcome('Consumption Growth'),
            TimeSeriesOutcome('Utility of Consumption'),
            TimeSeriesOutcome('Per Capita Damage'),
            TimeSeriesOutcome('Damage Growth'),
            TimeSeriesOutcome('Disutility of Damage'),
            TimeSeriesOutcome('Welfare'),
            TimeSeriesOutcome('Undiscounted Period Welfare'),
            TimeSeriesOutcome('Consumption SDR'),
            TimeSeriesOutcome('Damage SDR')
        ]

    elif out_spec_name == 'VD':
        dice_sm.outcomes = [
            TimeSeriesOutcome('Atmospheric Temperature'),
            # TimeSeriesOutcome('Total Output'),
            # TimeSeriesOutcome('Population'),
            # TimeSeriesOutcome('Per Capita Consumption'),
            # TimeSeriesOutcome('Consumption Growth'),
            # TimeSeriesOutcome('Utility of Consumption'),
            TimeSeriesOutcome('Per Capita Damage'),
            TimeSeriesOutcome('Damage Growth'),
            TimeSeriesOutcome('Disutility of Damage'),
            TimeSeriesOutcome('Welfare'),
            TimeSeriesOutcome('Undiscounted Period Welfare'),
            # TimeSeriesOutcome('Consumption SDR'),
            TimeSeriesOutcome('Damage SDR')
        ]

    elif out_spec_name == 'UC':
        dice_sm.outcomes = [
            TimeSeriesOutcome('Atmospheric Temperature'),
            # TimeSeriesOutcome('Total Output'),
            # TimeSeriesOutcome('Population'),
            TimeSeriesOutcome('Per Capita Consumption'),
            TimeSeriesOutcome('Consumption Growth'),
            TimeSeriesOutcome('Utility of Consumption'),
            TimeSeriesOutcome('Per Capita Damage'),
            # TimeSeriesOutcome('Damage Growth'),
            TimeSeriesOutcome('Disutility of Damage'),
            TimeSeriesOutcome('Welfare'),
            TimeSeriesOutcome('Undiscounted Period Welfare'),
            TimeSeriesOutcome('Consumption SDR'),
            # TimeSeriesOutcome('Damage SDR')
        ]

    elif out_spec_name == 'light':
        dice_sm.outcomes = [  #TimeSeriesOutcome('Atmospheric Temperature'),
            # TimeSeriesOutcome('Total Output'),
            # TimeSeriesOutcome('Population'),
            TimeSeriesOutcome('Per Capita Consumption'),
            # TimeSeriesOutcome('Consumption Growth'),
            TimeSeriesOutcome('Utility of Consumption'),
            TimeSeriesOutcome('Per Capita Damage'),
            # TimeSeriesOutcome('Damage Growth'),
            TimeSeriesOutcome('Disutility of Damage'),
            TimeSeriesOutcome('Welfare'),
            TimeSeriesOutcome('Undiscounted Period Welfare'),
            # TimeSeriesOutcome('Consumption SDR'),
            # TimeSeriesOutcome('Damage SDR')
        ]

    # elif out_spec_name == 'final':
    #     dice_sm.outcomes = [
    #         ScalarOutcome('Atmospheric Temperature 2300'),
    #         ScalarOutcome('Per Capita Consumption 2300'),
    #         ScalarOutcome('Utility of Consumption 2300'),
    #         ScalarOutcome('Per Capita Damage 2300'),
    #         ScalarOutcome('Disutility of Damage 2300'),
    #         ScalarOutcome('Welfare 2300'),
    #         ScalarOutcome('Total Output 2300')

    # ]

    return dice_sm.outcomes
예제 #12
0
파일: PRIM.py 프로젝트: shkulk/noDICE
        IntegerParameter('cback', 100, 600),
        RealParameter('emdd', -1, 0.99),
        IntegerParameter('vd_switch', 0, 1),
    ]

    dice_sm.levers = [
        RealParameter('sr', 0.1, 0.5),
        RealParameter('prtp_con', 0.001, 0.015),
        RealParameter('emuc', 1.01, 2.00),
        #   IntegerParameter('vd_switch', 0, 1),
        IntegerParameter('periodfullpart', 10, 58),
        IntegerParameter('miu_period', 10, 58)
    ]

    dice_sm.outcomes = [
        TimeSeriesOutcome('Atmospheric Temperature'),
        TimeSeriesOutcome('Total Output'),
        TimeSeriesOutcome('Per Capita Consumption'),
        TimeSeriesOutcome('Consumption Growth'),
        TimeSeriesOutcome('Utility of Consumption'),
        TimeSeriesOutcome('Per Capita Damage'),
        TimeSeriesOutcome('Damage Growth'),
        TimeSeriesOutcome('Disutility of Damage'),
        TimeSeriesOutcome('Welfare'),
        # TimeSeriesOutcome('Undiscounted Period Welfare'),
        TimeSeriesOutcome('Consumption SDR'),
        TimeSeriesOutcome('Damage SDR'),
        TimeSeriesOutcome('SCC')
    ]

# %%
예제 #13
0
# .. codeauthor::  jhkwakkel


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

    model = NetLogoModel('predprey',
                         wd="./models/predatorPreyNetlogo",
                         model_file="Wolf Sheep Predation.nlogo")
    model.run_length = 100
    model.replications = 10

    model.uncertainties = [RealParameter("grass-regrowth-time", 1, 99),
                           RealParameter("initial-number-sheep", 50, 100),
                           RealParameter("initial-number-wolves", 50, 100),
                           RealParameter("sheep-reproduce", 5, 10),
                           RealParameter("wolf-reproduce", 5, 10),
                           ]

    model.outcomes = [TimeSeriesOutcome('sheep'),
                      TimeSeriesOutcome('wolves'),
                      TimeSeriesOutcome('grass')]

    # perform experiments
    n = 10

    with MultiprocessingEvaluator(model, n_processes=2,
                                  maxtasksperchild=4) as evaluator:
        results = evaluator.perform_experiments(n)
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)
예제 #15
0
from ema_workbench import Model, RealParameter, TimeSeriesOutcome

model = Model('predprey', function=predprey)

# specify 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),
]

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

# model constants
model.constants = [
    Constant('dt', 0.25),
    Constant('final_time', 365),
    Constant('reps', 1)
]

###
# Perform experiments
from ema_workbench import (SequentialEvaluator)

with SequentialEvaluator(model) as evaluator:
예제 #16
0
        RealParameter('x32', 0, 0.5),
        RealParameter('x41', 0, 0.9),
        RealParameter('x51', 0, 0.5),
        RealParameter('x52', 0, 0.5),
        RealParameter('x61', 0, 0.8),
        RealParameter('x62', 0, 0.8),
        RealParameter('x81', 1, 10),
        RealParameter('x82', 1, 10),
        RealParameter('x91', 0, 0.1),
        RealParameter('x92', 0, 0.1),
        RealParameter('x101', 0, 200),
        RealParameter('x102', 0, 200)
    ]

    model.outcomes = [
        TimeSeriesOutcome("TIME"),
        TimeSeriesOutcome("deceased_population_region_1")
    ]

    nr_experiments = 500

    results = perform_experiments(model, 10)

    #     with MultiprocessingPoolEvaluator(model) as evaluator:
    #         results = perform_experiments(model, nr_experiments,
    #                                       evaluator=evaluator)

    lines(results,
          outcomes_to_show="deceased_population_region_1",
          show_envelope=True,
          density=KDE,
예제 #17
0
    ema_logging.log_to_stderr(level=ema_logging.INFO)

    model = ExcelModel("predatorPrey",
                       wd="./models/excelModel",
                       model_file='excel example.xlsx')
    model.uncertainties = [
        RealParameter("K2", 0.01,
                      0.2),  #we can refer to a cell in the normal way
        RealParameter("KKK", 450, 550),  # we can also use named cells
        RealParameter("rP", 0.05, 0.15),
        RealParameter("aaa", 0.00001, 0.25),
        RealParameter("tH", 0.45, 0.55),
        RealParameter("kk", 0.1, 0.3)
    ]

    #specification of the outcomes
    model.outcomes = [
        TimeSeriesOutcome(
            "B4:B1076"),  #we can refer to a range in the normal way
        TimeSeriesOutcome("P_t")
    ]  # we can also use named range

    #name of the sheet
    model.sheet = "Sheet1"

    with MultiprocessingEvaluator(model) as evaluator:
        results = perform_experiments(model,
                                      100,
                                      reporting_interval=1,
                                      evaluator=evaluator)
if __name__ == "__main__":
    ema_logging.log_to_stderr(level=ema_logging.INFO)

    model = ExcelModel("predatorPrey", wd=".", model_file='PredPrey.xlsx')

    model.uncertainties = [
        RealParameter("B3", 0.015, 0.35),  # prey_birth_rate
        RealParameter("B4", 0.0005, 0.003),  # predation_rate
        RealParameter("B5", 0.001, 0.004),  # predator_efficiency
        RealParameter("B6", 0.04, 0.08),  # predator_loss_rate
    ]

    # specification of the outcomes
    model.outcomes = [
        TimeSeriesOutcome(
            "B17:BDF17"),  # we can refer to a range in the normal way
        TimeSeriesOutcome("B18:BDF18")
    ]  # we can also use named range

    # name of the sheet
    model.default_sheet = "Sheet1"

    with SequentialEvaluator(model) as evaluator:
        results = perform_experiments(model,
                                      25,
                                      reporting_interval=1,
                                      evaluator=evaluator)

    experiments, outcomes = results
    print(experiments.shape)
    print(list(outcomes.keys()))
예제 #19
0
from ema_workbench import (RealParameter, TimeSeriesOutcome, ema_logging,
                           perform_experiments)

from ema_workbench.connectors.excel import ExcelModel
from ema_workbench.em_framework.evaluators import MultiprocessingEvaluator


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

    model = ExcelModel("predatorPrey", wd="./models/excelModel",
                       model_file='excel example.xlsx')
    model.uncertainties = [RealParameter("K2", 0.01, 0.2),  # we can refer to a cell in the normal way
                           # we can also use named cells
                           RealParameter("KKK", 450, 550),
                           RealParameter("rP", 0.05, 0.15),
                           RealParameter("aaa", 0.00001, 0.25),
                           RealParameter("tH", 0.45, 0.55),
                           RealParameter("kk", 0.1, 0.3)]

    # specification of the outcomes
    model.outcomes = [TimeSeriesOutcome("B4:B1076"),  # we can refer to a range in the normal way
                      TimeSeriesOutcome("P_t")]  # we can also use named range

    # name of the sheet
    model.sheet = "Sheet1"

    with MultiprocessingEvaluator(model) as evaluator:
        results = perform_experiments(model, 100, reporting_interval=1,
                                      evaluator=evaluator)
예제 #20
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)
예제 #21
0
                          0.4, ax1)
    tree_generate_heatmap(x, prey_final_np, prey_mean_np, prey_std_np, 100,
                          0.6, ax2)
    tree_generate_heatmap(x, prey_final_np, prey_mean_np, prey_std_np, 100,
                          0.8, ax3)

    plt.show()


model = Model('PredPreyGSA', function=pred_prey)

model.uncertainties = [
    RealParameter('prey_birth_rate', 0.015, 0.035),
    RealParameter('predation_rate', 0.0005, 0.003),
    RealParameter('predator_efficiency', 0.001, 0.004),
    RealParameter('predator_loss_rate', 0.04, 0.08)
]

model.outcomes = [
    TimeSeriesOutcome('TIME', function=np.squeeze),
    TimeSeriesOutcome('predators', function=np.squeeze),
    TimeSeriesOutcome('prey', function=np.squeeze)
]

run_full_tree_experiment(50)
run_full_tree_experiment(250)
run_full_tree_experiment(1000)

# We can see that the sample size has a significant impact on the relative sobol indices. Most noticably, the tree model predicts a lower importance of the predator efficiency on the prey_mean value.
#
예제 #22
0
def plot_lotka_volterra(model_instance):

    model_instance.uncertainties = [
        RealParameter('prey_birth_rate', 0.015, 0.035),
        RealParameter('predation_rate', 0.0005, 0.003),
        RealParameter('predator_efficiency', 0.001, 0.004),
        RealParameter('predator_loss_rate', 0.04, 0.08)
    ]

    model_instance.outcomes = [
        TimeSeriesOutcome('TIME'),
        TimeSeriesOutcome('predators'),
        TimeSeriesOutcome('prey')
    ]

    with SequentialEvaluator(model_instance) as evaluator:
        sa_results = evaluator.perform_experiments(scenarios=50,
                                                   uncertainty_sampling=LHS)

    experiments, outcomes = sa_results

    # Squeeze outcomes
    outcomes_squeezed = {}

    for key in outcomes:
        outcomes_squeezed[key] = np.squeeze(outcomes[key])

    # Store final values of prey outcome
    prey_final = []
    prey_mean = []
    prey_std = []

    # Iterate through rows of outcome numpy array (experiments) to calculate indicators
    for experiment_row in outcomes_squeezed["prey"]:
        prey_final.append(experiment_row[-1])  # Get last element
        prey_mean.append(np.mean(experiment_row))
        prey_std.append(np.std(experiment_row))

    # Collect indicators in dictionary to calculate regression for each of them
    indicators = {
        'prey_final': prey_final,
        'prey_mean': prey_mean,
        'prey_std': prey_std
    }

    # Calculate regression to investigate relationship between uncertainties and final number of preys after one year, the mean value of preys, and the standard deviation of preys
    for indicator_key in indicators.keys():
        generate_regression_single(experiments["prey_birth_rate"],
                                   indicators[indicator_key])
        generate_regression_single(experiments["predation_rate"],
                                   indicators[indicator_key])
        generate_regression_single(experiments["predator_efficiency"],
                                   indicators[indicator_key])
        generate_regression_single(experiments["predator_loss_rate"],
                                   indicators[indicator_key])

    # Select uncertainties that were applied in every experiment
    # uncertainties_experiments = experiments[["prey_birth_rate", "predation_rate", "predator_efficiency", "predator_loss_rate"]]

    # generate_regression_single(experiments["prey_birth_rate"], prey_final)

    #generate_regression(uncertainties_experiments, prey_final)
    #generate_regression(uncertainties_experiments, prey_mean)
    #generate_regression(uncertainties_experiments, prey_std)

    #for outcome_key in outcomes_squeezed.keys():
    #   if outcome_key != 'TIME':
    # Fetch numpy array from dictionary, and calculate average over every single column (average at every point of time)
    # Plot using workbench
    #plotting.lines(experiments, outcomes_squeezed, outcomes_to_show=outcome_key, density=plotting_util.Density.HIST)

    return prey_final, prey_mean, prey_std
    #     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')
    df_unc['Min'] = df_unc['Reference'] * 0.5
    df_unc['Max'] = df_unc['Reference'] * 1.5

    vensimModel.uncertainties = [
        RealParameter(row['Uncertainties'], row['Min'], row['Max'])
        for index, row in df_unc.iterrows()
    ]

    #vensimModel.outcomes = [TimeSeriesOutcome(out) for out in df_out['Outcomes']]
    vensimModel.outcomes = [
        TimeSeriesOutcome('Total Agricultural and Land Use Emissions')
    ]

    sc = 0
    n = 2500
    vensimModel.constants = [Constant('SA Diet Composition Switch', sc)]
    with MultiprocessingEvaluator(vensimModel, n_processes=7) as evaluator:
        for sc in [0, 2, 3, 4]:
            start = time.time()
            results_sa = evaluator.perform_experiments(
                n, uncertainty_sampling=SOBOL, reporting_interval=5000)
            end = time.time()
            print("Experiments took {} seconds, {} hours.".format(
                end - start, (end - start) / 3600))

            fn = './Diet_Sobol_n{}_sc{}_v4_2050.tar.gz'.format(
def perform_EMA_sobol_experiment(model, N):

    model.uncertainties = [
        RealParameter('prey_birth_rate', 0.015, 0.035),
        RealParameter('predation_rate', 0.0005, 0.003),
        RealParameter('predator_efficiency', 0.001, 0.004),
        RealParameter('predator_loss_rate', 0.04, 0.08)
    ]

    # We assume that Sobol sampling automatically performs N * (2D+2) scenarios.
    # Therefore, we do not perform this calculation.
    # number_uncertainties = 4
    # total_scenarios = N * (2*number_uncertainties + 2)

    total_scenarios = N

    model.outcomes = [
        TimeSeriesOutcome('TIME', function=np.squeeze),
        TimeSeriesOutcome('predators', function=np.squeeze),
        TimeSeriesOutcome('prey', function=np.squeeze)
    ]

    #N * (2D+2) scenarios, where D is the number of uncertain parameters,
    #and N is the value for scenarios passed to perform_experiments

    experiments, outcomes = perform_experiments(model,
                                                scenarios=total_scenarios,
                                                uncertainty_sampling='sobol')

    # Store final values of prey outcome
    prey_final = []
    prey_mean = []
    prey_std = []

    # Iterate through rows of outcome numpy array (experiments) to calculate indicators
    for experiment_row in outcomes["prey"]:
        prey_final.append(experiment_row[-1])  # Get last element
        prey_mean.append(np.mean(experiment_row))
        prey_std.append(np.std(experiment_row))

    # Collect indicators in dictionary to calculate regression for each of them
    #indicators = {'prey_final':prey_final, 'prey_mean':prey_mean, 'prey_std':prey_std}

    # Convert outputs to numpy array
    prey_final_np = np.array(prey_final)
    prey_mean_np = np.array(prey_mean)
    prey_std_np = np.array(prey_std)

    # Create plots including subplots
    fig1 = plt.figure()
    fig1.tight_layout()
    fig1.set_size_inches(20, 10)

    ax1 = fig1.add_subplot(131)
    ax2 = fig1.add_subplot(132, sharey=ax1)
    ax3 = fig1.add_subplot(133, sharey=ax1)

    # Perform sobol analysis on experiment result using SALib for every output of interest
    perform_SALib_sobol(model, prey_final_np, "Final value of prey", ax1)
    perform_SALib_sobol(model, prey_mean_np, "Mean value of prey", ax2)
    perform_SALib_sobol(model, prey_std_np, "Standard deviation of prey", ax3)
def mun_subscripted_outcomes(working_directory, y):
    x = mun_subscripted_variables(working_directory, y)
    outcomes = []
    for m in x:
        outcomes.append(TimeSeriesOutcome(m))
    return outcomes