Changeset 766
- Timestamp:
- 10/23/14 15:06:42 (19 months ago)
- Location:
- mystic
- Files:
-
- 2 deleted
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
mystic/examples/mpl_corana.py
r736 r766 15 15 from mystic.tools import getch 16 16 17 from mystic.models.corana import corana1d as Corana1 17 from mystic.models.storn import Corana 18 Corana1 = Corana(1) 18 19 19 20 x = numpy.arange(-2., 2., 0.01) -
mystic/examples/test_corana.py
r723 r766 25 25 random.seed(123) 26 26 27 from mystic.models import corana as Corana 28 from mystic.models.corana import corana1d as Corana1 27 from mystic.models import corana 28 from mystic.models.storn import Corana as Corana1 29 corana1 = Corana1(1) 29 30 30 31 ND = 4 … … 38 39 solver.SetEvaluationLimits(generations=MAX_GENERATIONS) 39 40 40 solver.Solve( Corana, termination=VTR(0.00000001), strategy=Rand1Exp,\41 solver.Solve(corana, termination=VTR(0.00000001), strategy=Rand1Exp,\ 41 42 CrossProbability=0.5, ScalingFactor=0.9) 42 43 … … 58 59 import random 59 60 print "\nScipy: " 60 sol = fmin( Corana, [random.random() for j in range(4)], full_output=0, retall=1)61 sol = fmin(corana, [random.random() for j in range(4)], full_output=0, retall=1) 61 62 print "solution: ", sol[-1][0] 62 63 print "\nCorana 1 with Scipy" 63 sol = fmin( Corana1, [random.random()], full_output=1, retall=1)64 sol = fmin(corana1, [random.random()], full_output=1, retall=1) 64 65 print "solution: ", sol[-1][0] 65 66 except: -
mystic/models/__init__.py
r752 r766 76 76 # functions 77 77 from dejong import sphere, rosen, step, quartic, shekel 78 from corana import corana78 from storn import corana, griewangk, zimmermann 79 79 from wolfram import fosc3d, nmin51 80 from griewangk import griewangk81 from zimmermann import zimmermann82 80 from nag import peaks 83 81 from venkataraman import venkat91 -
mystic/models/storn.py
r751 r766 8 8 __doc__ = _doc = """ 9 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 in [2], with 'Corana' function definitions drawn from [3,4], 'Griewangk' 11 function definitions drawn from [5], and 'Zimmermann' function definitions 12 drawn from [6]. 11 13 12 14 References:: … … 26 28 'Simulated Annealing Algorithm'" ACM Transactions on Mathematical 27 29 Software, March, 272-280, 1987. 30 31 [5] Griewangk, A.O. "Generalized Descent for Global Optimization" 32 Journal of Optimization Theory and Applications 34: 11-39, 1981. 33 34 [6] Zimmermann, W. "Operations Research" Oldenbourg Munchen, Wien, 1990. 28 35 """ 29 36 from abstract_model import AbstractFunction 30 37 31 38 from numpy import asarray 32 from math import pow 39 from math import pow, cos, sqrt 33 40 from numpy import sign, floor 34 41 … … 94 101 pass 95 102 103 class Griewangk(AbstractFunction): 104 __doc__ = \ 105 """a Griewangk's function generator 106 107 Griewangk's function [1,2,5] is a multi-dimensional cosine 108 function that provides several periodic local minima, with 109 the global minimum at the origin. The local minima are 110 fractionally more shallow than the global minimum, such that 111 when viewed at a very coarse scale the function appears as 112 a multi-dimensional parabola similar to De Jong's sphere. 113 114 The generated function f(x) is a modified version of equation (23) 115 of [2], where len(x) >= 0. 116 """ + _doc 117 def __init__(self, ndim=10): # is n-dimensional (n=10 in ref) 118 AbstractFunction.__init__(self, ndim=ndim) 119 return 120 121 def function(self,coeffs): 122 """evaluates an N-dimensional Griewangk's function for a list of coeffs 123 124 f(x) = f_0(x) - f_1(x) + 1 125 126 Where: 127 f_0(x) = \sum_(i=0)^(N-1) x_(i)^(2) / 4000. 128 and: 129 f_1(x) = \prod_(i=0)^(N-1) \cos( x_i / (i+1)^(1/2) ) 130 131 Inspect with mystic_model_plotter using:: 132 mystic.models.griewangk -b "-10:10:.1, -10:10:.1" -d -x 5 133 134 The minimum is f(x)=0.0 for x_i=0.0""" 135 #x = asarray(x) #XXX: converting to numpy.array slows by 10x 136 term1 = sum([c*c for c in coeffs])/4000. 137 term2 = 1 138 for i in range(len(coeffs)): 139 term2 = term2 * cos( coeffs[i] / sqrt(i+1.0) ) 140 return term1 - term2 + 1 141 142 143 minimizers = [0.] #XXX: there are many periodic local minima 144 pass 145 146 class Zimmermann(AbstractFunction): 147 __doc__ = \ 148 """a Zimmermann function generator 149 150 A Zimmermann function [1,2,6] poses difficulty for minimizers 151 as the minimum is located at the corner of the constrained region. 152 A penalty is applied to all values outside the constrained region, 153 creating a local minimum. 154 155 The generated function f(x) is a modified version of equation (24-26) 156 of [2], and requires len(x) == 2. 157 """ + _doc 158 def __init__(self, ndim=2): 159 AbstractFunction.__init__(self, ndim=ndim) 160 return 161 162 def function(self,coeffs): 163 """evaluates a Zimmermann function for a list of coeffs 164 165 f(x) = max(f_0(x), p_i(x)), with i = 0,1,2,3 166 167 Where: 168 f_0(x) = 9 - x_0 - x_1 169 with for x_0 < 0: 170 p_0(x) = -100 * x_0 171 and for x_1 < 0: 172 p_1(x) = -100 * x_1 173 and for c_2(x) > 16 and c_3(x) > 14: 174 p_i(x) = 100 * c_i(x), with i = 2,3 175 c_2(x) = (x_0 - 3)^2 + (x_1 - 2)^2 176 c_3(x) = x_0 * x_1 177 Otherwise, p_i(x)=0 for i=0,1,2,3 and c_i(x)=0 for i=2,3. 178 179 Inspect with mystic_model_plotter using:: 180 mystic.models.zimmermann -b "-5:10:.1, -5:10:.1" -d -x 1 181 182 The minimum is f(x)=0.0 at x=(7.0,2.0)""" 183 x0, x1 = coeffs #must provide 2 values (x0,y0) 184 f8 = 9 - x0 - x1 185 #XXX: apply penalty p(k) = 100 + 100*k; k = |f(x) - c(x)| 186 c0,c1,c2,c3 = 0,0,0,0 187 if x0 < 0: c0 = -100 * x0 188 if x1 < 0: c1 = -100 * x1 189 xx = (x0-3.)*(x0-3) + (x1-2.)*(x1-2) 190 if xx > 16: c2 = 100 * (xx-16) 191 if x0 * x1 > 14: c3 = 100 * (x0*x1-14.) 192 return max(f8,c0,c1,c2,c3) 193 194 minimizers = [(7., 2.), (2.35477650, 5.94832200)] 195 #minima = [0.0, 0.69690150] 196 pass 197 96 198 # cleanup 97 199 del _doc … … 99 201 # prepared instances 100 202 corana = Corana().function 203 griewangk = Griewangk().function 204 zimmermann = Zimmermann().function 101 205 102 206 # End of file
Note: See TracChangeset
for help on using the changeset viewer.