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

TODO: data_with_same_key behaves like a stack (see setitem and delitem), but rather should behave like a queue?! A queue is less consistent with the operation self[key] = ..., if self.data_with_same_key[key] is not empty.

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.
Instance Variable data_with_same_key Undocumented
Instance Variable last_iteration 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.

data_with_same_key: dict =

Undocumented

last_iteration: int =