ema workbench

Table Of Contents

Other Sub Sites

util

Created on 13 jan. 2011

Code author: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>

This module provides various convenience functions and classes.

util.save_results(results, file)

save the results to the specified cPickle file. To facilitate transfer across different machines. the files are saved in binary format

see also: http://projects.scipy.org/numpy/ticket/1284

Parameters:
  • results – the return of run_experiments
  • file – the path of the file
Raises :

IOError if file not found

util.load_results(file)

load the specified cPickle file. the file is assumed to be saves using save_results.

Parameters:file – the path of the file
Returns:the unpickled results
Raises :IOError if file not found
util.experiments_to_cases(experiments)

This function transform a structured experiments array into a list of case dicts. This can then for example be used as an argument for running perform_experiments().

Parameters:experiments – a structured array containing experiments
Returns:a list of case dicts.
util.merge_results(results1, results2, downsample=None)

convenience function for merging the return from perform_experiments().

The function merges results2 with results1. For the experiments, it generates an empty array equal to the size of the sum of the experiments. As dtype is uses the dtype from the experiments in results1. The function assumes that the ordering of dtypes and names is identical in both results.

A typical use case for this function is in combination with experiments_to_cases(). Using experiments_to_cases() one extracts the cases from a first set of experiments. One then performs these cases on a different model or policy, and then one wants to merge these new results with the old result for further analysis.

Parameters:
  • results1 – first results to be merged
  • results2 – second results to be merged
  • downsample – should be an integer, will be used in slicing the results in order to avoid memory problems.
Returns:

the merged results

AbstractCallback

class util.AbstractCallback(uncertainties, outcomes, nrOfExperiments)

Base class from which different call back classes can be derived. Callback is responisble for storing the results of the runs.

callback(case, policy, name, result)

Method responsible for storing results. The implementation in this class only keeps track of how many runs have been completed and logging this.

Parameters:
  • case – the case to be stored
  • policy – the name of the policy being used
  • name – the name of the model being used
  • result – the result dict

DefaultCallback

class util.DefaultCallback(uncs, outcomes, nrOfExperiments)

default callback system callback can be used in performExperiments as a means for specifying the way in which the results should be handled. If no callback is specified, this default implementation is used. This one can be overwritten or replaced with a callback of your own design. For example if you prefer to store the result in a database or write them to a text file

callback(case, policy, name, result)

Method responsible for storing results. This method calls super() first, thus utilizing the logging provided there

Parameters:
  • case – the case to be stored
  • policy – the name of the policy being used
  • name – the name of the model being used
  • result – the result dict. This implementation assumes that the values in this dict are numpy array instances. Two types of instances are excepted: single values and 1-D arrays.
Returns:

a tuple with the cases structured array and the dict of result arrays.