Changeset 760
- Timestamp:
- 10/04/14 18:52:54 (20 months ago)
- Location:
- mystic
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/_math/compressed.py
r713 r760 23 23 def index2binary(index, npts=None): 24 24 """convert a list of integers to a list of binary strings""" 25 if npts ==None: npts = max(index) + 125 if npts is None: npts = max(index) + 1 26 26 v = [binary(i) for i in index + [npts]] 27 27 v = [( (len(v[-1]) - len(i))*'0' + i)[::-1] for i in v][:-1] -
mystic/_math/legacydata.py
r713 r760 165 165 else: 166 166 self.raw.position = position 167 if value ==None: raise ValueError, "value not set for the datapoint"167 if value is None: raise ValueError, "value not set for the datapoint" 168 168 self.raw.value = value 169 if id ==None: id = self.__hash_id(self) #XXX: default id is hash id169 if id is None: id = self.__hash_id(self) #XXX: default id is hash id 170 170 self.id = id 171 171 self.cone = lipschitzcone(self,lipschitz) … … 617 617 # apply filter(s) 618 618 from numpy import asarray 619 if _filter !=None and filter != False:619 if _filter is not None and filter != False: 620 620 _filter = asarray(_filter) 621 621 _filter = _filter[_filter < len(pt)] 622 622 pt = [pt[i] for i in _filter] 623 if filter !=None and filter != False:623 if filter is not None and filter != False: 624 624 filter = asarray(filter) 625 625 filter = filter[filter < len(pt)] … … 648 648 if data.lipschitz: 649 649 file.write("# lipschitz: %s\n" % str(tuple(data.lipschitz)) ) 650 if filter !=None:650 if filter is not None: 651 651 file.write("# filter: %s\n" % str(filter)) 652 652 file.write("# ___id___ __value__ __coords__\n") -
mystic/_math/measures.py
r757 r760 73 73 tol -- weight tolerance, where any weight <= tol is considered zero 74 74 """ 75 if weights ==None:75 if weights is None: 76 76 return maximum(f, samples) 77 77 return maximum(f, support(samples, weights, tol)) … … 96 96 tol -- weight tolerance, where any weight <= tol is considered zero 97 97 """ 98 if weights ==None:98 if weights is None: 99 99 return minimum(f, samples) 100 100 return minimum(f, support(samples, weights, tol)) … … 109 109 tol -- weight tolerance, where any weight <= tol is ignored 110 110 """ 111 if weights ==None:111 if weights is None: 112 112 y = [f(x) for x in samples] 113 113 return mean(y, weights) … … 130 130 weights -- a list of sample weights 131 131 """ 132 if weights ==None:132 if weights is None: 133 133 weights = [1.0/float(len(samples))] * len(samples) 134 134 # get weighted sum … … 166 166 weights -- a list of sample weights 167 167 """ 168 if weights ==None:168 if weights is None: 169 169 weights = [1.0/float(len(samples))] * len(samples) 170 #if _mean ==None:170 #if _mean is None: 171 171 _mean = mean(samples, weights) 172 172 svar = [abs(s - _mean)**2 for s in samples] … … 394 394 """impose a mean on a list of points, using reweighting""" 395 395 ndim = len(samples) 396 if weights ==None:396 if weights is None: 397 397 weights = [1.0/ndim] * ndim 398 398 if solver is None or solver == 'fmin': … … 437 437 """impose a variance on a list of points, using reweighting""" 438 438 ndim = len(samples) 439 if weights ==None:439 if weights is None: 440 440 weights = [1.0/ndim] * ndim 441 441 if solver is None or solver == 'fmin': -
mystic/mystic/_symbolic.py
r713 r760 60 60 #XXX: use solve? or first if not in form xi = ... ? 61 61 if list_or_tuple_or_ndarray(variables): 62 if nvars !=None: variables = variables[:nvars]62 if nvars is not None: variables = variables[:nvars] 63 63 constraints = replace_variables(constraints, variables) 64 64 varname = '$' … … 69 69 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 70 70 else: ndim = 0 71 if nvars !=None: ndim = nvars71 if nvars is not None: ndim = nvars 72 72 73 73 eqns = constraints.splitlines() … … 181 181 #XXX: if constraints contain x0,x1,x3 for 'x', should x2 be in code,xlist? 182 182 if list_or_tuple_or_ndarray(variables): 183 if nvars !=None: variables = variables[:nvars]183 if nvars is not None: variables = variables[:nvars] 184 184 constraints = replace_variables(constraints, variables, markers='_') 185 185 varname = '_' … … 190 190 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 191 191 else: ndim = 0 192 if nvars !=None: ndim = nvars192 if nvars is not None: ndim = nvars 193 193 194 194 # split constraints_str into lists of left hand sides and right hand sides … … 284 284 from mystic.symbolic import replace_variables, get_variables 285 285 if list_or_tuple_or_ndarray(variables): 286 if nvars !=None: variables = variables[:nvars]286 if nvars is not None: variables = variables[:nvars] 287 287 constraints = replace_variables(constraint, variables, markers='_') 288 288 varname = '_' … … 297 297 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 298 298 else: ndim = 0 299 if nvars !=None: ndim = nvars299 if nvars is not None: ndim = nvars 300 300 301 301 # create function to replace "_" with original variables … … 450 450 from mystic.symbolic import replace_variables, get_variables 451 451 if list_or_tuple_or_ndarray(variables): 452 if nvars !=None: variables = variables[:nvars]452 if nvars is not None: variables = variables[:nvars] 453 453 _constraints = replace_variables(constraints, variables, '_') 454 454 varname = '_' … … 463 463 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 464 464 else: ndim = 0 465 if nvars !=None: ndim = nvars465 if nvars is not None: ndim = nvars 466 466 467 467 # create function to replace "_" with original variables … … 709 709 from mystic.symbolic import replace_variables, get_variables 710 710 if list_or_tuple_or_ndarray(variables): 711 if nvars !=None: variables = variables[:nvars]711 if nvars is not None: variables = variables[:nvars] 712 712 constraints = replace_variables(constraints, variables, '_') 713 713 varname = '_' … … 718 718 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 719 719 else: ndim = 0 720 if nvars !=None: ndim = nvars720 if nvars is not None: ndim = nvars 721 721 722 722 # create function to replace "_" with original variables -
mystic/mystic/abstract_ensemble_solver.py
r748 r760 220 220 else: 221 221 solver = self 222 if termination ==None:222 if termination is None: 223 223 termination = solver._termination 224 224 -
mystic/mystic/abstract_solver.py
r737 r760 313 313 return 314 314 #XXX: better to use 'defaultMin,defaultMax' or '-inf,inf' ??? 315 if min ==None: min = self._defaultMin316 if max ==None: max = self._defaultMax315 if min is None: min = self._defaultMin 316 if max is None: max = self._defaultMax 317 317 # when 'some' of the bounds are given as 'None', replace with default 318 318 for i in range(len(min)): 319 if min[i] ==None: min[i] = self._defaultMin[0]320 if max[i] ==None: max[i] = self._defaultMax[0]319 if min[i] is None: min[i] = self._defaultMin[0] 320 if max[i] is None: max[i] = self._defaultMax[0] 321 321 322 322 min = asarray(min); max = asarray(max) … … 378 378 - min, max: must be a sequence of length self.nDim 379 379 - each min[i] should be <= the corresponding max[i]""" 380 if min ==None: min = self._defaultMin381 if max ==None: max = self._defaultMax380 if min is None: min = self._defaultMin 381 if max is None: max = self._defaultMax 382 382 #if numpy.any(( asarray(min) > asarray(max) ),0): 383 383 # raise ValueError, "each min[i] must be <= the corresponding max[i]" … … 386 386 # when 'some' of the bounds are given as 'None', replace with default 387 387 for i in range(len(min)): 388 if min[i] ==None: min[i] = self._defaultMin[0]389 if max[i] ==None: max[i] = self._defaultMax[0]388 if min[i] is None: min[i] = self._defaultMin[0] 389 if max[i] is None: max[i] = self._defaultMax[0] 390 390 import random 391 391 #generate random initial values … … 406 406 from numpy.random import multivariate_normal 407 407 assert(len(mean) == self.nDim) 408 if var ==None:408 if var is None: 409 409 var = numpy.eye(self.nDim) 410 410 else: … … 537 537 termination conditions will be used. 538 538 """ 539 if termination ==None:539 if termination is None: 540 540 termination = self._termination 541 541 # check for termination messages … … 572 572 def _RegisterObjective(self, cost, ExtraArgs=None): 573 573 """decorate cost function with bounds, penalties, monitors, etc""" 574 if ExtraArgs ==None: ExtraArgs = ()574 if ExtraArgs is None: ExtraArgs = () 575 575 self._fcalls, cost = wrap_function(cost, ExtraArgs, self._evalmon) 576 576 if self._useStrictRange: … … 590 590 """HACK to enable not explicitly calling _RegisterObjective""" 591 591 args = None 592 if cost ==None: # 'use existing cost'592 if cost is None: # 'use existing cost' 593 593 cost,args = self._cost # use args, unless override with ExtraArgs 594 if ExtraArgs !=None: args = ExtraArgs595 if self._cost[0] ==None: # '_RegisterObjective not yet called'594 if ExtraArgs is not None: args = ExtraArgs 595 if self._cost[0] is None: # '_RegisterObjective not yet called' 596 596 if args is None: args = () 597 597 cost = self._RegisterObjective(cost, args) … … 607 607 """save solver state to a restart file""" 608 608 import dill 609 if filename ==None: # then check if already has registered file610 if self._state ==None: # then create a new one609 if filename is None: # then check if already has registered file 610 if self._state is None: # then create a new one 611 611 import tempfile 612 612 self._state = tempfile.mkstemp(suffix='.pkl')[-1] -
mystic/mystic/constraints.py
r721 r760 283 283 from mystic.termination import ChangeOverGeneration as COG 284 284 termination = COG() 285 if guess !=None:285 if guess is not None: 286 286 solver.SetInitialPoints(guess) #XXX: nice if 'diffev' also had methods 287 287 else: -
mystic/mystic/differential_evolution.py
r759 r760 202 202 def _RegisterObjective(self, cost, ExtraArgs=None): 203 203 """decorate cost function with bounds, penalties, monitors, etc""" 204 if ExtraArgs ==None: ExtraArgs = ()204 if ExtraArgs is None: ExtraArgs = () 205 205 self._fcalls, cost = wrap_function(cost, ExtraArgs, self._evalmon) 206 206 if self._useStrictRange: … … 349 349 def _RegisterObjective(self, cost, ExtraArgs=None): 350 350 """decorate cost function with bounds, penalties, monitors, etc""" 351 if ExtraArgs ==None: ExtraArgs = ()351 if ExtraArgs is None: ExtraArgs = () 352 352 #FIXME: EvaluationMonitor fails for MPI, throws error for 'pp' 353 353 from python_map import python_map -
mystic/mystic/monitors.py
r725 r760 220 220 y = " %f" % self._y[-1][best] 221 221 msg = "Generation %d has%s Chi-Squared:%s" % (self._step-1,who,y) 222 if id !=None: msg = "[id: %d] " % (id) + msg222 if id is not None: msg = "[id: %d] " % (id) + msg 223 223 print msg 224 224 if self._xinterval is not numpy.inf and \ … … 234 234 x = "\n %s" % self._x[-1][best] 235 235 msg = "Generation %d has%s fit parameters:%s" % (self._step-1,who,x) 236 if id !=None: msg = "[id: %d] " % (id) + msg236 if id is not None: msg = "[id: %d] " % (id) + msg 237 237 print msg 238 238 return … … 292 292 x = "%s" % xb 293 293 step = [self._step-1] 294 if id !=None: step.append(id)294 if id is not None: step.append(id) 295 295 self._file.write(" %s %s %s\n" % (tuple(step), y, x)) 296 296 self._file.close() … … 335 335 y = " %f" % self._y[-1][best] 336 336 msg = "Generation %d has%s Chi-Squared:%s" % (self._step-1,who,y) 337 if id !=None: msg = "[id: %d] " % (id) + msg337 if id is not None: msg = "[id: %d] " % (id) + msg 338 338 print msg 339 339 if self._vxinterval is not numpy.inf and \ … … 349 349 x = "\n %s" % self._x[-1][best] 350 350 msg = "Generation %d has%s fit parameters:%s" % (self._step-1,who,x) 351 if id !=None: msg = "[id: %d] " % (id) + msg351 if id is not None: msg = "[id: %d] " % (id) + msg 352 352 print msg 353 353 return -
mystic/mystic/solvers.py
r748 r760 80 80 def LoadSolver(filename=None, **kwds): 81 81 """load solver state from a restart file""" 82 if filename ==None: filename = kwds.get('_state', None)82 if filename is None: filename = kwds.get('_state', None) 83 83 #XXX: only allow a list override keys (lookup values from self) 84 # if filename ==None: filename = self._state85 # if filename ==None:84 # if filename is None: filename = self._state 85 # if filename is None: 86 86 # solver = self 87 87 # else: -
mystic/mystic/symbolic.py
r713 r760 48 48 eqstring = "" 49 49 # Equality constraints 50 if A != None and b !=None:50 if A is not None and b is not None: 51 51 # If one-dimensional and not in a nested list, add a list layer 52 52 try: … … 73 73 # Inequality constraints 74 74 ineqstring = "" 75 if G != None and h !=None:75 if G is not None and h is not None: 76 76 # If one-dimensional and not in a nested list, add a list layer 77 77 try: … … 252 252 #ndim = len(get_variables(src(func), variables)) 253 253 if list_or_tuple_or_ndarray(variables): 254 if nvars !=None: variables = variables[:nvars]254 if nvars is not None: variables = variables[:nvars] 255 255 constraints = replace_variables(constraints, variables) 256 256 varname = '$' … … 261 261 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 262 262 else: ndim = 0 263 if nvars !=None: ndim = nvars263 if nvars is not None: ndim = nvars 264 264 265 265 # Parse the constraints string … … 339 339 #ndim = len(get_variables(src(func), variables)) 340 340 if list_or_tuple_or_ndarray(variables): 341 if nvars !=None: variables = variables[:nvars]341 if nvars is not None: variables = variables[:nvars] 342 342 constraints = replace_variables(constraints, variables) 343 343 varname = '$' … … 348 348 if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 349 349 else: ndim = 0 350 if nvars !=None: ndim = nvars350 if nvars is not None: ndim = nvars 351 351 352 352 # Parse the constraints string -
mystic/mystic/tools.py
r753 r760 104 104 import sys, subprocess 105 105 if sys.stdin.isatty(): 106 if str !=None:106 if str is not None: 107 107 print str 108 108 subprocess.call('stty raw', shell=True) … … 111 111 return a 112 112 else: 113 if str !=None:113 if str is not None: 114 114 print str + " and press enter" 115 115 return raw_input()
Note: See TracChangeset
for help on using the changeset viewer.