Module cma :: Class BoundTransform
[hide private]
[frames] | no frames]

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

Instance Methods [hide private]
 
__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
 
transform(self, x) 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 BoundaryHandlerBase (private): _get_bounds

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, bounds=None)
(Constructor)

source code 
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__

repair(self, x, copy_if_changed=True, copy_always=False)

source code 

transforms x into the bounded domain.

copy_always option might disappear.

Overrides: BoundaryHandlerBase.repair

inverse(self, x, copy_if_changed=True, copy_always=False)

source code 
inverse transform of x from the bounded domain.
Overrides: BoundaryHandlerBase.inverse