Пример #1
0
# population that is ill at any given point in time
deaths = outcomes['deceased population region 1'][:, -1]
peak = np.max(outcomes['infected fraction R1'], axis=1)

deaths = [(deaths[i], i) for i in range(deaths.shape[0])]
deaths = sorted(deaths, reverse=True)
death_indices = [death[1] for death in deaths]

peak = [(peak[i], i) for i in range(peak.shape[0])]
peak = sorted(peak, reverse=True)
peak_indices = [element[1] for element in peak]

# combine the top 20 of both
indices = death_indices[0:20]
[indices.append(entry) for entry in peak_indices[0:20]]

# how much can we nest....
# we first do the set to remove duplicates, next we cast it to a list
# so we can sort it. The sorting might be superfluous.
indices = sorted(list(set(indices)))
indices = np.asarray(indices)

#lets modify the default time label
plotting.TIME_LABEL = "Time (months)"

# visualize the results on top of an envelope
# do not show titles for the axes
lines(results, experiments_to_show=indices, show_envelope=True, titles=None)

plt.savefig("./pictures/advanced_lines.png", dpi=75)
Пример #2
0
'''
Created on 26 sep. 2011

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

from expWorkbench import load_results
from analysis.plotting import lines

data = load_results(r'../../../src/analysis/1000 flu cases.cPickle')
fig = lines(data, group_by='fatality ratio region 1')
plt.show()
Пример #3
0
death_indices = [death[1] for death in deaths]

peak = [(peak [i], i) for i in range(peak.shape[0])]
peak = sorted(peak, reverse=True)
peak_indices = [element[1] for element in peak]

# combine the top 20 of both
indices = death_indices[0:20]
[indices.append(entry) for entry in peak_indices[0:20]]

# how much can we nest....
# we first do the set to remove duplicates, next we cast it to a list
# so we can sort it. The sorting might be superfluous. 
indices = sorted(list(set(indices)))
indices = np.asarray(indices)

#lets modify the default time label
plotting.TIME_LABEL = "Time (months)"

# visualize the results on top of an envelope
# do not show titles for the axes
lines(results, 
      experiments_to_show=indices, 
      show_envelope=True,
      titles=None)

plt.savefig("./pictures/advanced_lines.png", dpi=75)



Пример #4
0
        susceptible_population_region_1 = susceptible_population_region_1_NEXT
        susceptible_population_region_2 = susceptible_population_region_2_NEXT
    
        immune_population_region_1 = immune_population_region_1_NEXT
        immune_population_region_2 = immune_population_region_2_NEXT
    
        deceased_population_region_1.append(deceased_population_region_1_NEXT)
        deceased_population_region_2.append(deceased_population_region_2_NEXT)
        
        #End of main code
    return (runTime, deceased_population_region_1) #, Max_infected, Max_time)

        
if __name__ == "__main__":
    import expWorkbench.ema_logging as logging
    np.random.seed(150) #set the seed for replication purposes
    logging.log_to_stderr(logging.INFO)
    
    fluModel = MexicanFlu(None, "mexicanFluExample")
    ensemble = ModelEnsemble()
    ensemble.parallel = True
    ensemble.set_model_structure(fluModel)
    
    nr_experiments = 500
    results = ensemble.perform_experiments(nr_experiments, reporting_interval=100)

    lines(results, outcomes_to_show="deceased_population_region_1", 
          show_envelope=True, density=KDE, titles=None, 
          experiments_to_show=np.arange(0, nr_experiments, 10)
          )
    plt.show()
Пример #5
0
'''
Created on 26 sep. 2011

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

from expWorkbench import load_results
from analysis.plotting import lines, KDE

data = load_results(r'../../../src/analysis/1000 flu cases.cPickle', zipped=False)
fig = lines(data, density=KDE, hist=True)
plt.show()
new_outcomes['avg. price'] = outcomes['avg price']
new_outcomes['fraction non-fossil'] = new_outcomes['total non-fossil'] / new_outcomes['total generation'] 

# create the time dimension including 2006 as a starting year
time = np.arange(0, new_outcomes['avg. price'].shape[1])+2006
time = np.tile(time, (new_outcomes['avg. price'].shape[0],1))
new_outcomes["TIME"] = time

results = (experiments, new_outcomes)

# create a lines plot on top of an envelope
fig, axes_dict = lines(results,
                       density='kde',
                       outcomes_to_show=['total capacity',
                                         'total generation',
                                         'avg. price',
                                         'fraction non-fossil'],
                       show_envelope=True,
                       experiments_to_show=np.random.randint(0, new_outcomes['avg. price'].shape[0], (5,)),
                       titles=None,
                       )

# use the returned axes dict to modify the ylim on one of the outcomes
axes_dict['fraction non-fossil'].set_ylim(ymin=0, ymax=1)
axes_dict['fraction non-fossil_density'].set_ylim(ymin=0, ymax=1)

# transform the figure to black and white
set_fig_to_bw(fig)

plt.savefig("./pictures/jotke_envelopes.png", dpi=75)

Пример #7
0
    outcomes = [
        Outcome('sheep', time=True),
        Outcome('wolves', time=True),
        Outcome('grass', time=True)  # TODO patches not working in reporting
    ]


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

    #instantiate a model
    fh = r"./models/predatorPreyNetlogo"
    model = PredatorPrey(fh, "simpleModel")

    #instantiate an ensemble
    ensemble = ModelEnsemble()

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

    #run in parallel, if not set, FALSE is assumed
    ensemble.parallel = True

    #perform experiments
    results = ensemble.perform_experiments(100, reporting_interval=1)

    plotting.lines(results, density=plotting_util.KDE)
    plt.show()
Пример #8
0
        susceptible_population_region_2 = susceptible_population_region_2_NEXT
    
        immune_population_region_1 = immune_population_region_1_NEXT
        immune_population_region_2 = immune_population_region_2_NEXT
    
        deceased_population_region_1.append(deceased_population_region_1_NEXT)
        deceased_population_region_2.append(deceased_population_region_2_NEXT)
        
        #End of main code
    return (runTime, deceased_population_region_1) #, Max_infected, Max_time)

        
if __name__ == "__main__":
   
    np.random.seed(150) #set the seed for replication purposes
    
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    fluModel = MexicanFlu(None, "mexicanFluExample")
    ensemble = ModelEnsemble()
    ensemble.parallel = True
    ensemble.model_structure = fluModel
    
    nr_experiments = 500
    results = ensemble.perform_experiments(nr_experiments, reporting_interval=100)

    lines(results, outcomes_to_show="deceased_population_region_1", 
          show_envelope=True, density=KDE, titles=None, 
          experiments_to_show=np.arange(0, nr_experiments, 10)
          )
    plt.show()
Пример #9
0
#load the data
experiments, outcomes = load_results(r'Data/200 runs.bz2')

results = (experiments, outcomes)

'''==============================================================================
 print out the lines, envelope and KDE
=============================================================================='''
desired__nr_lines = 200
nr_cases = experiments.shape[0]
indices = np.arange(0, nr_cases, nr_cases/desired__nr_lines)

#for key in ['repayment months']:
for key, value in outcomes.items():
    fig, axes = lines(results, outcomes_to_show=key, density=KDE,
              show_envelope=True, experiments_to_show=indices, 
              titles="")
# plt.show()
# 
    n = key
    plt.savefig("./pictures/KDE_200_{}.png".format(n), dpi=75)
'''==============================================================================
to print for only selected outomes and group by model:
=============================================================================='''
#for key in ['total revenue Yearly']:
#    fig, axes = envelopes(results, outcomes_to_show=key, density=KDE,
#            group_by='model', titles="",fill=True)



Пример #10
0
# create the time dimension including 2006 as a starting year
time = np.arange(0, new_outcomes['avg. price'].shape[1]) + 2006
time = np.tile(time, (new_outcomes['avg. price'].shape[0], 1))
new_outcomes["TIME"] = time

results = (experiments, new_outcomes)

# create a lines plot on top of an envelope
fig, axes_dict = lines(
    results,
    density='kde',
    outcomes_to_show=[
        'total capacity', 'total generation', 'avg. price',
        'fraction non-fossil'
    ],
    show_envelope=True,
    experiments_to_show=np.random.randint(0,
                                          new_outcomes['avg. price'].shape[0],
                                          (5, )),
    titles=None,
)

# use the returned axes dict to modify the ylim on one of the outcomes
axes_dict['fraction non-fossil'].set_ylim(ymin=0, ymax=1)
axes_dict['fraction non-fossil_density'].set_ylim(ymin=0, ymax=1)

# transform the figure to black and white
set_fig_to_bw(fig)

plt.savefig("./pictures/jotke_envelopes.png", dpi=75)
Пример #11
0
    
    #specification of the outcomes
    outcomes = [Outcome("B4:B1076", time=True),  #we can refer to a range in the normal way
                Outcome("P_t", time=True)] # we can also use named range
    
    #name of the sheet
    sheet = "Sheet1"
    
    #relative path to the Excel file
    workbook = r'\excel example.xlsx'
    

if __name__ == "__main__":    
    logger = ema_logging.log_to_stderr(level=ema_logging.INFO)
    
    model = ExcelModel(r"..\..\models\excelModel", "predatorPrey")
    
    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model) 

    ensemble.parallel = True #turn on parallel computing
    ensemble.processes = 2 #using only 2 cores 
    
    #generate 100 cases
    results = ensemble.perform_experiments(10) 
    
    lines(results)
    plt.show()
    
    #save results
#    save_results(results, r'..\..\excel runs.cPickle')
Пример #12
0
                                                "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()                   

        
if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = Burnout(r'./models/burnout', "burnout")

    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model)
    
    #run policy with old cases
    results = ensemble.perform_experiments(100)
    lines(results, 'Energy Level', density=BOXPLOT)
    plt.show()

    
                [(-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()


if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = Burnout(r"./models/burnout", "burnout")

    ensemble = ModelEnsemble()
    ensemble.model_structure = model

    # run policy with old cases
    results = ensemble.perform_experiments(100)
    lines(results, "Energy Level", density=BOXPLOT)
    plt.show()
=============================================================================='''


#for key in ['repayment months']:
for key, value in outcomes.items():
    ooi_name = 'percentage_of_early_majority_with_ISG_appliances'
    ooi = outcomes[ooi_name]
    ooi = np.reshape(ooi, (ooi.shape[0]*ooi.shape[1], ooi.shape[2]))
    temp_outcomes = {ooi_name: ooi}

desired__nr_lines = 200
nr_cases = experiments.shape[0]
indices = np.arange(0, nr_cases, nr_cases/desired__nr_lines)   
    
lines((ooi, temp_outcomes), density=KDE,
            show_envelope=True, experiments_to_show=indices, 
            titles="")

plt.show()

#     n = key
#     plt.savefig("./pictures/KDE_200_{}.png".format(n), dpi=75)
'''==============================================================================
to print for only selected outomes and group by model:
=============================================================================='''
#for key in ['total revenue Yearly']:
#    fig, axes = envelopes(results, outcomes_to_show=key, density=KDE,
#            group_by='model', titles="",fill=True)


Пример #15
0
    ]

    outcomes = [
        Outcome("sheep", time=True),
        Outcome("wolves", time=True),
        Outcome("grass", time=True),  # TODO patches not working in reporting
    ]


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

    # instantiate a model
    vensimModel = PredatorPrey(r"..\..\models\predatorPreyNetlogo", "simpleModel")

    # instantiate an ensemble
    ensemble = ModelEnsemble()

    # set the model on the ensemble
    ensemble.set_model_structure(vensimModel)

    # run in parallel, if not set, FALSE is assumed
    ensemble.parallel = True

    # perform experiments
    results = ensemble.perform_experiments(100)

    plotting.lines(results, density=plotting.KDE)
    plt.show()
Пример #16
0
'''
Created on 26 sep. 2011

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

from expWorkbench import load_results
from analysis.plotting import lines

data = load_results(r'../../../src/analysis/1000 flu cases.cPickle')
fig = lines(data, group_by='fatality ratio region 1')
plt.show()
Пример #17
0
                "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()


if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = Burnout(r'./models/burnout', "burnout")

    ensemble = ModelEnsemble()
    ensemble.model_structure = model

    #run policy with old cases
    results = ensemble.perform_experiments(100)
    lines(results, 'Energy Level', density=BOXPLOT)
    plt.show()
Пример #18
0
'''
Created on 26 sep. 2011

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

from expWorkbench import load_results
from analysis.plotting import lines, KDE

data = load_results(r'../../../src/analysis/1000 flu cases.cPickle',
                    zipped=False)
fig = lines(data, density=KDE, hist=True)
plt.show()