How to use the cma.bbobbenchmarks.BBOBNfreeFunction function in cma

To help you get started, we’ve selected a few cma examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
# BOUNDARY HANDLING
        fadd = fadd + self.boundaryhandling(x)

        # TRANSFORMATION IN SEARCH SPACE
        x = x - self.arrxopt # cannot be replaced with x -= arrxopt!

        # COMPUTATION core
        ftrue = np.sum(x**2, -1)
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F1(_FSphere, BBOBNfreeFunction):
    """Noise-free Sphere function"""
    funId = 1
    def boundaryhandling(self, x):
        return 0.

class F101(_FSphere, BBOBGaussFunction):
    """Sphere with moderate Gauss noise"""
    funId = 101
    gaussbeta = 0.01

class F102(_FSphere, BBOBUniformFunction):
    """Sphere with moderate uniform noise"""
    funId = 102
    unifalphafac = 0.01
    unifbeta = 0.01
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
funId = 119
    gaussbeta = 1.

class F120(_FDiffPow, BBOBUniformFunction):
    """Sum of different powers with uniform noise, between x^2 and x^6"""
    funId = 120
    unifalphafac = 1.
    unifbeta = 1.

class F121(_FDiffPow, BBOBCauchyFunction):
    """Sum of different powers with seldom Cauchy noise, between x^2 and x^6"""
    funId = 121
    cauchyalpha = 1.
    cauchyp = 0.2

class F15(BBOBNfreeFunction):
    """Rastrigin with asymmetric non-linear distortion, "condition" 10"""
    funId = 15
    condition = 10.
    beta = 0.2

    def initwithsize(self, curshape, dim):
        # DIM-dependent initialization
        if self.dim != dim:
            if self.zerox:
                self.xopt = zeros(dim)
            else:
                self.xopt = compute_xopt(self.rseed, dim)
            self.rotation = compute_rotation(self.rseed + 1e6, dim)
            self.scales = (self.condition ** .5) ** linspace(0, 1, dim)
            self.linearTF = dot(compute_rotation(self.rseed, dim), diag(self.scales))
            # decouple scaling from function definition
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
funId = 110
    gaussbeta = 1.

class F111(_FRosenbrock, BBOBUniformFunction):
    """Rosenbrock non-rotated with uniform noise"""
    funId = 111
    unifalphafac = 1.
    unifbeta = 1.

class F112(_FRosenbrock, BBOBCauchyFunction):
    """Rosenbrock non-rotated with Cauchy noise"""
    funId = 112
    cauchyalpha = 1.
    cauchyp = 0.2

class F9(BBOBNfreeFunction):
    """Rosenbrock, rotated"""
    funId = 9

    def initwithsize(self, curshape, dim):
        # DIM-dependent initialization
        if self.dim != dim:
            if self.zerox:
                self.xopt = zeros(dim)
            else:
                self.xopt = compute_xopt(self.rseed, dim)
            scale = max(1, dim ** .5 / 8.) # nota: different from scales in F8
            self.linearTF = scale * compute_rotation(self.rseed, dim)
            self.xopt = np.hstack(dot(.5 * np.ones((1, dim)), self.linearTF.T)) / scale ** 2

        # DIM- and POPSI-dependent initialisations of DIM*POPSI matrices
        if self.lastshape != curshape:
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
if self.lastshape != curshape:
            self.initwithsize(curshape, dim)

        # TRANSFORMATION IN SEARCH SPACE
        x = x - self.arrxopt # cannot be replaced with x -= arrxopt!

        # COMPUTATION core
        ftrue = dot(monotoneTFosc(x)**2, self.scales)
        fval = self.noise(ftrue) # without noise

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F3(BBOBNfreeFunction):
    """Rastrigin with monotone transformation separable "condition" 10"""

    funId = 3
    condition = 10.
    beta = 0.2

    def initwithsize(self, curshape, dim):
        # DIM-dependent initialisation
        if self.dim != dim:
            if self.zerox:
                self.xopt = zeros(dim)
            else:
                self.xopt = compute_xopt(self.rseed, dim)
            self.scales = (self.condition ** .5) ** linspace(0, 1, dim)

        # DIM- and POPSI-dependent initialisations of DIM*POPSI matrices
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
# COMPUTATION core
        try:
            ftrue = (1e2 * np.sum((x[:, :-1] ** 2 - x[:, 1:]) ** 2, -1) +
                     np.sum((x[:, :-1] - 1.) ** 2, -1))
        except IndexError:
            ftrue = (1e2 * np.sum((x[:-1] ** 2 - x[1:]) ** 2) +
                     np.sum((x[:-1] - 1.) ** 2))
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F8(_FRosenbrock, BBOBNfreeFunction):
    """Rosenbrock noise-free"""
    funId = 8
    def boundaryhandling(self, x):
        return 0.

class F104(_FRosenbrock, BBOBGaussFunction):
    """Rosenbrock non-rotated with moderate Gauss noise"""
    funId = 104
    gaussbeta = 0.01

class F105(_FRosenbrock, BBOBUniformFunction):
    """Rosenbrock non-rotated with moderate uniform noise"""
    funId = 105
    unifalphafac = 0.01
    unifbeta = 0.01
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
F15, F16, F17, F18, F19, F20, F21, F22, F23, F24) # hard coded
noisyfunclasses = (F101, F102, F103, F104, F105, F106, F107, F108, F109, F110,
                   F111, F112, F113, F114, F115, F116, F117, F118, F119, F120,
                   F121, F122, F123, F124, F125, F126, F127, F128, F129, F130)
dictbbobnfree = dict((i.funId, i) for i in nfreefunclasses)
nfreeIDs = sorted(dictbbobnfree.keys())  # was: "nfreenames"
nfreeinfos = [str(i) + ': ' + dictbbobnfree[i].__doc__ for i in nfreeIDs]

dictbbobnoisy = dict((i.funId, i) for i in noisyfunclasses)
noisyIDs = sorted(dictbbobnoisy.keys())  # was noisynames

funclasses = list(nfreefunclasses) + list(noisyfunclasses)
dictbbob = dict((i.funId, i) for i in funclasses)

# TODO: pb xopt f9, 21, 22
class _FTemplate(BBOBNfreeFunction):
    """Template based on F1"""

    funId = 421337

    def initwithsize(self, curshape, dim):
        # DIM-dependent initialization
        if self.dim != dim:
            if self.zerox:
                self.xopt = zeros(dim)
            else:
                self.xopt = compute_xopt(self.rseed, dim)

        # DIM- and POPSI-dependent initialisations of DIM*POPSI matrices
        if self.lastshape != curshape:
            self.dim = dim
            self.lastshape = curshape
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
x = monotoneTFosc(x)

        # COMPUTATION core
        ftrue = dot(x ** 2, self.scales)
        try:
            ftrue = np.hstack(ftrue)
        except TypeError: # argument 2 to map() must support iteration
            pass
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F10(_FEllipsoid, BBOBNfreeFunction):
    """Ellipsoid with monotone transformation, condition 1e6"""
    funId = 10
    condition = 1e6
    def boundaryhandling(self, x):
        return 0.

class F116(_FEllipsoid, BBOBGaussFunction):
    """Ellipsoid with Gauss noise, monotone x-transformation, condition 1e4"""
    funId = 116
    condition = 1e4
    gaussbeta = 1.

class F117(_FEllipsoid, BBOBUniformFunction):
    """Ellipsoid with uniform noise, monotone x-transformation, condition 1e4"""
    funId = 117
    condition = 1e4
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
xx = tile(e, (self.nhighpeaks, 1)) - self.xlocal
                f[k, :] = self.peakvalues * np.exp(fac * np.sum(self.arrscales * xx ** 2, 1))
        else:
            f = np.zeros((curshape[0], self.nhighpeaks))
            for i in range(self.nhighpeaks):
                xx = (x - tile(self.xlocal[i, :], (curshape[0], 1)))
                f[:, i] = self.peakvalues[i] * np.exp(fac * (dot(xx ** 2, self.arrscales[i, :])))
        ftrue = monotoneTFosc(10 - np.max(f, -1)) ** 2
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F21(_FGallagher, BBOBNfreeFunction):
    """Gallagher with 101 Gaussian peaks, condition up to 1000, one global rotation, noise-free"""
    funId = 21
    nhighpeaks = 101
    fac2 = 1.
    highpeakcond = 1000. ** .5
    def boundaryhandling(self, x):
        return defaultboundaryhandling(x, 1.)

class F22(_FGallagher, BBOBNfreeFunction):
    """Gallagher with 21 Gaussian peaks, condition up to 1000, one global rotation"""
    funId = 22
    rrseed = 22
    nhighpeaks = 21
    fac2 = 0.98
    highpeakcond = 1000.
    def boundaryhandling(self, x):
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
x1 = x[0]
        idx = np.abs(x) > .5
        x[idx] = np.round(x[idx])
        x[~idx] = np.round(self.alpha * x[~idx]) / self.alpha
        x = dot(x, self.rotation)

        # COMPUTATION core
        ftrue = .1 * np.maximum(1e-4 * np.abs(x1), dot(x ** 2, self.scales))
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F7(_FStepEllipsoid, BBOBNfreeFunction):
    """Step-ellipsoid, condition 100, noise-free"""
    funId = 7
    def boundaryhandling(self, x):
        return defaultboundaryhandling(x, 1.)

class F113(_FStepEllipsoid, BBOBGaussFunction):
    """Step-ellipsoid with gauss noise, condition 100"""
    funId = 113
    gaussbeta = 1.

class F114(_FStepEllipsoid, BBOBUniformFunction):
    """Step-ellipsoid with uniform noise, condition 100"""
    funId = 114
    unifalphafac = 1.
    unifbeta = 1.
github CMA-ES / pycma / cma / bbobbenchmarks.py View on Github external
tmpx = x[:, :min(self.dim, self.maxindex):2] # tmpx is a reference to a part of x
        except IndexError:
            tmpx = x[:min(self.dim, self.maxindex):2] # tmpx is a reference to a part of x
        tmpx[tmpx > 0] = self.alpha ** .5 * tmpx[tmpx > 0] # this modifies x
        x = self.arrscales * x # scale while assuming that Xopt == 0

        # COMPUTATION core
        ftrue = 10 * (self.dim - np.sum(np.cos(2 * np.pi * x), -1)) + np.sum(x ** 2, -1)
        fval = self.noise(ftrue)

        # FINALIZE
        ftrue += fadd
        fval += fadd
        return fval, ftrue

class F5(BBOBNfreeFunction):
    """Linear slope"""

    funId = 5
    alpha = 100.

    def initwithsize(self, curshape, dim):
        # DIM-dependent initialization
        if self.dim != dim:
            if self.zerox:
                self.xopt = zeros(dim) # TODO: what happens here?
            else:
                self.xopt = 5 * sign(compute_xopt(self.rseed, dim))
            self.scales = -sign(self.xopt) * (self.alpha ** .5) ** linspace(0, 1, dim)

        # DIM- and POPSI-dependent initialisations of DIM*POPSI matrices
        if self.lastshape != curshape: