Class BoundTransform
source code
object --+
|
BoundaryHandlerBase --+
|
BoundTransform
Handles boundary by a smooth, piecewise linear and quadratic
transformation into the feasible domain.
>>> import cma
>>> veq = cma.Mh.vequals_approximately
>>> b = cma.BoundTransform([None, 1])
>>> assert b.bounds == [[None], [1]]
>>> assert veq(b.repair([0, 1, 1.2]), 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 ])
>>> o=cma.fmin(cma.fcts.sphere, 6 * [-2], 0.5, options={
... 'boundary_handling': 'BoundTransform ',
... 'bounds': [[], 5 * [-1] + [inf]] })
>>> assert o[1] < 5 + 1e-8
>>> import numpy as np
>>> b = cma.BoundTransform([-np.random.rand(120), np.random.rand(120)])
>>> for i in range(100):
... 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
|
__init__(self,
bounds=None)
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. |
source code
|
|
|
repair(self,
x,
copy_if_changed=True,
copy_always=False)
transforms x into the bounded domain. |
source code
|
|
|
|
|
inverse(self,
x,
copy_if_changed=True,
copy_always=False)
inverse transform of x from the bounded domain. |
source code
|
|
Inherited from BoundaryHandlerBase :
__call__ ,
get_bounds ,
has_bounds ,
is_in_bounds ,
to_dim_times_two ,
update
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
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.
- Overrides:
object.__init__
|