source:
releases/mystic-0.2a1-patch2.diff
@
248
Revision 248, 6.3 KB checked in by mmckerns, 6 years ago (diff) |
---|
-
mystic-0.2a1/mystic/tools.py
132 132 self._y = [] 133 133 134 134 def __call__(self, x, y): 135 from numpy import ndarray 136 if isinstance(x,ndarray): x = list(x) 135 137 self._x.append(x) 136 138 self._y.append(y) 137 139 … … 153 155 """ 154 156 import numpy 155 157 def __init__(self, interval = 10, xinterval = numpy.inf): 156 Sow.__init__(self) 158 #Sow.__init__(self) 159 super(VerboseSow,self).__init__() 157 160 self._step = 0 158 161 self._yinterval = interval 159 162 self._xinterval = xinterval 160 163 return 161 164 def __call__(self, x, y): 162 165 from numpy import ndarray 163 Sow.__call__(self, x, y) 166 #Sow.__call__(self, x, y) 167 super(VerboseSow,self).__call__(x, y) 164 168 if isinstance(y,(list,ndarray)): 165 169 y = y[0] #XXX: get the "best" fit... which should be in y[0] 166 170 if isinstance(x[0],(list,ndarray)): #XXX: x should always be iterable … … 169 173 #print "Generation %d has best Chi-Squared: %s" % (self._step, y) 170 174 print "Generation %d has best Chi-Squared: %f" % (self._step, y) 171 175 if int(self._step % self._xinterval) == 0: 176 if isinstance(x,ndarray): x = list(x) 172 177 print "Generation %d has best fit parameters:\n %s" % (self._step, x) 173 178 self._step += 1 174 179 return … … 182 187 import numpy 183 188 def __init__(self, interval=1, filename='log.txt', new=False): 184 189 import datetime 185 Sow.__init__(self) 190 #Sow.__init__(self) 191 super(LoggingSow,self).__init__() 186 192 self._filename = filename 187 193 self._step = 0 188 194 self._yinterval = interval … … 197 203 def __call__(self, x, y): 198 204 self._file = open(self._filename,'a') 199 205 from numpy import ndarray 200 Sow.__call__(self, x, y) 206 #Sow.__call__(self, x, y) 207 super(LoggingSow,self).__call__(x, y) 201 208 if isinstance(y,(list,ndarray)): 202 209 y = y[0] #XXX: get the "best" fit... which should be in y[0] 203 210 if isinstance(x[0],(list,ndarray)): #XXX: x should always be iterable 204 211 x = x[0] #XXX: get the "best" fit... which should be in x[0] 205 212 if int(self._step % self._yinterval) == 0: 213 if isinstance(x,ndarray): x = list(x) 206 214 self._file.write(" %d %f %s\n" % (self._step, y, x)) 207 215 self._step += 1 208 216 self._file.close() -
mystic-0.2a1/mystic/differential_evolution.py
215 215 Further Inputs: 216 216 217 217 strategy -- the mutation strategy for generating new trial 218 solutions [default = Best1 Exp]218 solutions [default = Best1Bin] 219 219 CrossProbability -- the probability of cross-parameter mutations 220 [default = 0. 5]220 [default = 0.9] 221 221 ScalingFactor -- multiplier for the impact of mutations on the 222 trial solution [default = 0. 7]222 trial solution [default = 0.8] 223 223 callback -- an optional user-supplied function to call after each 224 224 iteration. It is called as callback(xk), where xk is 225 225 the current parameter vector. [default = None] … … 227 227 228 228 """ 229 229 #allow for inputs that don't conform to AbstractSolver interface 230 from mystic.strategy import Best1 Exp231 strategy=Best1 Exp#mutation strategy (see mystic.strategy)232 CrossProbability=0. 5#potential for parameter cross-mutation233 ScalingFactor=0. 7#multiplier for mutation impact230 from mystic.strategy import Best1Bin 231 strategy=Best1Bin #mutation strategy (see mystic.strategy) 232 CrossProbability=0.9 #potential for parameter cross-mutation 233 ScalingFactor=0.8 #multiplier for mutation impact 234 234 callback=None #user-supplied function, called after each step 235 235 disp=0 #non-zero to print convergence messages 236 236 if kwds.has_key('strategy'): strategy = kwds['strategy'] … … 399 399 Further Inputs: 400 400 401 401 strategy -- the mutation strategy for generating new trial 402 solutions [default = Best1 Exp]402 solutions [default = Best1Bin] 403 403 CrossProbability -- the probability of cross-parameter mutations 404 [default = 0. 5]404 [default = 0.9] 405 405 ScalingFactor -- multiplier for the impact of mutations on the 406 trial solution [default = 0. 7]406 trial solution [default = 0.8] 407 407 callback -- an optional user-supplied function to call after each 408 408 iteration. It is called as callback(xk), where xk is 409 409 the current parameter vector. [default = None] … … 415 415 disp -- non-zero to print convergence messages. 416 416 """ 417 417 #allow for inputs that don't conform to AbstractSolver interface 418 from mystic.strategy import Best1 Exp419 strategy=Best1 Exp#mutation strategy (see mystic.strategy)420 CrossProbability=0. 5#potential for parameter cross-mutation421 ScalingFactor=0. 7#multiplier for mutation impact418 from mystic.strategy import Best1Bin 419 strategy=Best1Bin #mutation strategy (see mystic.strategy) 420 CrossProbability=0.9 #potential for parameter cross-mutation 421 ScalingFactor=0.8 #multiplier for mutation impact 422 422 callback=None #user-supplied function, called after each step 423 423 disp=0 #non-zero to print convergence messages 424 424 if kwds.has_key('strategy'): strategy = kwds['strategy'] -
mystic-0.2a1/examples/test_mogi.py
114 114 # 115 115 desol, dstepmon = de_solve() 116 116 print "desol: ", desol 117 print "dstepmon 10: ", dstepmon.x[50]118 print "dstepmon 20: ", dstepmon.x[100]117 print "dstepmon 50: ", dstepmon.x[50] 118 print "dstepmon 100: ", dstepmon.x[100] 119 119 # 120 120 # this will try to use nelder_mean from a relatively "near by" point (very sensitive) 121 121 point = [1234., -500., 10., 0.001] # both cg and nm does fine
Note: See TracBrowser
for help on using the repository browser.