Changeset 751
- Timestamp:
- 09/23/14 18:22:45 (20 months ago)
- Location:
- mystic
- Files:
-
- 3 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
mystic/models/__init__.py
r713 r751 16 16 the function API found in `mystic.models.abstract_model`. These standard 17 17 functions are provided:: 18 sphere -- De Jong's spherical function 18 19 rosen -- Rosenbrock's function 19 20 step -- De Jong's step function … … 21 22 shekel -- Shekel's function 22 23 corana -- Corana's function 23 fosc3d -- the fOsc3D Mathematicafunction24 fosc3d -- Trott's fOsc3D function 24 25 griewangk -- Griewangk's function 25 26 zimmermann -- Zimmermann's function 27 peaks -- NAG's peaks function 28 venkat91 -- Venkataraman's sinc function 29 schwefel -- Schwefel's function 30 ellipsoid -- Pohlheim's rotated hyper-ellipsoid function 31 rastrigin -- Rastrigin's function 32 powers -- Pohlheim's sum of different powers function 33 ackley -- Ackley's path function 34 michal -- Michalewicz's function 35 branins -- Branins's rcos function 36 easom -- Easom's function 37 goldstein -- Goldstein-Price's function 26 38 wavy1 -- a simple sine-based multi-minima function 27 39 wavy2 -- another simple sine-based multi-minima function … … 61 73 62 74 # functions 63 from dejong import rosen, step, quartic, shekel75 from dejong import sphere, rosen, step, quartic, shekel 64 76 from corana import corana 65 from fosc3dimport fosc3d77 from trott import fosc3d 66 78 from griewangk import griewangk 67 79 from zimmermann import zimmermann 80 from nag import peaks 81 from venkataraman import venkat91 68 82 from wavy import wavy1, wavy2 83 from pohlheim import schwefel, ellipsoid, rastrigin, powers, ackley 84 from pohlheim import michal, branins, easom, goldstein 69 85 70 86 #shortcuts … … 72 88 #from br8 import data as br8data 73 89 #from br8 import cost as br8cost 74 #from corana import corana1d, corana2d, corana3d75 90 #from lorentzian import gendata, histogram 76 91 -
mystic/models/abstract_model.py
r750 r751 23 23 24 24 For example, if function is overwritten with the Rosenbrock function: 25 >>> rosen = Rosenbrock( )26 >>> rosen( 1,1,1)25 >>> rosen = Rosenbrock(ndim=3) 26 >>> rosen([1,1,1]) 27 27 0. 28 28 """ 29 29 30 def __init__(self ):30 def __init__(self, ndim=None): 31 31 """ 32 32 Provides a base class for mystic functions. 33 33 34 Takes no inputs.34 Takes optional input 'ndim' (number of dimensions). 35 35 """ 36 if self.minimizers is None: 37 self.minimizers = [] 38 #raise NotImplementedError('minimizers have not been provided') 39 nmin = len(self.minimizers) 40 41 # set the number of dimensions 42 try: # fixed dimension 43 self.ndim = len(self.minimizers[0] if nmin else None) 44 fixed = True 45 if ndim is None: ndim = self.ndim 46 except TypeError: # not fixed 47 self.ndim = ndim 48 fixed = False 49 if fixed and ndim != self.ndim: 50 raise ValueError('number of dimensions is fixed (ndim=%d)' % self.ndim) 51 elif not fixed and ndim is None: 52 raise ValueError('number of dimensions must be set (ndim=None)') 53 54 # set the minimizer (and adjust minimizers if not fixed) 55 if not nmin: 56 self.minimizers = list(self.minimizers) 57 self.minimizer = None 58 elif not fixed: #XXX: should be array instead of tuple? 59 self.minimizers = [tuple([m]*ndim) for m in self.minimizers] 60 self.minimizer = self.minimizers[0] # global *must* be first 61 else: 62 self.minimizers = list(self.minimizers) 63 self.minimizer = self.minimizers[0] # global *must* be first 64 65 # get the mimima 66 self.minima = map(self.function, self.minimizers) 67 self.minimum = min(self.minima) if self.minima else None 68 if self.minima and self.minima.index(self.minimum): 69 raise ValueError('global minimum must be at index = 0') 36 70 return 37 71 38 72 def __call__(self,*args,**kwds): 73 coeffs = kwds.get('coeffs', args[0] if len(args) else []) 74 if len(coeffs) != self.ndim: 75 raise ValueError('input length does not match ndim (ndim=%d)' % self.ndim) 39 76 return self.function(*args,**kwds) 40 77 41 78 def function(self,coeffs): 42 79 """takes a list of coefficients x, returns f(x)""" 43 raise NotImplementedError, "overwrite f or each derived class"80 raise NotImplementedError, "overwrite function for each derived class" 44 81 45 82 # def forward(self,pts): 46 83 # """takes points p=(x,y,...), returns f(xi,yi,...)""" 47 84 # pts = asarray(pts) #XXX: converting to numpy.array slows by 10x 48 # return [self.function(i) for i in pts.transpose()] #FIXME: requires pts is a numpy.array 85 # return [self.function(i) for i in pts.transpose()] 86 87 minimizers = None # not given; *must* set to 'list' or 'list of tuples' 88 # - None => not set / not known / no minimizers 89 # - [1,5] => global and local; input dimensions are not fixed 90 # - [(1,2),(5,3)] => global and local; input dimensions are fixed 49 91 pass 50 92 -
mystic/models/corana.py
r713 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """ 9 Corana's function 8 __doc__ = _doc = """ 9 This is part of Storn's "Differential Evolution" test suite, as defined 10 in [2], with 'Corana' function definitions drawn from [3,4]. 10 11 11 12 References:: 12 [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient13 Heuristic for Global Optimization over Continuous Spaces. Journal of Global14 Optimization 11: 341-359, 1997.13 [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 14 Efficient Heuristic for Global Optimization over Continuous Spaces" 15 Journal of Global Optimization 11: 341-359, 1997. 15 16 16 [2] Storn, R. and Price, K. 17 (Same title as above, but as a technical report.) 18 http://www.icsi.berkeley.edu/~storn/deshort1.ps 17 [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 18 Efficient Heuristic for Global Optimization over Continuous Spaces" 19 TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 20 21 [3] Ingber, L. "Simulated Annealing: Practice Versus Theory" J. of 22 Mathematical and Computer Modeling 18(11), 29-57, 1993. 23 24 [4] Corana, A. and Marchesi, M. and Martini, C. and Ridella, S. 25 "Minimizing Multimodal Functions of Continuous Variables with the 26 'Simulated Annealing Algorithm'" ACM Transactions on Mathematical 27 Software, March, 272-280, 1987. 19 28 """ 20 29 from abstract_model import AbstractFunction … … 25 34 26 35 class Corana(AbstractFunction): 27 """Corana's function:28 a multi-minima function, Equation (22) of [2]""" 36 __doc__ = \ 37 """a Corana's parabola function generator 29 38 30 def __init__(self): 31 AbstractFunction.__init__(self) 39 Corana's parabola function [1,2,3,4] defines a paraboloid whose 40 axes are parallel to the coordinate axes. This funciton has a 41 large number of wells that increase in depth with proximity to 42 the origin. The global minimum is a plateau around the origin. 43 44 The generated function f(x) is a modified version of equation (22) 45 of [2], where len(x) <= 4. 46 """ + _doc 47 def __init__(self, ndim=4): # is n-dimensional n=[1,4] (n=4 in ref) 48 AbstractFunction.__init__(self, ndim=ndim) 32 49 return 33 50 34 51 def function(self,coeffs): 35 """evaluates the Corana function for a list of coeffs52 """evaluates a 4-D Corana's parabola function for a list of coeffs 36 53 37 minimum is f(x)=0.0 at xi=0.0""" 54 f(x) = \sum_(i=0)^(3) f_0(x) 55 56 Where for \abs(x_i - z_i) < 0.05: 57 f_0(x) = 0.15*(z_i - 0.05*\sign(z_i))^(2) * d_i 58 and otherwise: 59 f_0(x) = d_i * x_(i)^(2), 60 with z_i = \floor(\abs(x_i/0.2)+0.49999)*\sign(x_i)*0.2 61 and d_i = 1,1000,10,100. 62 63 For len(x) == 1, x = x_0,0,0,0; 64 for len(x) == 2, x = x_0,0,x_1,0; 65 for len(x) == 3, x = x_0,0,x_1,x_2; 66 for len(x) >= 4, x = x_0,x_1,x_2,x_3. 67 68 Inspect with mystic_model_plotter using:: 69 mystic.models.corana -b "-1:1:.01, -1:1:.01" -d -x 1 70 71 The minimum is f(x)=0 for \abs(x_i) < 0.05 for all i.""" 38 72 d = [1., 1000., 10., 100.] 73 _d = [0, 3, 1, 2] # ordering for lower dimensions 39 74 #x = asarray(coeffs) #XXX: converting to numpy.array slows by 10x 40 x = coeffs 75 x = [0.]*4 # ensure that there are 4 coefficients 76 if len(coeffs) < 4: 77 _x = x[:] 78 _x[:len(coeffs)]=coeffs 79 for i in range(4): 80 x[_d.index(i)] = _x[i] 81 else: 82 x = coeffs 41 83 r = 0 42 84 for j in range(4): … … 48 90 return r 49 91 50 # def forward(self,pts): 51 # """n-dimensional Corana; returns f(xi) for each xi in pts""" 52 # return AbstractFunction.forward(self,pts) 53 92 minimizers = None #FIXME: degenerate minimum... (-0.05, 0.05) 93 # minimum is f(x)=0 for \abs(x_i) < 0.05 for all i.""" 54 94 pass 55 95 96 # cleanup 97 del _doc 56 98 57 99 # prepared instances 58 corana = Corana() 59 60 def corana1d(x): 61 """Corana in 1D; coeffs = (x,0,0,0)""" 62 return corana([x[0], 0, 0, 0]) 63 64 def corana2d(x): 65 """Corana in 2D; coeffs = (x,0,y,0)""" 66 return corana([x[0], 0, x[1], 0]) 67 68 def corana3d(x): 69 """Corana in 3D; coeffs = (x,0,y,z)""" 70 return corana([x[0], 0, x[1], x[2]]) 100 corana = Corana().function 71 101 72 102 # End of file -
mystic/models/dejong.py
r713 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """9 Rosenbrock's function, De Jong's step function, De Jong's quartic function, 10 and Shekel's function 8 __doc__ = _doc = """ 9 This is part of Storn's "Differential Evolution" test suite, as defined 10 in [2], with 'De Jong' function definitions drawn from [3]. 11 11 12 12 References:: 13 [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 14 Heuristic for Global Optimization over Continuous Spaces. Journal of Global 15 Optimization 11: 341-359, 1997. 16 17 [2] Storn, R. and Price, K. 18 (Same title as above, but as a technical report.) 19 http://www.icsi.berkeley.edu/~storn/deshort1.ps 13 [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 14 Efficient Heuristic for Global Optimization over Continuous Spaces" 15 Journal of Global Optimization 11: 341-359, 1997. 16 17 [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 18 Efficient Heuristic for Global Optimization over Continuous Spaces" 19 TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 20 21 [3] Ingber, L. and Rosen, B. "Genetic Algorithms and Very Fast 22 Simulated Reannealing: A Comparison" J. of Mathematical and Computer 23 Modeling 16(11), 87-100, 1992. 20 24 """ 21 25 from abstract_model import AbstractFunction 22 26 23 27 from numpy import sum as numpysum 24 from numpy import asarray, transpose 28 from numpy import asarray, transpose, inf 25 29 from numpy import zeros_like, diag, zeros, atleast_1d 26 30 from math import floor 27 31 import random 28 32 from math import pow 33 from mystic.tools import permutations 34 35 class Sphere(AbstractFunction): 36 __doc__ = \ 37 """a De Jong spherical function generator 38 39 De Jong's spherical function [1,2,3] is considered to be a simple 40 task for every serious minimization method. The minimum is located 41 at the center of the N-dimensional spehere. There are no local 42 minima. 43 44 The generated function f(x) is identical to equation (17) of [2], 45 where len(x) >= 0. 46 """ + _doc 47 def __init__(self, ndim=3): # is n-dimensional (n=3 in ref) 48 AbstractFunction.__init__(self, ndim=ndim) 49 return 50 51 def function(self,coeffs): 52 """evaluates an N-dimensional spherical function for a list of coeffs 53 54 f(x) = \sum_(i=0)^(N-1) x_(i)^2 55 56 Inspect with mystic_model_plotter using:: 57 mystic.models.sphere -b "-5:5:.1, -5:5:.1" -d 58 59 The minimum is f(x)=0.0 at x_i=0.0 for all i""" 60 f = 0. 61 for c in coeffs: 62 f += c*c 63 return f 64 65 minimizers = [0.] 66 pass 67 29 68 30 69 class Rosenbrock(AbstractFunction): 31 """Rosenbrock function: 32 A modified second De Jong function, Equation (18) of [2]""" 33 34 def __init__(self): 35 AbstractFunction.__init__(self) 36 return 37 38 def function(self,coeffs): 39 """evaluates n-dimensional Rosenbrock function for a list of coeffs 40 41 minimum is f(x)=0.0 at xi=1.0""" 70 __doc__ = \ 71 """a Rosenbrock's Saddle function generator 72 73 Rosenbrock's Saddle function [1,2,3] has the reputation of being 74 a difficult minimization problem. In two dimensions, the function 75 is a saddle with an inverted basin, where the global minimum 76 occurs along the rim of the inverted basin. 77 78 The generated function f(x) is a modified version of equation (18) 79 of [2], where len(x) >= 0. 80 """ + _doc 81 def __init__(self, ndim=2): # is n-dimensional (n=2 in ref) 82 AbstractFunction.__init__(self, ndim=ndim) 83 return 84 85 def function(self,coeffs): 86 """evaluates an N-dimensional Rosenbrock saddle for a list of coeffs 87 88 f(x) = \sum_(i=0)^(N-2) 100*(x_(i+1) - x_(i)^(2))^(2) + (1 - x_(i))^(2) 89 90 Inspect with mystic_model_plotter using:: 91 mystic.models.rosen -b "-3:3:.1, -1:5:.1, 1" -d -x 1 92 93 The minimum is f(x)=0.0 at x_i=1.0 for all i""" 42 94 x = [1]*2 # ensure that there are 2 coefficients 43 95 x[:len(coeffs)]=coeffs … … 45 97 return numpysum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)#,axis=0) 46 98 47 #def forward(self,pts):48 # """n-dimensional Rosenbrock; returns f(xi,yi,...) for pts=(x,y,...)"""49 # return AbstractFunction.forward(self,pts)50 51 99 def derivative(self,coeffs): 52 """evaluates n-dimensional Rosenbrock derivative for a list of coeffs53 54 minimum is f'(x)=[0.0]*n at x=[1.0]*n; x must have len >= 2"""100 """evaluates an N-dimensional Rosenbrock derivative for a list of coeffs 101 102 The minimum is f'(x)=[0.0]*n at x=[1.0]*n, where len(x) >= 2.""" 55 103 l = len(coeffs) 56 104 x = [0]*l #XXX: ensure that there are 2 coefficients ? … … 67 115 68 116 def hessian(self, coeffs): 69 """evaluates n-dimensional Rosenbrock hessian for the given coeffs70 71 coeffs must have len >= 2"""117 """evaluates an N-dimensional Rosenbrock hessian for the given coeffs 118 119 The function f''(x) requires len(x) >= 2.""" 72 120 x = atleast_1d(coeffs) 73 121 H = diag(-400*x[:-1],1) - diag(400*x[:-1],-1) … … 80 128 81 129 def hessian_product(self, coeffs, p): 82 """evaluates n-dimensional Rosenbrock hessian product for the given coeffs 83 84 both p and coeffs must have len >= 2""" 130 """evaluates an N-dimensional Rosenbrock hessian product 131 for p and the given coeffs 132 133 The hessian product requires both p and coeffs to have len >= 2.""" 85 134 #XXX: not well-tested 86 135 p = atleast_1d(p) … … 93 142 return Hp 94 143 144 minimizers = [1.] #NOTE: minima in lower dimensions occur along the ridge 95 145 pass 96 146 97 147 98 148 class Step(AbstractFunction): 99 """De Jong's step function: 100 The third De Jong function, Equation (19) of [2]""" 101 102 def __init__(self): 103 AbstractFunction.__init__(self) 104 return 105 106 def function(self,coeffs): 107 """evaluates n-dimensional De Jong step function for a list of coeffs 108 109 minimum is f(x)=0.0 at xi=-5-n where n=[0.0,0.12]""" 149 __doc__ = \ 150 """a De Jong step function generator 151 152 De Jong's step function [1,2,3] has several plateaus, which pose 153 difficulty for many optimization algorithms. Degenerate global 154 minima occur for all x_i on the lowest plateau, with degenerate 155 local minima on all other plateaus. 156 157 The generated function f(x) is a modified version of equation (19) 158 of [2], where len(x) >= 0. 159 """ + _doc 160 def __init__(self, ndim=5): # is n-dimensional (n=5 in ref) 161 AbstractFunction.__init__(self, ndim=ndim) 162 return 163 164 def function(self,coeffs): 165 """evaluates an N-dimensional step function for a list of coeffs 166 167 f(x) = f_0(x) + p_i(x), with i=0,1 168 169 Where for abs(x_i) <= 5.12: 170 f_0(x) = 30 + \sum_(i=0)^(N-1) \floor x_i 171 and for x_i > 5.12: 172 p_0(x) = 30 * (1 + (x_i - 5.12)) 173 and for x_i < 5.12: 174 p_1(x) = 30 * (1 + (5.12 - x_i)) 175 Otherwise, f_0(x) = 0 and p_i(x)=0 for i=0,1. 176 177 Inspect with mystic_model_plotter using:: 178 mystic.models.step -b "-10:10:.2, -10:10:.2" -d -x 1 179 180 The minimum is f(x)=(30 - 6*N) for all x_i=[-5.12,-5)""" 110 181 f = 30. 111 182 for c in coeffs: … … 118 189 return f 119 190 120 # def forward(self,pts): 121 # """n-dimensional De Jong step; returns f(xi,yi,...) for pts=(x,y,...)""" 122 # return AbstractFunction.forward(self,pts) 123 191 minimizers = None #FIXME: degenerate minimum... [-5.00000001]to[-5.12000000] 192 # minimum is f(x)=(30 - 6*N) for all x_i=[-5.12,-5.00000001]""" 124 193 pass 125 194 126 195 127 196 class Quartic(AbstractFunction): 128 """De Jong's quartic function: 129 The modified fourth De Jong function, Equation (20) of [2]""" 130 131 def __init__(self): 132 AbstractFunction.__init__(self) 133 return 134 135 def function(self,coeffs): 136 """evaluates n-dimensional De Jong quartic function for a list of coeffs 137 138 minimum is f(x)=random, but statistically at xi=0""" 197 __doc__ = \ 198 """a De Jong quartic function generator 199 200 De Jong's quartic function [1,2,3] is designed to test the 201 behavior of minimizers in the presence of noise. The function's 202 global minumum depends on the expectation value of a random 203 variable, and also includes several randomly distributed local 204 minima. 205 206 The generated function f(x) is a modified version of equation (20) 207 of [2], where len(x) >= 0. 208 """ + _doc 209 def __init__(self, ndim=30): # is n-dimensional (n=30 in ref) 210 AbstractFunction.__init__(self, ndim=ndim) 211 return 212 213 def function(self,coeffs): 214 """evaluates an N-dimensional quartic function for a list of coeffs 215 216 f(x) = \sum_(i=0)^(N-1) (x_(i)^4 * (i+1) + k_i) 217 218 Where k_i is a random variable with uniform distribution bounded by [0,1). 219 220 Inspect with mystic_model_plotter using:: 221 mystic.models.quartic -b "-3:3:.1, -3:3:.1" -d -x 1 222 223 The minimum is f(x)=N*E[k] for x_i=0.0, where E[k] is the expectation 224 of k, and thus E[k]=0.5 for a uniform distribution bounded by [0,1).""" 139 225 f = 0. 140 226 for j, c in enumerate(coeffs): … … 142 228 return f 143 229 144 # def forward(self,pts): 145 # """n-dimensional De Jong quartic; returns f(xi,yi,...) for pts=(x,y,...)""" 146 # return AbstractFunction.forward(self,pts) 147 230 minimizers = None #FIXME: statistical minimum... of f(x) <= N*0.5 148 231 pass 149 232 150 233 151 234 class Shekel(AbstractFunction): 152 """Shekel's function: 153 The modified fifth De Jong function, Equation (21) of [2]""" 154 155 def __init__(self): 156 AbstractFunction.__init__(self) 157 return 158 159 def function(self,coeffs): 160 """evaluates 2-D Shekel's function at (x,y) 161 162 minimum is f(x)=0.0 at x(-32,-32)""" 235 __doc__ = \ 236 """a Shekel's Foxholes function generator 237 238 Shekel's Foxholes function [1,2,3] has a generally flat surface 239 with several narrow wells. The function's global minimum is at 240 (-32, -32), with local minima at (i,j) in (-32, -16, 0, 16, 32). 241 242 The generated function f(x) is a modified version of equation (21) 243 of [2], where len(x) == 2. 244 """ + _doc 245 def __init__(self, ndim=2): 246 AbstractFunction.__init__(self, ndim=ndim) 247 return 248 249 def function(self,coeffs): 250 """evaluates a 2-D Shekel's Foxholes function for a list of coeffs 251 252 f(x) = 1 / (0.002 + f_0(x)) 253 254 Where: 255 f_0(x) = \sum_(i=0)^(24) 1 / (i + \sum_(j=0)^(1) (x_j - a_ij)^(6)) 256 with a_ij=(-32,-16,0,16,32). 257 for j=0 and i=(0,1,2,3,4), a_i0=a_k0 with k=i \mod 5 258 also j=1 and i=(0,5,10,15,20), a_i1=a_k1 with k=i+k' and k'=(1,2,3,4). 259 260 Inspect with mystic_model_plotter using:: 261 mystic.models.shekel -b "-50:50:1, -50:50:1" -d -x 1 262 263 The minimum is f(x)=0 for x=(-32,-32)""" 163 264 A = [-32., -16., 0., 16., 32.] 164 265 a1 = A * 5 … … 168 269 r = 0.0 169 270 for i in range(25): 170 r += 1.0/ (1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) + 1e-15) 271 # r += 1.0/ (1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) + 1e-15) 272 z = 1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) 273 if z: r += 1.0/z 274 else: r += inf 171 275 return 1.0/(0.002 + r) 172 276 173 # def forward(self,pts): 174 # """2-D Shekel; returns f(xi,yi) for pts=(x,y)""" 175 # return AbstractFunction.forward(self,pts) 176 177 pass 277 minimizers = [(j,i) for (i,j) in sorted(list(permutations(range(-32,33,16),2))+[(i,i) for i in range(-32,33,16)])] 278 pass 279 280 # cleanup 281 del _doc 178 282 179 283 # prepared instances 180 rosen = Rosenbrock() 181 step = Step() 182 quartic = Quartic() 183 shekel = Shekel() 284 sphere = Sphere().function 285 rosen = Rosenbrock().function 286 step = Step().function 287 quartic = Quartic().function 288 shekel = Shekel().function 184 289 185 290 # End of file -
mystic/models/griewangk.py
r713 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """ 9 Griewangk's function 8 __doc__ = _doc = """ 9 This is part of Storn's "Differential Evolution" test suite, as defined 10 in [2], with 'Griewangk' function definitions drawn from [3]. 10 11 11 12 References:: 12 [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient13 Heuristic for Global Optimization over Continuous Spaces. Journal of Global14 Optimization 11: 341-359, 1997.13 [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 14 Efficient Heuristic for Global Optimization over Continuous Spaces" 15 Journal of Global Optimization 11: 341-359, 1997. 15 16 16 [2] Storn, R. and Price, K. 17 (Same title as above, but as a technical report.) 18 http://www.icsi.berkeley.edu/~storn/deshort1.ps 17 [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 18 Efficient Heuristic for Global Optimization over Continuous Spaces" 19 TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 20 21 [3] Griewangk, A.O. "Generalized Descent for Global Optimization" 22 Journal of Optimization Theory and Applications 34: 11-39, 1981. 19 23 """ 20 24 from abstract_model import AbstractFunction … … 24 28 25 29 class Griewangk(AbstractFunction): 26 """Griewangk function:27 a multi-minima function, Equation (23) of [2]""" 30 __doc__ = \ 31 """a Griewangk's function generator 28 32 29 def __init__(self): 30 AbstractFunction.__init__(self) 33 Griewangk's function [1,2,3] is a multi-dimensional cosine 34 function that provides several periodic local minima, with 35 the global minimum at the origin. The local minima are 36 fractionally more shallow than the global minimum, such that 37 when viewed at a very coarse scale the function appears as 38 a multi-dimensional parabola similar to De Jong's sphere. 39 40 The generated function f(x) is a modified version of equation (23) 41 of [2], where len(x) >= 0. 42 """ + _doc 43 def __init__(self, ndim=10): # is n-dimensional (n=10 in ref) 44 AbstractFunction.__init__(self, ndim=ndim) 31 45 return 32 46 33 47 def function(self,coeffs): 34 """evaluates the Griewangkfunction for a list of coeffs48 """evaluates an N-dimensional Griewangk's function for a list of coeffs 35 49 36 minimum is f(x)=0.0 at xi=0.0""" 37 # ensure that there are 10 coefficients 38 x = [0]*10 39 x[:len(coeffs)]=coeffs 50 f(x) = f_0(x) - f_1(x) + 1 51 52 Where: 53 f_0(x) = \sum_(i=0)^(N-1) x_(i)^(2) / 4000. 54 and: 55 f_1(x) = \prod_(i=0)^(N-1) \cos( x_i / (i+1)^(1/2) ) 56 57 Inspect with mystic_model_plotter using:: 58 mystic.models.griewangk -b "-10:10:.1, -10:10:.1" -d -x 5 59 60 The minimum is f(x)=0.0 for x_i=0.0""" 40 61 #x = asarray(x) #XXX: converting to numpy.array slows by 10x 41 42 term1 = sum([c*c for c in x])/4000 62 term1 = sum([c*c for c in coeffs])/4000. 43 63 term2 = 1 44 for i in range( 10):45 term2 = term2 * cos( x[i] / sqrt(i+1.0) )64 for i in range(len(coeffs)): 65 term2 = term2 * cos( coeffs[i] / sqrt(i+1.0) ) 46 66 return term1 - term2 + 1 47 67 48 68 49 # def forward(self,pts): 50 # """10-D Griewangk; returns f(xi,yi,...) for pts=(x,y,...)""" 51 # return AbstractFunction.forward(self,pts) 52 69 minimizers = [0.] #XXX: there are many periodic local minima 53 70 pass 54 71 72 # cleanup 73 del _doc 55 74 56 75 # prepared instances 57 griewangk = Griewangk() 76 griewangk = Griewangk().function 58 77 59 78 # End of file -
mystic/models/poly.py
r713 r751 10 10 11 11 References:: 12 [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient13 Heuristic for Global Optimization over Continuous Spaces. Journal of Global14 Optimization 11: 341-359, 1997.12 [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 13 Efficient Heuristic for Global Optimization over Continuous Spaces" 14 Journal of Global Optimization 11: 341-359, 1997. 15 15 16 [2] Storn, R. and Price, K. 17 (Same title as above, but as a technical report.) 18 http://www.icsi.berkeley.edu/~storn/deshort1.ps 16 [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 17 Efficient Heuristic for Global Optimization over Continuous Spaces" 18 TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 19 20 [3] Storn, R. "Constrained Optimization" Dr. Dobb's Journal, May, 21 119-123, 1995. 19 22 """ 20 23 from abstract_model import AbstractModel -
mystic/models/trott.py
r713 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """ 9 the fOsc3D Mathematica function 8 __doc__ = _doc = """ 9 This is drawn from the Mathematica GuideBook's example suite, with the 10 'fOsc3D' function definition found in [1]. 10 11 11 12 References:: 12 [4] Mathematica guidebook 13 [1] Trott, M. "The Mathematica GuideBook for Numerics", Springer-Verlag, 14 New York, 2006. 13 15 """ 14 16 from abstract_model import AbstractFunction … … 17 19 18 20 class fOsc3D(AbstractFunction): 19 """fOsc3D Mathematica function:20 fOsc3D[x_,y_] := -4 Exp[(-x^2 - y^2)] + Sin[6 x] Sin[5 y]""" 21 __doc__ = \ 22 """a fOsc3D function generator 21 23 22 def __init__(self): 23 AbstractFunction.__init__(self) 24 A fOsc3D function [1] for positive x_1 values yields 25 small sinusoidal oscillations on a flat plane, where 26 a sinkhole containing the global minimum and a few local 27 minima is found in a small region near the origin. 28 For negative x_1 values, a parabolic penalty is applied 29 that decreases as the x_1 appoaches zero. 30 31 The generated function f(x) is identical to equation (75) 32 of section 1.10 of [1], and requires len(x) == 2. 33 """ + _doc 34 def __init__(self, ndim=2): # is 2-dimensional 35 AbstractFunction.__init__(self, ndim=ndim) 24 36 return 25 37 … … 27 39 """evaluates the fOsc3D function for a list of coeffs 28 40 29 minimum is f(x)=? at x=(?,?)""" 41 f(x) = f_0(x) + p(x) 42 43 Where: 44 f_0(x) = -4 * \exp(-x_(0)^2 - x_(1)^2) + \sin(6*x_(0)) * \sin(5*x_(1)) 45 with for x_1 < 0: 46 p(x) = 100.*x_(1)^2 47 and otherwise: 48 p(x) = 0. 49 50 Inspect with mystic_model_plotter using:: 51 mystic.models.fosc3d -b "-5:5:.1, 0:5:.1" -d 52 53 The minimum is f(x)=-4.501069742528923 at x=(-0.215018, 0.240356)""" 30 54 x,y = coeffs 31 55 func = -4. * exp( -x*x - y*y ) + sin(6. * x) * sin(5. *y) … … 34 58 return func + penalty 35 59 36 # def forward(self,pts): 37 # """2-D fOsc3D; returns f(xi,yi) for pts=(x,y)""" 38 # return AbstractFunction.forward(self,pts) 39 60 minimizers = [(-0.215018, 0.240356)] #XXX: there are many local minima 40 61 pass 41 62 63 # cleanup 64 del _doc 42 65 43 66 # prepared instances 44 fosc3d = fOsc3D() 67 fosc3d = fOsc3D().function 45 68 46 69 # End of file -
mystic/models/wavy.py
r726 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """ 9 simple sine-based multi-minima functions 8 __doc__ = _doc = """ 9 Multi-minima example functions with vector outputs, which require 10 a 'reducing' function to provide scalar return values. 10 11 11 12 References:: … … 18 19 from numpy import sin, pi 19 20 20 class Wavy1(AbstractFunction): 21 """Wavy function #1:22 a simple multi-minima function""" 21 class Wavy1(AbstractFunction): #XXX: not a standard test function...? 22 __doc__ = \ 23 """a wavy1 function generator 23 24 24 def __init__(self): 25 AbstractFunction.__init__(self) 25 A wavy1 function has a vector return value, and oscillates 26 similarly to x+\sin(x) in each direction. When a reduction 27 function, like 'numpy.add' is applied, the surface can be 28 visualized. The global minimum is at the center of a 29 cross-hairs running along x_i = -pi, with periodic local 30 minima in each direction. 31 32 The generated function f(x) requires len(x) > 0, and a 33 reducing function for use in most optimizers. 34 """ + _doc 35 def __init__(self, ndim=2): # is n-dimensional 36 AbstractFunction.__init__(self, ndim=ndim) 26 37 return 27 38 28 39 def function(self,coeffs): 29 """evaluates the Wavy1 function for a list of coeffs40 """evaluates the wavy1 function for a list of coeffs 30 41 31 minimum is f(x)=0.0 at xi=-3.141592653589793""" 42 f(x) = \abs(x + 3*\sin(x + \pi) + \pi) 43 44 Inspect with mystic_model_plotter using:: 45 mystic.models.wavy1 -b "-20:20:.5, -20:20:.5" -d -r numpy.add 46 47 The minimum is f(x)=0.0 at x_i=-pi for all i""" 32 48 x = asarray(coeffs) #XXX: must be numpy.array 33 49 return abs(x+3.*sin(x+pi)+pi) 34 50 35 # def forward(self,pts): 36 # """n-D Wavy; returns f(xi,yi,...) for pts=(x,y,...)""" 37 # return AbstractFunction.forward(self,pts) 38 51 minimizers = [-pi] 39 52 pass 40 53 41 54 42 class Wavy2(Wavy1): 43 """Wavy function #2: 44 a simple multi-minima function""" 55 class Wavy2(AbstractFunction): #XXX: not a standard test function...? 56 """a wavy2 function generator 45 57 46 def __init__(self): 47 Wavy1.__init__(self) 58 A wavy2 function has a vector return value, and oscillates 59 similarly to \sin(x) in each direction. When a reduction 60 function, like 'numpy.add' is applied, the surface can be 61 visualized. There are degenerate global minima which are 62 periodic at 2*\pi, and similarly periodic local minima 63 at nearly the same location and magnitude. 64 65 The generated function f(x) requires len(x) > 0, and a 66 reducing function for use in most optimizers. 67 """ + _doc 68 def __init__(self, ndim=2): # is n-dimensional 69 AbstractFunction.__init__(self, ndim=ndim) 48 70 return 49 71 50 72 def function(self,coeffs): 51 """evaluates the Wavy2 function for a list of coeffs73 """evaluates the wavy2 function for a list of coeffs 52 74 53 (degenerate) minimum is f(x)=-6.9 at xi=-26.92""" 75 f(x) = 4*\sin(x)+\sin(4*x)+\sin(8*x)+\sin(16*x)+\sin(32*x)+\sin(64*x) 76 77 Inspect with mystic_model_plotter using:: 78 mystic.models.wavy2 -b "-10:10:.2, -10:10:.2" -d -r numpy.add 79 80 The function has degenerate global minima of f(x)=-6.987594 81 at x_i = 4.489843526 + 2*k*pi for all i, and k is an integer""" 54 82 x = asarray(coeffs) #XXX: must be a numpy.array 55 return 4 *sin(x)+sin(4*x) +sin(8*x)+sin(16*x)+sin(32*x)+sin(64*x)83 return 4*sin(x)+sin(4*x)+sin(8*x)+sin(16*x)+sin(32*x)+sin(64*x) 56 84 85 minimizers = None #FIXME: degenerate minimum... 86 # minimum is ??? 57 87 pass 58 88 89 # cleanup 90 del _doc 59 91 60 92 # prepared instances 61 wavy1 = Wavy1() 62 wavy2 = Wavy2() 63 93 wavy1 = Wavy1().function 94 wavy2 = Wavy2().function 64 95 65 96 # End of file -
mystic/models/zimmermann.py
r713 r751 6 6 # License: 3-clause BSD. The full license text is available at: 7 7 # - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 8 """ 9 Zimmermann's function 8 __doc__ = _doc = """ 9 This is part of Storn's "Differential Evolution" test suite, as defined 10 in [2], with 'Zimmermann' function definitions drawn from [3]. 10 11 11 12 References:: 12 [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient13 Heuristic for Global Optimization over Continuous Spaces. Journal of Global14 Optimization 11: 341-359, 1997.13 [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 14 Efficient Heuristic for Global Optimization over Continuous Spaces" 15 Journal of Global Optimization 11: 341-359, 1997. 15 16 16 [2] Storn, R. and Price, K. 17 (Same title as above, but as a technical report.) 18 http://www.icsi.berkeley.edu/~storn/deshort1.ps 17 [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 18 Efficient Heuristic for Global Optimization over Continuous Spaces" 19 TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 20 21 [3] Zimmermann, W. "Operations Research" Oldenbourg Munchen, Wien, 1990. 19 22 """ 20 23 from abstract_model import AbstractFunction 21 24 22 25 class Zimmermann(AbstractFunction): 23 """Zimmermann function:24 a non-continuous function, Equation (24-26) of [2]""" 26 __doc__ = \ 27 """a Zimmermann function generator 25 28 26 def __init__(self): 27 AbstractFunction.__init__(self) 29 A Zimmermann function [1,2,3] poses difficulty for minimizers 30 as the minimum is located at the corner of the constrained region. 31 A penalty is applied to all values outside the constrained region, 32 creating a local minimum. 33 34 The generated function f(x) is a modified version of equation (24-26) 35 of [2], and requires len(x) == 2. 36 """ + _doc 37 def __init__(self, ndim=2): 38 AbstractFunction.__init__(self, ndim=ndim) 28 39 return 29 40 30 41 def function(self,coeffs): 31 """evaluates theZimmermann function for a list of coeffs42 """evaluates a Zimmermann function for a list of coeffs 32 43 33 minimum is f(x)=0.0 at x=(7.0,2.0)""" 44 f(x) = max(f_0(x), p_i(x)), with i = 0,1,2,3 45 46 Where: 47 f_0(x) = 9 - x_0 - x_1 48 with for x_0 < 0: 49 p_0(x) = -100 * x_0 50 and for x_1 < 0: 51 p_1(x) = -100 * x_1 52 and for c_2(x) > 16 and c_3(x) > 14: 53 p_i(x) = 100 * c_i(x), with i = 2,3 54 c_2(x) = (x_0 - 3)^2 + (x_1 - 2)^2 55 c_3(x) = x_0 * x_1 56 Otherwise, p_i(x)=0 for i=0,1,2,3 and c_i(x)=0 for i=2,3. 57 58 Inspect with mystic_model_plotter using:: 59 mystic.models.zimmermann -b "-5:10:.1, -5:10:.1" -d -x 1 60 61 The minimum is f(x)=0.0 at x=(7.0,2.0)""" 34 62 x0, x1 = coeffs #must provide 2 values (x0,y0) 35 63 f8 = 9 - x0 - x1 64 #XXX: apply penalty p(k) = 100 + 100*k; k = |f(x) - c(x)| 36 65 c0,c1,c2,c3 = 0,0,0,0 37 66 if x0 < 0: c0 = -100 * x0 … … 42 71 return max(f8,c0,c1,c2,c3) 43 72 44 # def forward(self,pts): 45 # """2-D Zimmermann; returns f(xi,yi) for pts=(x,y)""" 46 # return AbstractFunction.forward(self,pts) 47 73 minimizers = [(7., 2.), (2.35477650, 5.94832200)] 74 #minima = [0.0, 0.69690150] 48 75 pass 49 76 77 # cleanup 78 del _doc 50 79 51 80 # prepared instances 52 zimmermann = Zimmermann() 81 zimmermann = Zimmermann().function 53 82 54 83 # End of file -
mystic/scripts/mystic_model_plotter.py
r747 r751 170 170 else: 171 171 raise ValueError("invalid format string: '%s'" % ','.join(option)) 172 if not x.size or not y.size: 173 raise ValueError("invalid format string: '%s'" % ','.join(option)) 172 174 return x,y 173 175 … … 344 346 parser = OptionParser(usage=__doc__) 345 347 parser.add_option("-b","--bounds",action="store",dest="bounds",\ 346 metavar="STR",default=" 0:1:.1, 0:1:.1",348 metavar="STR",default="-5:5:.1, -5:5:.1", 347 349 help="indicator string to set plot bounds and density") 348 350 parser.add_option("-l","--label",action="store",dest="label",\ … … 386 388 options = parsed_opts.bounds # format is "-1:10:.1, -1:10:.1, 1.0" 387 389 except: 388 options = " 0:1:.1, 0:1:.1"390 options = "-5:5:.1, -5:5:.1" 389 391 390 392 try: # plot using filled contours -
mystic/tests/solver_test_suite.py
r735 r751 1699 1699 x1 = x[0] 1700 1700 x2 = x[1] 1701 return -20.*sin( 0.1 + ((x1 - 4.)**2 + (x2 - 4.)**2)**(0.5))/ \1702 ( 0.1 + ((x1 - 4.)**2 + (x2 - 4.)**2)**0.5)1701 return -20.*sin((0.1 + (x1 - 4.)**2 + (x2 - 4.)**2)**(0.5))/ \ 1702 ((0.1 + (x1 - 4.)**2 + (x2 - 4.)**2)**0.5) 1703 1703 self.costfunction = venkataraman_91 1704 1704 self.ND = 2
Note: See TracChangeset
for help on using the changeset viewer.