class documentation

class FixVariables(ComposedFunction):

View In Hierarchy

Insert variables with given values, thereby reducing the dimensionality of the resulting composed function.

The constructor takes index_value_pairs, a dict or list of pairs, as input and returns a function with smaller preimage space than input function f.

Fixing variable 3 and 5 works like

>>> from cma.fitness_transformations import FixVariables
>>> index_value_pairs = [[2, 0.2], [4, 0.4]]
>>> fun = FixVariables(cma.ff.elli, index_value_pairs)
>>> fun[1](4 * [1]) == [ 1.,  1.,  0.2,  1.,  0.4, 1.]
True

Or starting from a given current solution in the larger space from which we pick the fixed values:

>>> from cma.fitness_transformations import FixVariables
>>> current_solution = [0.1 * i for i in range(5)]
>>> fixed_indices = [2, 4]
>>> index_value_pairs = [[i, current_solution[i]]  # fix these
...                                     for i in fixed_indices]
>>> fun = FixVariables(cma.ff.elli, index_value_pairs)
>>> fun[1](4 * [1]) == [ 1.,  1.,  0.2,  1.,  0.4, 1.]
True
>>> assert (current_solution ==  # list with same values
...            fun.transform(fun.insert_variables(current_solution)))
>>> assert (current_solution ==  # list with same values
...            fun.insert_variables(fun.transform(current_solution)))

Details: this might replace the fixed_variables option in CMAOptions in future, but hasn't been thoroughly tested yet.

Supersedes ExpandSolution.

Method __init__ return f with reduced dimensionality.
Method insert_variables return x with inserted fixed values
Method transform transform x such that it could be used as argument to self.
Instance Variable index_value_pairs Undocumented

Inherited from ComposedFunction:

Method __call__ Undocumented
Method inverse evaluate the composition of inverses on x.
Instance Variable list_of_inverses Undocumented

Inherited from Function (via ComposedFunction):

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 __init__(self, f, index_value_pairs):

return f with reduced dimensionality.

index_value_pairs:
variables
def insert_variables(self, x):

return x with inserted fixed values

def transform(self, x):

transform x such that it could be used as argument to self.

Return a list or array, usually dismissing some elements of x. fun.transform is the inverse of fun.insert_variables == fun[1], that is np.all(x == fun.transform(fun.insert_variables(x))) is True.

index_value_pairs =

Undocumented