def plot_all_lines(results, outcomes, grouped, save, title): if grouped == True: for kpi in list(outcomes.keys())[1:]: # drop first entry (TIME) fig, axes = lines(results, density=u'kde', show_envelope=False, outcomes_to_show=kpi, group_by='policy') if save == True: plt.savefig('plots/scenario_policies/' + time.strftime('%Y%m%d') + title + '_lines_grouped_' + kpi + '.png', dpi=1200) else: print(kpi + ' was not saved') else: for kpi in list(outcomes.keys())[1:]: # drop first entry (TIME) fig, axes = lines(results, density=u'kde', show_envelope=False, outcomes_to_show=kpi) if save == True: plt.savefig('plots/scenario_policies/' + time.strftime('%Y%m%d') + title + '_lines_' + kpi + '.png', dpi=1200) else: print(kpi + ' was not saved')
def plot_individual_policies_lines(experiments, outcomes, policy, outcomes_to_show): '''Plot individual policy experiment sets''' sliced_result = slice_results(experiments, outcomes, policy) fig = lines(sliced_result, outcomes_to_show=outcomes_to_show, density=KDE) print('Plot of policy: ', policy)
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() if __name__ == "__main__": ema_logging.log_to_stderr(ema_logging.INFO) model = Burnout(r'./models/burnout', "burnout") # run policy with old cases results = perform_experiments(model, 100) lines(results, 'Energy Level', density=BOXPLOT) plt.show()
RealParameter("x22", 0.0001, 0.1), RealParameter("x31", 0, 0.5), 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, nr_experiments, parallel=True) 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()
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, titles=None, experiments_to_show=np.arange(0, nr_experiments, 10)) plt.show()
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) import matplotlib.pyplot as plt from ema_workbench.analysis.plotting import lines figure = lines(results, density=True) #show lines, and end state density plt.show() #show figure
from ema_workbench import load_results from ema_workbench.analysis import clusterer, plotting, Density experiments, outcomes = load_results('./data/1000 flu cases no policy.tar.gz') data = outcomes['infected fraction R1'] # calcuate distances distances = clusterer.calculate_cid(data) # plot dedrog clusterer.plot_dendrogram(distances) # do agglomerative clustering on the distances clusters = clusterer.apply_agglomerative_clustering(distances, n_clusters=5) # show the clusters in the output space x = experiments.copy() x['clusters'] = clusters.astype('object') plotting.lines(x, outcomes, group_by='clusters', density=Density.BOXPLOT) # show the input space sns.pairplot(x, hue='clusters', vars=['infection ratio region 1', 'root contact rate region 1', 'normal contact rate region 1', 'recovery time region 1', 'permanent immune population fraction R1'], plot_kws=dict(s=7)) plt.show()
ooi_name = "sheep" outcome = outcomes[ooi_name] outcome = outcome/default_flow ooi = np.zeros(outcome.shape[0]) temp_outcomes = {ooi_name: ooi} print ooi.shape desired__nr_lines = 5 nr_cases = ooi.shape[0] indices = np.arange(0, nr_cases, nr_cases/desired__nr_lines) lines(results, outcomes_to_show = 'sheep', density=KDE, show_envelope=True, experiments_to_show=indices) #n = key #plt.savefig("./pictures/adopter_category_bounded_no.png".format(key), dpi=75) plt.show() print(outcome) #print(results)
Outcome('grass', time=True) # TODO patches not working in reporting ] if __name__ == "__main__": import multiprocessing ema_logging.LOG_FORMAT = multiprocessing.util.DEFAULT_LOGGING_FORMAT #turn on logging ema_logging.log_to_stderr(ema_logging.DEBUG) ema_logging.info('in main') #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 ensemble.processes = 2 #perform experiments results = ensemble.perform_experiments(10, reporting_interval=1) plotting.lines(results, density=plotting_util.KDE) plt.show()
import numpy as np from ema_workbench import ema_logging, load_results from ema_workbench.analysis.plotting import lines from ema_workbench.analysis.plotting_util import KDE ema_logging.log_to_stderr(ema_logging.INFO) file_name = r'./data/1000 flu cases with policies.tar.gz' experiments, outcomes = load_results(file_name) # let's specify a few scenarios that we want to show for # each of the policies scenario_ids = np.arange(0, 1000, 100) experiments_to_show = experiments['scenario'].isin(scenario_ids) # the plotting functions return the figure and a dict of axes fig, axes = lines(experiments, outcomes, group_by='policy', density=KDE, show_envelope=True, experiments_to_show=experiments_to_show) # we can access each of the axes and make changes for key, value in axes.items(): # the key is the name of the outcome for the normal plot # and the name plus '_density' for the endstate distribution if key.endswith('_density'): value.set_xscale('log') plt.show()
''' Created on Jul 8, 2014 @author: [email protected] ''' import matplotlib.pyplot as plt from ema_workbench import ema_logging, load_results from ema_workbench.analysis.plotting import lines from ema_workbench.analysis.plotting_util import VIOLIN ema_logging.log_to_stderr(ema_logging.INFO) file_name = r'./data/1000 flu cases no policy.tar.gz' experiments, outcomes = load_results(file_name) # the plotting functions return the figure and a dict of axes fig, axes = lines(experiments, outcomes, density=VIOLIN) # we can access each of the axes and make changes for key, value in axes.items(): # the key is the name of the outcome for the normal plot # and the name plus '_density' for the endstate distribution if key.endswith('_density'): value.set_xscale('log') plt.show()
from ema_workbench import load_results from ema_workbench.analysis import clusterer, plotting, Density experiments, outcomes = load_results('./data/1000 flu cases no policy.tar.gz') data = outcomes['infected fraction R1'] # calcuate distances distances = clusterer.calculate_cid(data) # plot dedrog clusterer.plot_dendrogram(distances) # do agglomerative clustering on the distances clusters = clusterer.apply_agglomerative_clustering(distances, n_clusters=5) # show the clusters in the output space x = experiments.copy() x['clusters'] = clusters.astype('object') plotting.lines(x, outcomes, group_by='clusters', density=Density.BOXPLOT) # show the input space sns.pairplot(x, hue='clusters', vars=[ 'infection ratio region 1', 'root contact rate region 1', 'normal contact rate region 1', 'recovery time region 1', 'permanent immune population fraction R1' ], plot_kws=dict(s=7)) plt.show()