Changeset 760


Ignore:
Timestamp:
10/04/14 18:52:54 (20 months ago)
Author:
mmckerns
Message:

convert most eq and ne checks against None to is and is not

Location:
mystic
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • mystic/_math/compressed.py

    r713 r760  
    2323def index2binary(index, npts=None): 
    2424  """convert a list of integers to a list of binary strings""" 
    25   if npts == None: npts = max(index) + 1 
     25  if npts is None: npts = max(index) + 1 
    2626  v = [binary(i) for i in index + [npts]] 
    2727  v = [( (len(v[-1]) - len(i))*'0' + i)[::-1] for i in v][:-1] 
  • mystic/_math/legacydata.py

    r713 r760  
    165165    else: 
    166166      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" 
    168168      self.raw.value = value 
    169     if id == None: id = self.__hash_id(self)  #XXX: default id is hash id 
     169    if id is None: id = self.__hash_id(self)  #XXX: default id is hash id 
    170170    self.id = id 
    171171    self.cone = lipschitzcone(self,lipschitz) 
     
    617617  # apply filter(s) 
    618618  from numpy import asarray 
    619   if _filter != None and filter != False: 
     619  if _filter is not None and filter != False: 
    620620    _filter = asarray(_filter) 
    621621    _filter = _filter[_filter < len(pt)] 
    622622    pt = [pt[i] for i in _filter] 
    623   if filter != None and filter != False: 
     623  if filter is not None and filter != False: 
    624624    filter = asarray(filter) 
    625625    filter = filter[filter < len(pt)] 
     
    648648  if data.lipschitz: 
    649649    file.write("# lipschitz: %s\n" % str(tuple(data.lipschitz)) ) 
    650   if filter != None: 
     650  if filter is not None: 
    651651    file.write("# filter: %s\n" % str(filter)) 
    652652  file.write("# ___id___  __value__  __coords__\n") 
  • mystic/_math/measures.py

    r757 r760  
    7373    tol -- weight tolerance, where any weight <= tol is considered zero 
    7474""" 
    75   if weights == None: 
     75  if weights is None: 
    7676    return maximum(f, samples) 
    7777  return maximum(f, support(samples, weights, tol)) 
     
    9696    tol -- weight tolerance, where any weight <= tol is considered zero 
    9797""" 
    98   if weights == None: 
     98  if weights is None: 
    9999    return minimum(f, samples) 
    100100  return minimum(f, support(samples, weights, tol)) 
     
    109109    tol -- weight tolerance, where any weight <= tol is ignored 
    110110""" 
    111   if weights == None: 
     111  if weights is None: 
    112112    y = [f(x) for x in samples] 
    113113    return mean(y, weights) 
     
    130130    weights -- a list of sample weights 
    131131""" 
    132   if weights == None: 
     132  if weights is None: 
    133133    weights = [1.0/float(len(samples))] * len(samples) 
    134134  # get weighted sum 
     
    166166    weights -- a list of sample weights 
    167167""" 
    168   if weights == None: 
     168  if weights is None: 
    169169    weights = [1.0/float(len(samples))] * len(samples) 
    170  #if _mean == None: 
     170 #if _mean is None: 
    171171  _mean = mean(samples, weights) 
    172172  svar = [abs(s - _mean)**2 for s in samples] 
     
    394394    """impose a mean on a list of points, using reweighting""" 
    395395    ndim = len(samples) 
    396     if weights == None: 
     396    if weights is None: 
    397397        weights = [1.0/ndim] * ndim 
    398398    if solver is None or solver == 'fmin': 
     
    437437    """impose a variance on a list of points, using reweighting""" 
    438438    ndim = len(samples) 
    439     if weights == None: 
     439    if weights is None: 
    440440        weights = [1.0/ndim] * ndim 
    441441    if solver is None or solver == 'fmin': 
  • mystic/mystic/_symbolic.py

    r713 r760  
    6060    #XXX: use solve? or first if not in form xi = ... ? 
    6161    if list_or_tuple_or_ndarray(variables): 
    62         if nvars != None: variables = variables[:nvars] 
     62        if nvars is not None: variables = variables[:nvars] 
    6363        constraints = replace_variables(constraints, variables) 
    6464        varname = '$' 
     
    6969        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    7070        else: ndim = 0 
    71     if nvars != None: ndim = nvars 
     71    if nvars is not None: ndim = nvars 
    7272 
    7373    eqns = constraints.splitlines() 
     
    181181    #XXX: if constraints contain x0,x1,x3 for 'x', should x2 be in code,xlist? 
    182182    if list_or_tuple_or_ndarray(variables): 
    183         if nvars != None: variables = variables[:nvars] 
     183        if nvars is not None: variables = variables[:nvars] 
    184184        constraints = replace_variables(constraints, variables, markers='_') 
    185185        varname = '_' 
     
    190190        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    191191        else: ndim = 0 
    192     if nvars != None: ndim = nvars 
     192    if nvars is not None: ndim = nvars 
    193193 
    194194    # split constraints_str into lists of left hand sides and right hand sides 
     
    284284    from mystic.symbolic import replace_variables, get_variables 
    285285    if list_or_tuple_or_ndarray(variables): 
    286         if nvars != None: variables = variables[:nvars] 
     286        if nvars is not None: variables = variables[:nvars] 
    287287        constraints = replace_variables(constraint, variables, markers='_') 
    288288        varname = '_' 
     
    297297        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    298298        else: ndim = 0 
    299     if nvars != None: ndim = nvars 
     299    if nvars is not None: ndim = nvars 
    300300 
    301301    # create function to replace "_" with original variables 
     
    450450    from mystic.symbolic import replace_variables, get_variables 
    451451    if list_or_tuple_or_ndarray(variables): 
    452         if nvars != None: variables = variables[:nvars] 
     452        if nvars is not None: variables = variables[:nvars] 
    453453        _constraints = replace_variables(constraints, variables, '_') 
    454454        varname = '_' 
     
    463463        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    464464        else: ndim = 0 
    465     if nvars != None: ndim = nvars 
     465    if nvars is not None: ndim = nvars 
    466466 
    467467    # create function to replace "_" with original variables 
     
    709709    from mystic.symbolic import replace_variables, get_variables 
    710710    if list_or_tuple_or_ndarray(variables): 
    711         if nvars != None: variables = variables[:nvars] 
     711        if nvars is not None: variables = variables[:nvars] 
    712712        constraints = replace_variables(constraints, variables, '_') 
    713713        varname = '_' 
     
    718718        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    719719        else: ndim = 0 
    720     if nvars != None: ndim = nvars 
     720    if nvars is not None: ndim = nvars 
    721721 
    722722    # create function to replace "_" with original variables 
  • mystic/mystic/abstract_ensemble_solver.py

    r748 r760  
    220220        else: 
    221221            solver = self 
    222         if termination == None: 
     222        if termination is None: 
    223223            termination = solver._termination 
    224224 
  • mystic/mystic/abstract_solver.py

    r737 r760  
    313313            return 
    314314        #XXX: better to use 'defaultMin,defaultMax' or '-inf,inf' ??? 
    315         if min == None: min = self._defaultMin 
    316         if max == None: max = self._defaultMax 
     315        if min is None: min = self._defaultMin 
     316        if max is None: max = self._defaultMax 
    317317        # when 'some' of the bounds are given as 'None', replace with default 
    318318        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] 
    321321 
    322322        min = asarray(min); max = asarray(max) 
     
    378378    - min, max: must be a sequence of length self.nDim 
    379379    - each min[i] should be <= the corresponding max[i]""" 
    380         if min == None: min = self._defaultMin 
    381         if max == None: max = self._defaultMax 
     380        if min is None: min = self._defaultMin 
     381        if max is None: max = self._defaultMax 
    382382       #if numpy.any(( asarray(min) > asarray(max) ),0): 
    383383       #    raise ValueError, "each min[i] must be <= the corresponding max[i]" 
     
    386386        # when 'some' of the bounds are given as 'None', replace with default 
    387387        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] 
    390390        import random 
    391391        #generate random initial values 
     
    406406        from numpy.random import multivariate_normal 
    407407        assert(len(mean) == self.nDim) 
    408         if var == None: 
     408        if var is None: 
    409409            var = numpy.eye(self.nDim) 
    410410        else: 
     
    537537    termination conditions will be used. 
    538538        """ 
    539         if termination == None: 
     539        if termination is None: 
    540540            termination = self._termination 
    541541        # check for termination messages 
     
    572572    def _RegisterObjective(self, cost, ExtraArgs=None): 
    573573        """decorate cost function with bounds, penalties, monitors, etc""" 
    574         if ExtraArgs == None: ExtraArgs = () 
     574        if ExtraArgs is None: ExtraArgs = () 
    575575        self._fcalls, cost = wrap_function(cost, ExtraArgs, self._evalmon) 
    576576        if self._useStrictRange: 
     
    590590        """HACK to enable not explicitly calling _RegisterObjective""" 
    591591        args = None 
    592         if cost == None: # 'use existing cost' 
     592        if cost is None: # 'use existing cost' 
    593593            cost,args = self._cost # use args, unless override with ExtraArgs 
    594         if ExtraArgs != None: args = ExtraArgs 
    595         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' 
    596596            if args is None: args = () 
    597597            cost = self._RegisterObjective(cost, args) 
     
    607607        """save solver state to a restart file""" 
    608608        import dill 
    609         if filename == None: # then check if already has registered file 
    610             if self._state == None: # then create a new one 
     609        if filename is None: # then check if already has registered file 
     610            if self._state is None: # then create a new one 
    611611                import tempfile 
    612612                self._state = tempfile.mkstemp(suffix='.pkl')[-1] 
  • mystic/mystic/constraints.py

    r721 r760  
    283283        from mystic.termination import ChangeOverGeneration as COG 
    284284        termination = COG() 
    285     if guess != None: 
     285    if guess is not None: 
    286286        solver.SetInitialPoints(guess) #XXX: nice if 'diffev' also had methods 
    287287    else: 
  • mystic/mystic/differential_evolution.py

    r759 r760  
    202202    def _RegisterObjective(self, cost, ExtraArgs=None): 
    203203        """decorate cost function with bounds, penalties, monitors, etc""" 
    204         if ExtraArgs == None: ExtraArgs = () 
     204        if ExtraArgs is None: ExtraArgs = () 
    205205        self._fcalls, cost = wrap_function(cost, ExtraArgs, self._evalmon) 
    206206        if self._useStrictRange: 
     
    349349    def _RegisterObjective(self, cost, ExtraArgs=None): 
    350350        """decorate cost function with bounds, penalties, monitors, etc""" 
    351         if ExtraArgs == None: ExtraArgs = () 
     351        if ExtraArgs is None: ExtraArgs = () 
    352352       #FIXME: EvaluationMonitor fails for MPI, throws error for 'pp' 
    353353        from python_map import python_map 
  • mystic/mystic/monitors.py

    r725 r760  
    220220                y = " %f" % self._y[-1][best] 
    221221            msg = "Generation %d has%s Chi-Squared:%s" % (self._step-1,who,y) 
    222             if id != None: msg = "[id: %d] " % (id) + msg 
     222            if id is not None: msg = "[id: %d] " % (id) + msg 
    223223            print msg 
    224224        if self._xinterval is not numpy.inf and \ 
     
    234234                x = "\n %s" % self._x[-1][best] 
    235235            msg = "Generation %d has%s fit parameters:%s" % (self._step-1,who,x) 
    236             if id != None: msg = "[id: %d] " % (id) + msg 
     236            if id is not None: msg = "[id: %d] " % (id) + msg 
    237237            print msg 
    238238        return 
     
    292292                  x = "%s" % xb 
    293293            step = [self._step-1] 
    294             if id != None: step.append(id) 
     294            if id is not None: step.append(id) 
    295295            self._file.write("  %s     %s   %s\n" % (tuple(step), y, x)) 
    296296        self._file.close() 
     
    335335                y = " %f" % self._y[-1][best] 
    336336            msg = "Generation %d has%s Chi-Squared:%s" % (self._step-1,who,y) 
    337             if id != None: msg = "[id: %d] " % (id) + msg 
     337            if id is not None: msg = "[id: %d] " % (id) + msg 
    338338            print msg 
    339339        if self._vxinterval is not numpy.inf and \ 
     
    349349                x = "\n %s" % self._x[-1][best] 
    350350            msg = "Generation %d has%s fit parameters:%s" % (self._step-1,who,x) 
    351             if id != None: msg = "[id: %d] " % (id) + msg 
     351            if id is not None: msg = "[id: %d] " % (id) + msg 
    352352            print msg 
    353353        return 
  • mystic/mystic/solvers.py

    r748 r760  
    8080def LoadSolver(filename=None, **kwds): 
    8181    """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) 
    8383    #XXX: only allow a list override keys (lookup values from self) 
    84 #   if filename == None: filename = self._state 
    85 #   if filename == None: 
     84#   if filename is None: filename = self._state 
     85#   if filename is None: 
    8686#       solver = self 
    8787#   else: 
  • mystic/mystic/symbolic.py

    r713 r760  
    4848    eqstring = "" 
    4949    # Equality constraints 
    50     if A != None and b != None: 
     50    if A is not None and b is not None: 
    5151        # If one-dimensional and not in a nested list, add a list layer 
    5252        try: 
     
    7373    # Inequality constraints 
    7474    ineqstring = "" 
    75     if G != None and h != None: 
     75    if G is not None and h is not None: 
    7676        # If one-dimensional and not in a nested list, add a list layer 
    7777        try: 
     
    252252   #ndim = len(get_variables(src(func), variables)) 
    253253    if list_or_tuple_or_ndarray(variables): 
    254         if nvars != None: variables = variables[:nvars] 
     254        if nvars is not None: variables = variables[:nvars] 
    255255        constraints = replace_variables(constraints, variables) 
    256256        varname = '$' 
     
    261261        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    262262        else: ndim = 0 
    263     if nvars != None: ndim = nvars 
     263    if nvars is not None: ndim = nvars 
    264264 
    265265    # Parse the constraints string 
     
    339339   #ndim = len(get_variables(src(func), variables)) 
    340340    if list_or_tuple_or_ndarray(variables): 
    341         if nvars != None: variables = variables[:nvars] 
     341        if nvars is not None: variables = variables[:nvars] 
    342342        constraints = replace_variables(constraints, variables) 
    343343        varname = '$' 
     
    348348        if myvar: ndim = max([int(v.strip(varname)) for v in myvar]) + 1 
    349349        else: ndim = 0 
    350     if nvars != None: ndim = nvars 
     350    if nvars is not None: ndim = nvars 
    351351 
    352352    # Parse the constraints string 
  • mystic/mystic/tools.py

    r753 r760  
    104104    import sys, subprocess 
    105105    if sys.stdin.isatty(): 
    106        if str != None: 
     106       if str is not None: 
    107107          print str 
    108108       subprocess.call('stty raw', shell=True) 
     
    111111       return a 
    112112    else: 
    113        if str != None: 
     113       if str is not None: 
    114114           print str + " and press enter" 
    115115       return raw_input() 
Note: See TracChangeset for help on using the changeset viewer.