Changeset 558 for branches


Ignore:
Timestamp:
09/11/12 19:05:10 (4 years ago)
Author:
mmckerns
Message:

npop to 20 for set_feasible; expose maxiter to user in impose_short;
several substitutions of 'is' for '=='

Location:
branches/UQ/math/legacy
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/UQ/math/legacy/TEST_OUQ_StAlData.py

    r556 r558  
    112112       not c.short_wrt_self(data.lipschitz, tol=error[2]): 
    113113      c.set_feasible(data, error[2], bounds=bounds, constraints=constrain) 
     114                                                   # npop=20, maxiter=200) 
    114115    ###################### more function-specific ##################### 
    115116    if debug: 
  • branches/UQ/math/legacy/dirac_measure.py

    r557 r558  
    954954 
    955955  # prepare bounds for solver 
    956   bounds = None 
    957   if kwds.has_key('bounds'): 
    958     bounds = kwds['bounds'] 
     956  bounds = kwds.pop('bounds', None) 
    959957  # if bounds are not set, use the default optimizer bounds 
    960   if bounds == None: 
     958  if bounds is None: 
    961959    lower_bounds = []; upper_bounds = [] 
    962960    for n in pts:  # bounds for n*x in each dimension  (x2 due to weights) 
     
    971969  # plug in the 'constraints' function:  param' = constraints(param) 
    972970  # constraints should impose_mean(y,w), and possibly sum(weights) 
    973   constraints = None   # default is no constraints 
    974   if kwds.has_key('constraints'): constraints = kwds['constraints'] 
     971  constraints = kwds.pop('constraints', None) # default is no constraints 
    975972  if not constraints:  # if None (default), there are no constraints 
    976973    constraints = lambda x: x 
    977974 
     975  _self = kwds.pop('with_self', True) # default includes self in shortness 
     976  if _self is not False: _self = True 
    978977  # tolerance for optimization on sum(y) 
    979   npop = 40 #XXX: tune npop? 
    980   if kwds.has_key('npop'): npop = kwds.pop('npop') 
    981   tol = 0.0 # default 
    982   if kwds.has_key('tol'): tol = kwds.pop('tol') 
     978  tol = kwds.pop('tol', 0.0) # default 
     979  npop = kwds.pop('npop', 20) #XXX: tune npop? 
     980  maxiter = kwds.pop('maxiter', 1000) #XXX: tune maxiter? 
    983981 
    984982  # if no guess was made, then use bounds constraints 
    985   if guess == None: 
     983  if guess is None: 
    986984    if npop: 
    987985      guess = bounds 
    988986    else:  # fmin_powell needs a list params (not bounds) 
    989987      guess = [(a + b)/2. for (a,b) in bounds] 
    990  
    991   _self = True   # default is to include self in measuring shortness 
    992   if kwds.has_key('with_self'): _self = kwds['with_self'] 
    993   if _self != False: _self = True 
    994988 
    995989  # construct cost function to reduce sum(lipschitz_distance) 
     
    10121006 
    10131007  # construct and configure optimizer 
    1014   debug = True#False  #!!! 
    1015   maxiter = 1000;  maxfun = 1e+6 
     1008  debug = False  #!!! 
     1009  maxfun = 1e+6 
    10161010  crossover = 0.9; percent_change = 0.9 
    10171011  ftol = abs(tol); gtol = None 
     
    10981092  bounds = kwds.pop('bounds', None) 
    10991093  # if bounds are not set, use the default optimizer bounds 
    1100   if bounds == None: 
     1094  if bounds is None: 
    11011095    lower_bounds = []; upper_bounds = [] 
    11021096    for n in pts:  # bounds for n*x in each dimension  (x2 due to weights) 
  • branches/UQ/math/legacy/legacydata.py

    r557 r558  
    320320    of any element less than the cutoff. 
    321321""" 
    322     # get tolerance in y 
    323     tol = 0.0 
    324     if kwds.has_key('tol'): tol = kwds['tol'] 
    325     cutoff = tol  # default is to zero out distances less than tolerance 
    326     if kwds.has_key('cutoff'): cutoff = kwds['cutoff'] 
     322    tol = kwds.get('tol', 0.0) # get tolerance in y 
     323    # default is to zero out distances less than tolerance 
     324    cutoff = kwds.get('cutoff', tol) 
    327325    if cutoff is True: cutoff = tol 
    328326    elif cutoff is False: cutoff = None 
    329327 
    330     if L == None: L = self.lipschitz 
    331     if data == None: data = self 
     328    if L is None: L = self.lipschitz 
     329    if data is None: data = self 
    332330    from paramtrans import lipschitz_distance, is_feasible 
    333331    # calculate the shortness 
  • branches/UQ/math/legacy/paramtrans.py

    r557 r558  
    208208  from numpy import asarray 
    209209  d = infeasibility(distance, cutoff) > 0.0 
    210   if len(asarray(d).shape) == 0: 
     210  if len(asarray(d).shape) is 0: 
    211211    return not d 
    212212  return -d 
     
    226226  distance = array(distance) 
    227227  # zero-out all distances less than tolerated 
    228   if cutoff != None: 
    229     if len(distance.shape) == 0: 
     228  if cutoff is not None: 
     229    if len(distance.shape) is 0: 
    230230      return 0.0 if distance <= cutoff else distance 
    231231    distance[distance <= cutoff] = 0.0 
     
    263263 
    264264  # get tolerance in y 
    265   tol = 0.0 
    266   if kwds.has_key('tol'): tol = kwds.pop('tol') 
     265  tol = kwds.pop('tol', 0.0) 
    267266  cutoff = tol  # default is to zero out distances less than tolerance 
    268267  if kwds.has_key('cutoff'): cutoff = kwds.pop('cutoff') 
     
    326325 
    327326  # get tolerance in y and wiggle room in x 
    328   ytol = 0.0 
    329   if kwds.has_key('ytol'): ytol = kwds.pop('ytol') 
    330   xtol = 0.0  # default is to not allow 'wiggle room' in x  
    331   if kwds.has_key('xtol'): xtol = kwds.pop('xtol') 
     327  ytol = kwds.pop('ytol', 0.0) 
     328  xtol = kwds.pop('xtol', 0.0) # default is to not allow 'wiggle room' in x  
    332329 
    333330  cutoff = ytol  # default is to zero out distances less than tolerance 
     
    335332  if cutoff is True: cutoff = ytol 
    336333  elif cutoff is False: cutoff = None 
    337   ipop = min(20, 3*nxi) #XXX: tune ipop? 
    338   if kwds.has_key('ipop'): ipop = kwds.pop('ipop') 
    339   imax = 1000 #XXX: tune imax? 
    340   if kwds.has_key('imax'): imax = kwds.pop('imax') 
     334  ipop = kwds.pop('ipop', min(20, 3*nxi)) #XXX: tune ipop? 
     335  imax = kwds.pop('imax', 1000) #XXX: tune imax? 
    341336 
    342337  ######################################################################### 
Note: See TracChangeset for help on using the changeset viewer.