class documentation

`class BoundTransform(BoundaryHandlerBase):`

View In Hierarchy

Handle boundaries by a smooth, piecewise linear and quadratic transformation into the feasible domain.

```>>> import numpy as np
>>> import cma
>>> from cma.constraints_handler import BoundTransform
>>> from cma import fitness_transformations as ft
>>> veq = cma.utilities.math.Mh.vequals_approximately
>>> b = BoundTransform([None, 1])
>>> assert b.bounds == [[None], [1]]
>>> assert veq(b.repair([0, 1, 1.2]), np.array([ 0., 0.975, 0.975]))
>>> assert b.is_in_bounds([0, 0.5, 1])
>>> assert veq(b.transform([0, 1, 2]), [ 0.   ,  0.975,  0.2  ])
>>> bounded_sphere = ft.ComposedFunction([
...         cma.ff.sphere,
...         BoundTransform([[], 5 * [-1] + [np.inf]]).transform
...     ])
>>> o1 = cma.fmin(bounded_sphere, 6 * [-2], 0.5)  # doctest: +ELLIPSIS
(4_w,9)-aCMA-ES (mu_w=2.8,w_1=49%) in dimension 6 (seed=...
>>> o2 = cma.fmin(cma.ff.sphere, 6 * [-2], 0.5, options={
...    'BoundaryHandler': cma.s.ch.BoundTransform,
...    'bounds': [[], 5 * [-1] + [np.inf]] })  # doctest: +ELLIPSIS
(4_w,9)-aCMA-ES (mu_w=2.8,w_1=49%) in dimension 6 (seed=...
>>> assert o1[1] < 5 + 1e-8 and o2[1] < 5 + 1e-8
>>> b = BoundTransform([-np.random.rand(120), np.random.rand(120)])
>>> for i in range(0, 100, 9):
...     x = (-i-1) * np.random.rand(120) + i * np.random.randn(120)
...     x_to_b = b.repair(x)
...     x2 = b.inverse(x_to_b)
...     x2_to_b = b.repair(x2)
...     x3 = b.inverse(x2_to_b)
...     x3_to_b = b.repair(x3)
...     assert veq(x_to_b, x2_to_b)
...     assert veq(x2, x3)
...     assert veq(x2_to_b, x3_to_b)```

Details: this class uses class BoxConstraintsLinQuadTransformation

 Method `__init__` Argument bounds can be `None` or bounds[0] and bounds[1] are lower and upper domain boundaries, each is either `None` or a scalar or a list or array of appropriate size. Method `inverse` inverse transform of x from the bounded domain. Method `repair` transforms x into the bounded domain. Method `transform` Undocumented Instance Variable `bounds_tf` Undocumented

Inherited from `BoundaryHandlerBase`:

 Method `__call__` return penalty or list of penalties, by default zero(s). Method `get_bound` return lower and upper bound of variable with index `index` Method `get_bounds` get_bounds('lower', 8) returns the lower bounds in 8-D Method `has_bounds` return `True` if any variable is bounded Method `idx_out_of_bounds` return index list of out-of-bound values in `x`. Method `is_in_bounds` not yet tested Method `to_dim_times_two` return boundaries in format [[lb0, ub0], [lb1, ub1], ...], as used by BoxConstraints... class. Method `update` end-iteration callback of boundary handler (abstract/empty) Instance Variable `bounds` Undocumented Method `_get_bounds` ib == 0/1 means lower/upper bound, return a vector of length `dimension`
def __init__(self, bounds=None):
overrides `cma.constraints_handler.BoundaryHandlerBase.__init__`

Argument bounds can be `None` or bounds[0] and bounds[1] are lower and upper domain boundaries, each is either `None` or a scalar or a list or array of appropriate size.

def inverse(self, x, copy_if_changed=True):
overrides `cma.constraints_handler.BoundaryHandlerBase.inverse`

inverse transform of x from the bounded domain.

def repair(self, x, copy_if_changed=True):
overrides `cma.constraints_handler.BoundaryHandlerBase.repair`

transforms x into the bounded domain.

def transform(self, x):

Undocumented

bounds_tf =

Undocumented