예제 #1
0
def performExperiments():

    ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.INFO)

    model = Model('SimulateER', function=simulate_ER)  # instantiate the model
    # specify uncertainties
    model.uncertainties = [RealParameter("p", 0.1, 1.0)]
    model.uncertainties = [RealParameter("f", 0.1, 0.9)]

    model.levers = [IntegerParameter("n", 10, 100)]

    # specify outcomes
    model.outcomes = [ScalarOutcome('cc')]

    model.constants = [Constant('replications', 10)]

    n_scenarios = 10
    n_policies = 10

    res = perform_experiments(model, n_scenarios, n_policies)

    experiments, outcomes = res
    data = experiments[['n', 'p', 'f']]
    data.to_csv('out.csv', index=False)
    return data
def _get_exploratory_results(mediator, context):
    # turn logging on
    ema_logging.log_to_stderr(ema_logging.INFO)

    # create a EMA Model Object
    ema_model = _build_executable_model(mediator, context)

    with MultiprocessingEvaluator(ema_model,
                                  n_processes=context.num_processes,
                                  maxtasksperchild=4) as evaluator:
        # run model using EMA
        results = evaluator.perform_experiments(context.num_experiments)

        return results
예제 #3
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)
    
import statsmodels.api as sm
from patsy.highlevel import dmatrices

from ema_workbench import (Model, RealParameter, TimeSeriesOutcome,
                           ScalarOutcome, perform_experiments, ema_logging,
                           SequentialEvaluator)
from ema_workbench.analysis import plotting, plotting_util
from ema_workbench.em_framework.evaluators import LHS, SOBOL, MORRIS

from ema_workbench.analysis import feature_scoring
from ema_workbench.analysis.scenario_discovery_util import RuleInductionType
from ema_workbench.em_framework.salib_samplers import get_SALib_problem
from SALib.analyze import sobol

from ema_workbench import ema_logging
ema_logging.log_to_stderr(ema_logging.INFO)


def pred_prey(prey_birth_rate=0.025,
              predation_rate=0.0015,
              predator_efficiency=0.002,
              predator_loss_rate=0.06,
              initial_prey=50,
              initial_predators=20,
              dt=0.25,
              final_time=365,
              reps=1):

    #Initial values
    predators = np.zeros((reps, int(final_time / dt) + 1))
    prey = np.zeros((reps, int(final_time / dt) + 1))
예제 #5
0
'''
Created on May 26, 2015

@author: jhkwakkel
'''
from __future__ import (print_function)

import matplotlib.pyplot as plt

import ema_workbench.analysis.cart as cart
from ema_workbench import ema_logging, load_results

ema_logging.log_to_stderr(level=ema_logging.INFO)


def classify(data):
    # get the output for deceased population
    result = data['deceased population region 1']

    # if deceased population is higher then 1.000.000 people,
    # classify as 1
    classes = result[:, -1] > 1000000

    return classes


# load data
fn = './data/1000 flu cases with policies.tar.gz'
results = load_results(fn)
experiments, results = results
예제 #6
0
'''
Created on May 26, 2015

@author: jhkwakkel
'''
import matplotlib.pyplot as plt

import ema_workbench.analysis.cart as cart
from ema_workbench import ema_logging, load_results

ema_logging.log_to_stderr(level=ema_logging.INFO)

default_flow = 2.178849944502783e7

# load data
fn = './data/5000 runs WCM.tar.gz'
results = load_results(fn)
x, outcomes = results

ooi = 'throughput Rotterdam'
outcome = outcomes[ooi] / default_flow
y = outcome < 1

cart_alg = cart.CART(x, y)
cart_alg.build_tree()

# print cart to std_out
print(cart_alg.stats_to_dataframe())
print(cart_alg.boxes_to_dataframe())

# visualize
예제 #7
0
    df_conversion_efficiencies = db_file.parse('ConversionEfficiencies')
    df_conversion_units = db_file.parse('ConversionUnits')
    df_demand = db_file.parse('Demand')
    df_locations = db_file.parse('Locations')
    df_max_converted = db_file.parse('MaxConverted')
    df_max_flow = db_file.parse('MaxFlow')
    df_network = db_file.parse('Network')
    df_storage_units = db_file.parse('StorageUnits')
    df_supply = db_file.parse('Supply')
    df_supply_units = db_file.parse('SupplyUnits')
    df_time_periods = db_file.parse('TimePeriods')

    #model = Model('simpleModel', function=optim_model)
    ###############################################################################
    #ema_logging.LOG_FORMAT = '[%(name)s/%(levelname)s/%(processName)s] %(message)s'
    ema_logging.log_to_stderr(ema_logging.DEBUG)

    ##############################################################################
    model = PyomoModel('simpleModel', wd='./data')  # instantiate the model
    ##############################################################################

    # specify uncertainties
    model.uncertainties = [
        CategoricalParameter('demand_index',
                             (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)),
        RealParameter('dev_rate_wind', 0.011,
                      0.033),  #0.022 is estimated base value
        RealParameter('dev_rate_solar', 0.025,
                      0.075),  #0.05 is estimated base value
        RealParameter("dev_rate_storage_elec", 0.025,
                      0.075),  #0.05 is estimated base value
예제 #8
0
'''
Created on 20 sep. 2011

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
'''
import numpy as np
import matplotlib.pyplot as plt

from ema_workbench import load_results, ema_logging

from ema_workbench.analysis.pairs_plotting import (pairs_lines, pairs_scatter,
                                                   pairs_density)

ema_logging.log_to_stderr(level=ema_logging.DEFAULT_LEVEL)

# load the data
fh = './data/1000 flu cases no policy.tar.gz'
experiments, outcomes = load_results(fh)

# transform the results to the required format
# that is, we want to know the max peak and the casualties at the end of the
# run
tr = {}

# get time and remove it from the dict
time = outcomes.pop('TIME')

for key, value in outcomes.items():
    if key == 'deceased population region 1':
        tr[key] = value[:, -1]  #we want the end value
    else:
예제 #9
0
"""


"""
from __future__ import unicode_literals, print_function, absolute_import, division


# 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 import PysdModel

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

    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)
예제 #10
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')
예제 #11
0
"""
Created on Fri Dec 09 14:59:03 2016

@author: Pedro
"""
from __future__ import (division, print_function, absolute_import, 
                        unicode_literals)

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

from ema_workbench.connectors.excel import ExcelModel


if __name__ == "__main__":    
    ema_logging.log_to_stderr(level=ema_logging.DEBUG)
    
    model = ExcelModel("excelModel", wd="./models",
                      model_file= '/excelModel.xlsx')
    model.uncertainties = [RealParameter("B2", 0.04, 0.2), #we can refer to a cell in the normal way
                           RealParameter("B3", 4000,6000), # we can also use named cells
                           RealParameter("B4", 0.9,1.1),
                           RealParameter("B5", 0.9,1.1)]
    
    #specification of the outcomes
    model.outcomes = [ScalarOutcome("B7")] # we can also use named range
    
    #name of the sheet
    model.sheet = "EMA"
    
    results = perform_experiments(model, 100, parallel=True, reporting_interval=1)
예제 #12
0
'''
Created on 20 sep. 2011

.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
'''
import numpy as np
import matplotlib.pyplot as plt

from ema_workbench import load_results, ema_logging

from ema_workbench.analysis.pairs_plotting import (pairs_lines, pairs_scatter, 
                                                   pairs_density)

ema_logging.log_to_stderr(level=ema_logging.DEFAULT_LEVEL)

# load the data
fh = './data/1000 flu cases no policy.tar.gz'
experiments, outcomes = load_results(fh)

# transform the results to the required format
# that is, we want to know the max peak and the casualties at the end of the 
# run
tr = {}

# get time and remove it from the dict
time = outcomes.pop('TIME')

for key, value in outcomes.items():
    if key == 'deceased population region 1':
        tr[key] = value[:,-1] #we want the end value
    else: