class documentation

compose an arbitrary number of functions.

A class instance is a list of functions. Calling the instance executes the composition of these functions (evaluating from right to left as in math notation). Functions can be added to or removed from the list at any time with the obvious effect. To remain consistent (if needed), the list_of_inverses attribute must be updated respectively.

>>> import numpy as np
>>> from cma.fitness_transformations import ComposedFunction
>>> f1, f2, f3, f4 = lambda x: 2*x, lambda x: x**2, lambda x: 3*x, lambda x: x**3
>>> f = ComposedFunction([f1, f2, f3, f4])
>>> assert isinstance(f, list) and isinstance(f, ComposedFunction)
>>> assert f[0] == f1  # how I love Python indexing
>>> assert all(f(x) == f1(f2(f3(f4(x)))) for x in np.random.rand(10))
>>> assert f4 == f.pop()
>>> assert len(f) == 3
>>> f.insert(1, f4)
>>> f.append(f4)
>>> assert all(f(x) == f1(f4(f2(f3(f4(x))))) for x in range(5))

A more specific example:

>>> from cma.fitness_transformations import ComposedFunction
>>> from cma.constraints_handler import BoundTransform
>>> from cma import ff
>>> f = ComposedFunction([ff.elli,
...                       BoundTransform([[0], [1]]).transform])
>>> assert max(f([2, 3]), f([1, 1])) <= ff.elli([1, 1])

Details:

  • This class can serve as basis for a more transparent alternative to a scaling_of_variables CMA option or for any necessary transformation of the fitness/objective function (genotype-phenotype transformation).
  • The parallelizing call with a list of solutions of the Function class is not inherited. The inheritence from Function is rather declarative than funtional and could be omitted.
Method __call__ Undocumented
Method __init__ Caveat: to remain consistent, the list_of_inverses must be updated explicitly, if the list of function was updated after initialization.
Method inverse evaluate the composition of inverses on x.
Instance Variable list_of_inverses Undocumented

Inherited from Function:

Method initialize initialization of Function
Instance Variable evaluations Undocumented
Instance Variable ftarget Undocumented
Instance Variable target_hit_at Undocumented
Property function_names_to_evaluate_first_found attributes which are searched for to be called if no function was given to __init__.
Class Variable _function_names_to_evaluate_first_found Undocumented
Instance Variable __callable Undocumented
Instance Variable __initialized Undocumented
def __call__(self, x, *args, **kwargs):
def __init__(self, list_of_functions, list_of_inverses=None):
def inverse(self, x, *args, **kwargs):

evaluate the composition of inverses on x.

Return None, if no list was provided.

list_of_inverses =

Undocumented