def __init__( self, basef, translate=True, rotate=False, conditioning=None, asymmetry=None, oscillate=False, penalized=0, desiredValue=1e-8, gnoise=None, unoise=None, cnoise=None, sparse=True, ): FunctionEnvironment.__init__(self, basef.xdim, basef.xopt) self._name = basef.__class__.__name__ self.desiredValue = desiredValue self.toBeMinimized = basef.toBeMinimized if self.xdim < 500: sparse = False if sparse: try: from scipy.sparse import csc_matrix except: sparse = False if translate: self.xopt = (rand(self.xdim) - 0.5) * 9.8 if conditioning: prefix = generateDiags(conditioning, self.xdim) if sparse: prefix = csc_matrix(prefix) if rotate: prefix = prefix * sparse_orth(self.xdim) if oscillate or not asymmetry: prefix = sparse_orth(self.xdim) * prefix else: if rotate: prefix = dot(prefix, dense_orth(self.xdim)) if oscillate or not asymmetry: prefix = dot(dense_orth(self.xdim), prefix) elif rotate and asymmetry and not oscillate: if sparse: prefix = sparse_orth(self.xdim) else: prefix = dense_orth(self.xdim) elif sparse: prefix = None else: prefix = eye(self.xdim) if penalized != 0: if self.penalized: penalized = 0 else: self.penalized = True # combine transformations if rotate: if sparse: r = sparse_orth(self.xdim) tmp1 = lambda x: ravel(x * r) else: r = dense_orth(self.xdim) tmp1 = lambda x: dot(x, r) else: tmp1 = lambda x: x if oscillate: tmp2 = lambda x: BBOBTransformationFunction.oscillatify(tmp1(x)) else: tmp2 = tmp1 if asymmetry is not None: tmp3 = lambda x: BBOBTransformationFunction.asymmetrify( tmp2(x), asymmetry) else: tmp3 = tmp2 # noise ntmp = None if gnoise: ntmp = lambda f: f * exp(gnoise * gauss(0, 1)) elif unoise: alpha = 0.49 * (1. / self.xdim) * unoise ntmp = lambda f: f * power(random(), unoise) * max( 1, power(1e9 / (f + 1e-99), alpha * random())) elif cnoise: alpha, beta = cnoise ntmp = lambda f: f + alpha * max( 0, 1000 * (random() < beta) * gauss(0, 1) / (abs(gauss(0, 1)) + 1e-199)) def noisetrans(f): if ntmp is None or f < 1e-8: return f else: return ntmp(f) + 1.01e-8 if sparse: if prefix is None: tmp4 = lambda x: tmp3(x - self.xopt) else: tmp4 = lambda x: ravel(prefix * tmp3(x - self.xopt)) else: tmp4 = lambda x: dot(prefix, tmp3(x - self.xopt)) self.f = lambda x: (noisetrans(basef.f(tmp4(x))) + penalized * penalize(x))
def __init__(self, basef, translate=True, rotate=False, conditioning=None, asymmetry=None, oscillate=False, penalized=0, desiredValue=1e-8, gnoise=None, unoise=None, cnoise=None, sparse=True, ): FunctionEnvironment.__init__(self, basef.xdim, basef.xopt) self._name = basef.__class__.__name__ self.desiredValue = desiredValue self.toBeMinimized = basef.toBeMinimized if self.xdim < 500: sparse = False if sparse: try: from scipy.sparse import csc_matrix except: sparse = False if translate: self.xopt = (rand(self.xdim) - 0.5) * 9.8 if conditioning: prefix = generateDiags(conditioning, self.xdim) if sparse: prefix = csc_matrix(prefix) if rotate: prefix = prefix * sparse_orth(self.xdim) if oscillate or not asymmetry: prefix = sparse_orth(self.xdim) * prefix else: if rotate: prefix = dot(prefix, dense_orth(self.xdim)) if oscillate or not asymmetry: prefix = dot(dense_orth(self.xdim), prefix) elif rotate and asymmetry and not oscillate: if sparse: prefix = sparse_orth(self.xdim) else: prefix = dense_orth(self.xdim) elif sparse: prefix = None else: prefix = eye(self.xdim) if penalized != 0: if self.penalized: penalized = 0 else: self.penalized = True # combine transformations if rotate: if sparse: r = sparse_orth(self.xdim) tmp1 = lambda x: ravel(x * r) else: r = dense_orth(self.xdim) tmp1 = lambda x: dot(x, r) else: tmp1 = lambda x: x if oscillate: tmp2 = lambda x: BBOBTransformationFunction.oscillatify(tmp1(x)) else: tmp2 = tmp1 if asymmetry is not None: tmp3 = lambda x: BBOBTransformationFunction.asymmetrify(tmp2(x), asymmetry) else: tmp3 = tmp2 # noise ntmp = None if gnoise: ntmp = lambda f: f * exp(gnoise * gauss(0, 1)) elif unoise: alpha = 0.49 * (1. / self.xdim) * unoise ntmp = lambda f: f * power(random(), unoise) * max(1, power(1e9 / (f + 1e-99), alpha * random())) elif cnoise: alpha, beta = cnoise ntmp = lambda f: f + alpha * max(0, 1000 * (random() < beta) * gauss(0, 1) / (abs(gauss(0, 1)) + 1e-199)) def noisetrans(f): if ntmp is None or f < 1e-8: return f else: return ntmp(f) + 1.01e-8 if sparse: if prefix is None: tmp4 = lambda x: tmp3(x - self.xopt) else: tmp4 = lambda x: ravel(prefix * tmp3(x - self.xopt)) else: tmp4 = lambda x: dot(prefix, tmp3(x - self.xopt)) self.f = lambda x: (noisetrans(basef.f(tmp4(x))) + penalized * penalize(x))