class documentation

dictionary with computation of an hash key.

The hash key is generated from the inserted solution and a stack of previously inserted same solutions is provided. Each entry is meant to store additional information related to the solution.

>>> import cma.utilities.utils as utils, numpy as np
>>> d = utils.SolutionDict()
>>> x = np.array([1,2,4])
>>> d[x] = {'f': sum(x**2), 'iteration': 1}
>>> assert d[x]['iteration'] == 1
>>> assert d.get(x) == (d[x] if d.key(x) in d.keys() else None)
>>> y = [1,2,4]
>>> d[y] = {'f': sum([n ** 2 for n in y]), 'iteration': 1}
>>> assert d[y]['iteration'] == 1
>>> assert d.get(y) == (d[y] if d.key(y) in d.keys() else None)
>>> d[2] = 3
>>> assert d[2] == 3

data_with_same_key behaves (in contrast to the order of keys()) like a stack (see setitem and delitem). Thereby the last assignment self[key] = ... determines, as to be expected, the value of self[key] even when self.data_with_same_key[key] is not empty.

CAVEAT: after a same-key item was removed, self[key] returns the previous value, however self._unhashed_keys[key] raises a ValueError as the unhashed entries for the remaining items with this key are not available as unhashed keys are not stacked.

TODO: iteration key is used to clean up without error management

Method __contains__ Undocumented
Method __delitem__ remove only most current key-entry of list with same keys
Method __getitem__ define access self[key]
Method __init__ Undocumented
Method __setitem__ define self[key] = value
Method key compute key of x
Method truncate truncate to max_len/2 when len(self) > max_len.
Method truncate_to truncate to length len_ removing the oldest entries
Instance Variable data_with_same_key Undocumented
Instance Variable last_iteration Undocumented
Instance Variable _unhashed_keys Undocumented

Inherited from DerivedDictBase:

Method __iter__ Undocumented
Method __len__ Undocumented
Instance Variable data Undocumented
def __contains__(self, key):
def __delitem__(self, key):

remove only most current key-entry of list with same keys

def __getitem__(self, key):

define access self[key]

def __init__(self, *args, **kwargs):
def __setitem__(self, key, value):

define self[key] = value

def key(self, x):

compute key of x

def truncate(self, max_len, min_iter=None):

truncate to max_len/2 when len(self) > max_len.

Only truncate entries with 'iteration' key smaller than min_iter if given.

This looks overdesigned given the dict is ordered and chunk deletion is not available. See also truncate_to.

def truncate_to(self, len_):

truncate to length len_ removing the oldest entries

data_with_same_key: dict =

Undocumented

last_iteration: int =
_unhashed_keys: dict =

Undocumented