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), RealParameter('initial immune fraction of the population of region 2',
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)
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), 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), RealParameter('recovery time region 1', 0.1, 0.75),
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)
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, epsilons=[ 0.1,
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)
from ema_workbench import (RealParameter, TimeSeriesOutcome, ema_logging, perform_experiments) from ema_workbench.connectors.vensim import VensimModel from ema_workbench.em_framework.evaluators import MultiprocessingEvaluator 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),
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
# 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(
absolute_import) from ema_workbench import (RealParameter, TimeSeriesOutcome, ema_logging, perform_experiments) from ema_workbench.connectors.vensim import VensimModel from ema_workbench.em_framework.evaluators import MultiprocessingEvaluator 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),
.. 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), RealParameter("recovery time region 1", 0.1, 0.75), RealParameter("recovery time region 2", 0.1, 0.75), RealParameter("susceptible to immune population delay time region 1", 0.5, 2),