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

Class GenoPheno

source code

object --+
         |
        GenoPheno

Genotype-phenotype transformation.

Method pheno provides the transformation from geno- to phenotype, that is from the internal representation to the representation used in the objective function. Method geno provides the "inverse" pheno- to genotype transformation. The geno-phenotype transformation comprises, in this order:

By default all transformations are the identity. The repair is only applied, if the transformation is given as argument to the method pheno.

geno is only necessary, if solutions have been injected.

Instance Methods [hide private]
 
__init__(self, dim, scaling=None, typical_x=None, fixed_values=None, tf=None)
return GenoPheno instance with phenotypic dimension dim.
source code
 
pheno(self, x, into_bounds=None, copy=True, copy_always=False, archive=None, iteration=None)
maps the genotypic input argument into the phenotypic space, see help for class GenoPheno
source code
 
geno(self, y, from_bounds=None, copy_if_changed=True, copy_always=False, repair=None, archive=None)
maps the phenotypic input argument into the genotypic space, that is, computes essentially the inverse of pheno.
source code

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, dim, scaling=None, typical_x=None, fixed_values=None, tf=None)
(Constructor)

source code 

return GenoPheno instance with phenotypic dimension dim.

Keyword Arguments

scaling
the diagonal of a scaling transformation matrix, multipliers in the genotyp-phenotyp transformation, see typical_x
typical_x
pheno = scaling*geno + typical_x
fixed_values
a dictionary of variable indices and values, like {0:2.0, 2:1.1}, that are not subject to change, negative indices are ignored (they act like incommenting the index), values are phenotypic values.
tf

list of two user-defined transformation functions, or None.

tf[0] is a function that transforms the internal representation as used by the optimizer into a solution as used by the objective function. tf[1] does the back-transformation. For example:

tf_0 = lambda x: [xi**2 for xi in x]
tf_1 = lambda x: [abs(xi)**0.5 fox xi in x]

or "equivalently" without the lambda construct:

def tf_0(x):
    return [xi**2 for xi in x]
def tf_1(x):
    return [abs(xi)**0.5 fox xi in x]

tf=[tf_0, tf_1] is a reasonable way to guaranty that only positive values are used in the objective function.

Details

If tf_0 is not the identity and tf_1 is ommitted, the genotype of x0 cannot be computed consistently and "injection" of phenotypic solutions is likely to lead to unexpected results.

Overrides: object.__init__

pheno(self, x, into_bounds=None, copy=True, copy_always=False, archive=None, iteration=None)

source code 

maps the genotypic input argument into the phenotypic space, see help for class GenoPheno

Details

If copy, values from x are copied if changed under the transformation.

geno(self, y, from_bounds=None, copy_if_changed=True, copy_always=False, repair=None, archive=None)

source code 

maps the phenotypic input argument into the genotypic space, that is, computes essentially the inverse of pheno.

By default a copy is made only to prevent to modify y.

The inverse of the user-defined transformation (if any) is only needed if external solutions are injected, it is not applied to the initial solution x0.

Details

geno searches first in archive for the genotype of y and returns the found value, typically unrepaired. Otherwise, first from_bounds is applied, to revert a projection into the bound domain (if necessary) and pheno is reverted. repair is applied last, and is usually the method CMAEvolutionStrategy.repair_genotype that limits the Mahalanobis norm of geno(y) - mean.