ema workbench

Table Of Contents

Other Sub Sites

Graphs

this module provides functions for generating some basic figures. The code can be used as is, or serve as an example for writing your own code. These plots rely on matplotlib, numpy, and scipy.stats.kde

lines()

graphs.lines(results, outcomes=[], column=None, categories=None, ylabels={}, density=False, legend=True, discretesize=<function __discretesize at 0x0979AA30>, **kwargs)

This function takes the results from perform_experiments() and visualizes these as line plots. It is thus to be used in case of time series data. The function will try to find a result labeled “TIME”. If this is present, these values will be used on the X-axis. In case of Vensim models, TIME is present by default.

param results:return from perform_experiments().
param outcomes:list of outcome of interest you want to plot. If empty, all outcomes are plotted. Note: just names.
param column:name of the column in the cases array to group results by.
param categories:
 set of categories to be used as a basis for grouping by. Categories is only meaningful if column is provided as well.
param ylabels:ylabels is a dictionary with the outcome names as keys, the specified values will be used as labels for the y axis.
param density:boolean, if true, the density of the endstates will be plotted.
param legend:boolean, if true, and there is a column specified for grouping, show a legend.
param discretesize:
 function to be used to turn a continuous column into intervals in order to use for grouping by.
rtype:a figure instance

Additional key word arguments will be passed along to the density function, if density is True.

property description
hist use a histogram instead of a GKDE
log log the resulting histogram or GKDE

an example of use

>>> import expWorkbench.util as util
>>> data = util.load_results(r'1000 flu cases.cPickle')
>>> lines(data, density=True, hist=True)

will show lines for all the outcomes of interest, and also shows histograms for the endstate densities.

[source code, hires.png, pdf]

../_images/basicLines.png

while

>>> lines(data, column='fatality ratio region 1', density=False)

will group the result by the ‘fatality ratio region 1’, this uncertainty is grouped into five intervals generated by the default discretesize function.

[source code, hires.png, pdf]

../_images/basicLines2.png

the legend at the top shows the intervals used. Through the categorize keyword argument, or through providing a different discretesize function, alternative intervals can be specified.

Note

the current implementation is limited to seven different categories in case of column, categories, and/or discretesize. This limit is due to the colors specified in COLOR_LIST.

envelopes()

graphs.envelopes(results, outcomes=[], column=None, categories=None, ylabels={}, fill=False, density=True, legend=True, discretesize=<function __discretesize at 0x0979AA30>, **kwargs)

Make envelop plots. An envelope shows over time the minimum and maximum value for a set of runs over time. It is thus to be used in case of time series data. The function will try to find a result labeled “TIME”. If this is present, these values will be used on the X-axis. In case of Vensim models, TIME is present by default.

Parameters:
  • results – return from perform_experiments().
  • outcomes – list of outcome of interest you want to plot. If empty, all outcomes are plotted. Note: just names.
  • column – name of the column in the cases array to group results by.
  • categories – set of categories to be used as a basis for grouping by. Categories is only meaningful if column is provided as well.
  • ylabels – ylabels is a dictionary with the outcome names as keys, the specified values will be used as labels for the y axis.
  • fill – boolean, if true, fill the envelope.
  • density – boolean, if true, the density of the endstates will be plotted.
  • legend – boolean, if true, and there is a column specified for grouping, show a legend.
  • discretesize – function to be used to turn a continuous column into intervals in order to use for grouping by.
Return type:

a figure instance

Additional key word arguments will be passed along to the density function, if density is True.

property description
hist use a histogram instead of a GKDE
log log the resulting histogram or GKDE

an example of use

>>> import expWorkbench.util as util
>>> data = util.load_results(r'1000 flu cases.cPickle')
>>> envelopes(data, column='policy')

will show an envelope for three three different policies, for all the outcomes of interest.

[source code, hires.png, pdf]

../_images/basicEnvelope.png

while

>>> envelopes(data, column='policy', categories=['static policy', 'adaptive policy'])

will only show results for the two specified policies, ignoring any results associated with ‘no policy’.

[source code, hires.png, pdf]

../_images/basicEnvelope2.png

Note

the current implementation is limited to seven different categories in case of column, categories, and/or discretesize. This limit is due to the colors specified in COLOR_LIST.

multiplot_scatter()

graphs.multiplot_scatter(results, outcomes=[], column=None, categories=None, ylabels={}, legend=False, discretesize=<function __discretesize at 0x0979AA30>)

Generate a R style pairs scatter multiplot. In case of time-series data, the end states are used.

param input:return from perform_experiments.
param outcomes:list of outcome of interest you want to plot. If empty, all outcomes are plotted note: just names.
param column:name of the column in the cases array to group results by
param categories:
 set of categories to be used as a basis for grouping by. Categories is only meaningful if column is provided as well.
param ylabels:ylabels is a dictionary with the outcome names as keys, the specified values will be used as labels for the y axis.
param legend:boolean, if true, and there is a column specified for grouping, show a legend.
param discretesize:
 function to be used to turn a continuous column into intervals in order to use for grouping by.
rtype:a figure instance.

an example of use

>>> import expWorkbench.util as util
>>> data = util.load_results(r'1000 flu cases.cPickle')
>>> multiplot_scatter(data, column='policy', legend=True)

generates

[source code, hires.png, pdf]

../_images/basicMultiplotScatter.png

Note

the current implementation is limited to seven different categories in case of column, categories, and/or discretesize. This limit is due to the colors specified in COLOR_LIST.

multiplot_lines()

graphs.multiplot_lines(results, outcomes=[], column=None, categories=None, ylabels={}, legend=False, discretesize=<function __discretesize at 0x0979AA30>)

Generate a R style pairs lines multiplot. It shows the behavior of two outcomes over time against each other. The origin is denoted with a cicle and the end is denoted with a ‘+’.

Parameters:
  • input – return from perform_experiments.
  • outcomes – list of outcome of interest you want to plot. If empty, all outcomes are plotted note: just names.
  • column – name of the column in the cases array to group results by
  • categories – set of categories to be used as a basis for grouping by. Categories is only meaningful if column is provided as well.
  • ylabels – ylabels is a dictionary with the outcome names as keys, the specified values will be used as labels for the y axis.
  • legend – boolean, if true, and there is a column specified for grouping, show a legend.
  • discretesize – function to be used to turn a continuous column into intervals in order to use for grouping by.
Return type:

a figure instance.

an example of use

[source code, hires.png, pdf]

../_images/basicMultiplotLines.png

multiplot_density()

graphs.multiplot_density(results, outcomes=[], ylabels={}, log=True, gridsize=50, cmap=<matplotlib.colors.LinearSegmentedColormap instance at 0x0471E1C0>)

Generate a R style pairs hexbin density multiplot. In case of time-series data, the end states are used.

hexbin makes hexagonal binning plot of x versus y, where x, y are 1-D sequences of the same length, N. If C is None (the default), this is a histogram of the number of occurences of the observations at (x[i],y[i]). For further detail see matplotlib on hexbin

Parameters:
  • input – return from perform_experiments.
  • outcomes – list of outcome of interest you want to plot. If empty, all outcomes are plotted note: just names.
  • ylabels – ylabels is a dictionary with the outcome names as keys, the specified values will be used as labels for the y axis.
  • log – If True, the log of the value for each bin is taken prior to determining the color. (Default=True)
  • gridsize – The number of hexagons in the x-direction. The corresponding number of hexagons in the y-direction is chosen such that the hexagons are approximately regular. Alternatively, gridsize can be a tuple with two elements specifying the number of hexagons in the x-direction and the y-direction. (Default is 50)
  • cmap – color map that is to be used in generating the hexbin. For details on the available maps, see pylab. (Defaults = jet)
Return type:

a figure instance.

an example of use

[source code, hires.png, pdf]

../_images/basicMultiplotDensity.png

helper functions

__density()

graphs.__density(j, axDensity, ax, data, hist=False, log=False)

Helper function responsible for plotting the density part.

Parameters:
  • j – index of set of runs being plotted.
  • axDensity – the axes for plotting the density on.
  • ax – the axes in which the actual data is being plotted.
  • data – the data to be used for plotting the KDE or the histogram.
  • hist – boolean, if true, use histograms, otherwise use gaussian Kernel Densitiy Estimate.
  • log – boolean, if true log the results from histogram or kde

__discretesize()

graphs.__discretesize(array)

Helper function for discretesizing a continous array. By default, the array is split into 5 equally wide intervals.

Parameters:array – a 1-d array that is to be turned into discrete intervals.
Returns:list of tuples with the lower and upper bound of the intervals.