(self, dim, scaling=None, typical_x=None, bounds=None, fixed_values=None, tf=None)
return `GenoPheno` instance with fixed 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``
            `bounds` (obsolete, might disappear)
                list with two elements,
                lower and upper bounds both can be a scalar or a "vector"
                of length dim or `None`. Without effect, as `bounds` must
                be given as argument to `pheno()`.
            `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_1`` is ommitted, the initial x-value must be given as genotype (as the
        phenotype-genotype transformation is unknown) and injection of solutions
        might lead to unexpected results.
return `GenoPheno` instance with fixed dimension `dim`.
return GenoPheno instance with fixed dimension dim .
def __init__(self, dim, scaling=None, typical_x=None, bounds=None, fixed_values=None, tf=None):
        """return `GenoPheno` instance with fixed 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``
            `bounds` (obsolete, might disappear)
                list with two elements,
                lower and upper bounds both can be a scalar or a "vector"
                of length dim or `None`. Without effect, as `bounds` must
                be given as argument to `pheno()`.
            `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_1`` is ommitted, the initial x-value must be given as genotype (as the
        phenotype-genotype transformation is unknown) and injection of solutions
        might lead to unexpected results.

        """
        self.N = dim
        self.bounds = bounds
        self.fixed_values = fixed_values
        if tf is not None:
            self.tf_pheno = tf[0]
            self.tf_geno = tf[1]  # TODO: should not necessarily be needed
            # r = np.random.randn(dim)
            # assert all(tf[0](tf[1](r)) - r < 1e-7)
            # r = np.random.randn(dim)
            # assert all(tf[0](tf[1](r)) - r > -1e-7)
            print("WARNING in class GenoPheno: user defined transformations have not been tested thoroughly")
        else:
            self.tf_geno = None
            self.tf_pheno = None

        if fixed_values:
            if type(fixed_values) is not dict:
                raise _Error("fixed_values must be a dictionary {index:value,...}")
            if max(fixed_values.keys()) >= dim:
                raise _Error("max(fixed_values.keys()) = " + str(max(fixed_values.keys())) +
                    " >= dim=N=" + str(dim) + " is not a feasible index")
            # convenience commenting functionality: drop negative keys
            for k in list(fixed_values.keys()):
                if k < 0:
                    fixed_values.pop(k)
        if bounds:
            if len(bounds) != 2:
                raise _Error('len(bounds) must be 2 for lower and upper bounds')
            for i in (0,1):
                if bounds[i] is not None:
                    bounds[i] = array(dim * [bounds[i]] if np.isscalar(bounds[i]) else
                                        [b for b in bounds[i]])

        def vec_is_default(vec, default_val=0):
            """return True if `vec` has the value `default_val`,
            None or [None] are also recognized as default"""
            try:
                if len(vec) == 1:
                    vec = vec[0]  # [None] becomes None and is always default
                else:
                    return False
            except TypeError:
                pass  # vec is a scalar

            if vec is None or vec == array(None) or vec == default_val:
                return True
            return False

        self.scales = array(scaling)
        if vec_is_default(self.scales, 1):
            self.scales = 1  # CAVE: 1 is not array(1)
        elif self.scales.shape is not () and len(self.scales) != self.N:
            raise _Error('len(scales) == ' + str(len(self.scales)) +
                         ' does not match dimension N == ' + str(self.N))

        self.typical_x = array(typical_x)
        if vec_is_default(self.typical_x, 0):
            self.typical_x = 0
        elif self.typical_x.shape is not () and len(self.typical_x) != self.N:
            raise _Error('len(typical_x) == ' + str(len(self.typical_x)) +
                         ' does not match dimension N == ' + str(self.N))

        if (self.scales is 1 and
                self.typical_x is 0 and
                self.bounds in (None, [None, None]) and
                self.fixed_values is None and
                self.tf_pheno is None):
            self.isidentity = True
        else:
            self.isidentity = False
def __init__ ( self , dim , scaling = None , typical_x = None , bounds = None , fixed_values = None , tf = None ) : self . N = dim self . bounds = bounds self . fixed_values = fixed_values if tf is not None : self . tf_pheno = tf [ 0 ] self . tf_geno = tf [ 1 ] # TODO: should not necessarily be needed # r = np.random.randn(dim) # assert all(tf[0](tf[1](r)) - r < 1e-7) # r = np.random.randn(dim) # assert all(tf[0](tf[1](r)) - r > -1e-7) print ( "WARNING in class GenoPheno: user defined transformations have not been tested thoroughly" ) else : self . tf_geno = None self . tf_pheno = None if fixed_values : if type ( fixed_values ) is not dict : raise _Error ( "fixed_values must be a dictionary {index:value,...}" ) if max ( fixed_values . keys ( ) ) >= dim : raise _Error ( "max(fixed_values.keys()) = " + str ( max ( fixed_values . keys ( ) ) ) + " >= dim=N=" + str ( dim ) + " is not a feasible index" ) # convenience commenting functionality: drop negative keys for k in list ( fixed_values . keys ( ) ) : if k < 0 : fixed_values . pop ( k ) if bounds : if len ( bounds ) != 2 : raise _Error ( 'len(bounds) must be 2 for lower and upper bounds' ) for i in ( 0 , 1 ) : if bounds [ i ] is not None : bounds [ i ] = array ( dim * [ bounds [ i ] ] if np . isscalar ( bounds [ i ] ) else [ b for b in bounds [ i ] ] ) def vec_is_default ( vec , default_val = 0 ) : """return True if `vec` has the value `default_val`,
            None or [None] are also recognized as default""" try : if len ( vec ) == 1 : vec = vec [ 0 ] # [None] becomes None and is always default else : return False except TypeError : pass # vec is a scalar if vec is None or vec == array ( None ) or vec == default_val : return True return False self . scales = array ( scaling ) if vec_is_default ( self . scales , 1 ) : self . scales = 1 # CAVE: 1 is not array(1) elif self . scales . shape is not ( ) and len ( self . scales ) != self . N : raise _Error ( 'len(scales) == ' + str ( len ( self . scales ) ) + ' does not match dimension N == ' + str ( self . N ) ) self . typical_x = array ( typical_x ) if vec_is_default ( self . typical_x , 0 ) : self . typical_x = 0 elif self . typical_x . shape is not ( ) and len ( self . typical_x ) != self . N : raise _Error ( 'len(typical_x) == ' + str ( len ( self . typical_x ) ) + ' does not match dimension N == ' + str ( self . N ) ) if ( self . scales is 1 and self . typical_x is 0 and self . bounds in ( None , [ None , None ] ) and self . fixed_values is None and self . tf_pheno is None ) : self . isidentity = True else : self . isidentity = False