class documentation

class BoundDomainTransform(object):

Constructor: BoundDomainTransform(function, boundaries)

View In Hierarchy

create a callable with unbounded domain from a function with bounded domain,

for example an objective or constraints function. The new "unbounded" callable maps x to function(self.transform(x)), first "projecting" the input (e.g., candidate solutions) into the bounded domain with transform before to evaluate the result on the original function. The "projection" is smooth and differentiable, namely coordinate-wise piecewise linear or quadratic. The "projection" is not idempotent.

Bounds are passed as boundaries = [lower_bounds, upper_bounds] where each *_bounds can be None, or a scalar, or an iterable (a vector) whose values can be None too. If the iterable has fewer values than the solutions, the last value is recycled, if it has more values, trailing values are ignored.

For example, boundaries = [None, [0, 0, None]] means no lower bounds and an upper bound of zero for the first two variables.

Example:

>>> import cma
>>> fun = cma.boundary_handler.BoundDomainTransform(
...             cma.ff.sphere,  # is composed with fun.transform into fun
...             [[0.02, 0.01], None])  # boundaries for the "original" problem
>>> x, es = cma.fmin2(fun, 3 * [0.5], 0.5, {'verbose':-9})
>>> assert all(x - 1e-4 < [-0.03, -0.04, -0.04])  # x is in the unbounded domain
>>> print("solution in the original (bounded) domain = {}"
...       .format(fun.transform(es.result.xfavorite)))
solution in the original (bounded) domain = [0.02 0.01 0.01]

The original function can be accessed and called via the attribute function like fun.function(...). For code simplicity, attributes of function are "inherited" to fun.

Details: the resulting function has a repetitive landscape with a period slightly larger than twice the boundary interval. The BoundDomainTransform(function,...) instance emulates the original function on attribute access by calling __getattr__. To access shadowed attributes or for debugging, replace .attrname with .function.attrname.

Method __call__ Undocumented
Method __getattr__ return getattr(self.function, name) when not hasattr(self, name).
Method __init__ return a callable that evaluates function only within boundaries
Instance Variable boundary_handler Undocumented
Instance Variable function Undocumented
Instance Variable transform Undocumented
def __call__(self, x, *args, **kwargs):

Undocumented

def __getattr__(self, name):

return getattr(self.function, name) when not hasattr(self, name).

This emulates the function interface, kinda like blind inheritance.

def __init__(self, function, boundaries):

return a callable that evaluates function only within boundaries

boundary_handler =

Undocumented

function =

Undocumented

transform =

Undocumented