class documentation

class Results(object):

Constructor: Results(name, values_to_string, verbose)

View In Hierarchy

a container to communicate (changing) results via disk.

The data attribute is a dictionary (DataDict) which contains all observed data, usually a list for each key. Any new container reads previously saved data (with the same name) on initialization.

Before the data are saved, the old data are backupped under the current timestamp.

Use case example:

import cma.experimentation

# create or load 'sweep_data' results
res = cma.experimentation.Results('sweep_data')

# save data after each trial
for dim in dimensions:
    res.backup()  # in case we want fewer backups
    for ...:
        x, es = cma.fmin2(...)
        res.data[dim] += [es.result.evaluations if 'ftarget' in es.result.stop()
                          else np.inf]
        res.save(backup=False)  # like this we can never lose data

Details: Saving/loading of nonfinite values with ast.literat_eval is covered with the values_to_string parameters.

Some methods handle nested dictionaries, however it seems to be safer to use tuples as keys in a flat dictionary or use different Results instances, e.g. by dimension and/or popsize, like:

res = experimentation.Results('sweep_c_dim={}lam={}.format(dimension, popsize)

In particular .data.clean() for float keys does (currently) not work with key tuples.

Method __getattr__ access Results.data directly from Results
Method __init__ Undocumented
Method backup backup saved data by making a file copy
Method load load data from file, discard current data, see also update
Method save save self.data to disk
Method update Append data from filename to self.data.
Instance Variable backup_dirname Undocumented
Instance Variable data Undocumented
Instance Variable filename Undocumented
Instance Variable last_backup Undocumented
Instance Variable meta_data Undocumented
Method _arrays return a flat list of (references to) all non-dicts in data.
Method _backup0 append data to backup file, no easy to read back
Method _load_json return dictionary from load json file with keys to int or float, if possible
Method _value_to_string return "correct" value, doesn't work for nan
Method _values_to_string replace certain values in lists with strings or vice versa.
Instance Variable _extension Undocumented
Instance Variable _values_to_string_vals Undocumented
def __getattr__(self, name):

access Results.data directly from Results

def __init__(self, name=None, values_to_string=(np.inf, np.nan, math.nan), verbose=1):

Undocumented

def backup(self):

backup saved data by making a file copy

def load(self):

load data from file, discard current data, see also update

def save(self, backup=True):

save self.data to disk

def update(self, filename, backup=True):

Append data from filename to self.data.

To update self with a data dict instead a file, call self.data.update(data).

Details: assumes a flat dict structure.

backup_dirname =

Undocumented

data =

Undocumented

filename =

Undocumented

last_backup =

Undocumented

meta_data =

Undocumented

def _arrays(self, data=None):

return a flat list of (references to) all non-dicts in data.

Traverses recursively down into dictionaries.

def _backup0(self, data=None):

append data to backup file, no easy to read back

def _load_json(self):

return dictionary from load json file with keys to int or float, if possible

def _value_to_string(self, val, inverse=False):

return "correct" value, doesn't work for nan

def _values_to_string(self, inverse=False):

replace certain values in lists with strings or vice versa.

Values to be replaced are defined at instance creation in _values_to_string_vals.

Details: this prevents ast.literal_eval to bail on, for example, repr([1, 3, 'inf']), as 'inf' is just a string and will not be evaluated.

_extension =

Undocumented

_values_to_string_vals =

Undocumented