class FixVariables(ComposedFunction):
Constructor: FixVariables(f, index_value_pairs)
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 |
return x with inserted fixed values |
Method | transform |
transform x such that it could be used as argument to self . |
Instance Variable | index |
Undocumented |
Inherited from ComposedFunction
:
Method | __call__ |
Undocumented |
Method | inverse |
evaluate the composition of inverses on x. |
Instance Variable | list |
Undocumented |
Inherited from Function
(via ComposedFunction
):
Method | initialize |
initialization of Function |
Instance Variable | evaluations |
Undocumented |
Instance Variable | ftarget |
Undocumented |
Instance Variable | target |
Undocumented |
Property | function |
attributes which are searched for to be called if no function was given to __init__ . |
Class Variable | _function |
Undocumented |
Instance Variable | __callable |
Undocumented |
Instance Variable | __initialized |
Undocumented |