Changeset 585 for branches


Ignore:
Timestamp:
11/05/12 14:23:44 (4 years ago)
Author:
mmckerns
Message:

added constraints code to impose bounds constraints in legacy
added hausdorff keyword to graphical_distance in TEST_OUQ_1dSurr_CxCy

Location:
branches/UQ/math/legacy
Files:
1 added
7 edited

Legend:

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

    r575 r585  
    8484  # generate primary constraints function 
    8585  def constraints(rv): 
     86    rrv = range(len(rv)) 
     87    # impose range constraints: first try bounce-back to maintain randomness 
     88    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     89    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     90    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     91    rv = [max(rv[i], lb[i]) for i in rrv] 
     92    rv = [min(rv[i], ub[i]) for i in rrv] 
     93 
    8694    c = scenario() 
    8795    c.load(rv, npts) 
     
    136144 
    137145  if MINMAX == 1: 
    138     print "func_minimum: %s" % func_max # inf 
     146    tag = 'minimum' # inf 
    139147  else: 
    140     print "func_maximum: %s" % func_max  # sup 
     148    tag = 'maximum' # sup 
     149  print "func_%s: %s" % (tag,func_max) 
    141150  print "func_evals: %s" % func_evals 
    142151 
  • branches/UQ/math/legacy/MM_OUQ_StAlData.py

    r575 r585  
    9292  # generate primary constraints function 
    9393  def constraints(rv): 
     94    rrv = range(len(rv)) 
     95    # impose range constraints: first try bounce-back to maintain randomness 
     96    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     97    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     98    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     99    rv = [max(rv[i], lb[i]) for i in rrv] 
     100    rv = [min(rv[i], ub[i]) for i in rrv] 
     101 
    94102    c = scenario() 
    95103    c.load(rv, npts) 
     
    160168 
    161169  if MINMAX == 1: 
    162     print "func_minimum: %s" % func_max # inf 
     170    tag = 'minimum' # inf 
    163171  else: 
    164     print "func_maximum: %s" % func_max  # sup 
     172    tag = 'maximum' # sup 
     173  print "func_%s: %s" % (tag,func_max) 
    165174  print "func_evals: %s" % func_evals 
    166175 
  • branches/UQ/math/legacy/TEST_OUQ_1dData.py

    r582 r585  
    8888  # generate primary constraints function 
    8989  def constraints(rv): 
     90    rrv = range(len(rv)) 
     91    # impose range constraints: first try bounce-back to maintain randomness 
     92    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     93    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     94    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     95    rv = [max(rv[i], lb[i]) for i in rrv] 
     96    rv = [min(rv[i], ub[i]) for i in rrv] 
     97 
    9098    c = scenario() 
    9199    c.load(rv, npts) 
     
    156164 
    157165  if MINMAX == 1: 
    158     print "func_minimum: %s" % func_max # inf 
     166    tag = 'minimum' # inf 
    159167  else: 
    160     print "func_maximum: %s" % func_max  # sup 
     168    tag = 'maximum' # sup 
     169  print "func_%s: %s" % (tag,func_max) 
    161170  print "func_evals: %s" % func_evals 
    162171 
     
    193202  w_split = [0.5] 
    194203 
    195  #XXX XXX: EDITED TO USE w_split *AND* npts=(2,1,1) *AND* FIX Y1 == Y_lower 
     204 #XXX XXX: EDITED TO USE w_split *AND* FIX Y1 == Y_lower 
    196205  lower_bounds = (w_lower) + (w_split) + (nx * h_lower) \ 
    197206               + (ny * w_upper) + (ny * a_lower) \ 
  • branches/UQ/math/legacy/TEST_OUQ_1dSurr_CxCy.py

    r582 r585  
    8787  # generate primary constraints function 
    8888  def constraints(rv): 
     89    rrv = range(len(rv)) 
     90    # impose range constraints: first try bounce-back to maintain randomness 
     91    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     92    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     93    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     94    rv = [max(rv[i], lb[i]) for i in rrv] 
     95    rv = [min(rv[i], ub[i]) for i in rrv] 
     96 
    8997    c = scenario() 
    9098    c.load(rv, npts) 
     
    109117    # then test if valid... then impose model validity on product measure 
    110118    if not c.valid_wrt_model(model, ytol=target[2], xtol=target[3], \ 
    111                                                     imax=target[4]): 
     119                             imax=target[4],hausdorff=target[5]): 
    112120      c.set_valid(model, cutoff=target[2], bounds=bounds, tol=error[2], \ 
    113                                 constraints=constrain, xtol=target[3], \ 
    114                                 maxiter=error[3], imax=error[4]) 
     121                  constraints=constrain, xtol=target[3], \ 
     122                  maxiter=error[3], imax=error[4], hausdorff=target[5]) 
    115123    ###################### more function-specific ##################### 
    116124    if debug: 
    117125      if not c.valid_wrt_model(model, ytol=target[2], xtol=target[3], \ 
    118                                                       imax=target[4]): 
     126                                      imax=target[4], hausdorff=target[5]): 
    119127        print "valid_wrt_model: False" 
    120128      if not [sum(w) for w in c.wts] == [1.0] * len(c.wts): 
     
    143151 
    144152    if not c.valid_wrt_model(model, ytol=target[2], xtol=target[3], \ 
    145                                                     imax=target[4]): 
     153                                    imax=target[4], hausdorff=target[5]): 
    146154      if debug: print "skipping model-invalidity" 
    147155      return inf  #XXX: FORCE TO SATISFY E CONSTRAINTS 
     
    153161 
    154162  if MINMAX == 1: 
    155     print "func_minimum: %s" % func_max # inf 
     163    tag = 'minimum' # inf 
    156164  else: 
    157     print "func_maximum: %s" % func_max  # sup 
     165    tag = 'maximum' # sup 
     166  print "func_%s: %s" % (tag,func_max) 
    158167  print "func_evals: %s" % func_evals 
    159168 
     
    173182  Cy = 0.1           #NOTE: SET THE 'cutoff' HERE! 
    174183  Cx = (2.0,0.0,0.0) #NOTE: SET THE 'wiggle' HERE! 
     184  hausdorff = (1.0,0.0,0.0) #NOTE: SET THE 'hausdorff normalization' HERE! 
    175185  valid_tol = 0.0  #NOTE: SET THE 'model tolerance' HERE! 
    176186  imax_c = 200     #NOTE: SET THE 'max iterations to check valid' HERE! 
    177187  imax_i = 10      #NOTE: SET THE 'max inner iterations to set valid' HERE! 
    178188  imax_o = 50      #NOTE: SET THE 'max outer iterations to set valid' HERE! 
    179   target = (y_mean,theta,Cy,Cx,imax_c) 
    180   error = (y_mean_error,None,valid_tol,imax_o,imax_i) 
     189  target = (y_mean,theta,Cy,Cx,imax_c,hausdorff) 
     190  error = (y_mean_error,None,valid_tol,imax_o,imax_i,None) 
    181191  pars = (target,error) 
    182192 
     
    194204  h_upper = [1.0]; a_upper = [0.0];  v_upper = [0.0] 
    195205 
    196  #XXX XXX: EDITED TO USE npts=(2,1,1) *AND* FIX Y1 == Y_lower 
     206 #XXX XXX: EDITED TO FIX Y1 == Y_lower 
    197207  lower_bounds = (nx * w_lower) + (nx * h_lower) \ 
    198208               + (ny * w_lower) + (ny * a_lower) \ 
     
    258268 
    259269  print "fails valid wrt model:\n%s" % \ 
    260         c.valid_wrt_model(model, xtol=Cx, ytol=Cy, blamelist=True, imax=imax_c) 
     270        c.valid_wrt_model(model, xtol=Cx, ytol=Cy, blamelist=True, \ 
     271                                 imax=imax_c, hausdorff=hausdorff) 
    261272  print "mean(y): %s >= %s" % (str( c.get_mean_value() ), y_mean - y_mean_error) 
    262273  print "sum_wts: %s == 1.0" % [sum(w) for w in c.wts] 
    263274 
     275  try: _Cx = max(Cx) 
     276  except TypeError: _Cx = Cx 
    264277  from mystic.math.paramtrans import graphical_distance 
    265   Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 
    266   print "vertical_distance: %s <= %s" % (Ry, Cy + max(Cx)) 
    267   Rv = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=imax_c) 
     278  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, 
     279                          imax=0, hausdorff=hausdorff) 
     280  print "vertical_distance: %s <= %s" % (Ry, Cy + _Cx) 
     281  Rv = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, 
     282                          imax=imax_c, hausdorff=hausdorff) 
    268283  print "graphical_distance: %s <= %s" % (Rv, Cy) 
    269284 
  • branches/UQ/math/legacy/TEST_OUQ_1dSurr_Cy.py

    r582 r585  
    8787  # generate primary constraints function 
    8888  def constraints(rv): 
     89    rrv = range(len(rv)) 
     90    # impose range constraints: first try bounce-back to maintain randomness 
     91    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     92    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     93    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     94    rv = [max(rv[i], lb[i]) for i in rrv] 
     95    rv = [min(rv[i], ub[i]) for i in rrv] 
     96 
    8997    c = scenario() 
    9098    c.load(rv, npts) 
     
    153161 
    154162  if MINMAX == 1: 
    155     print "func_minimum: %s" % func_max # inf 
     163    tag = 'minimum' # inf 
    156164  else: 
    157     print "func_maximum: %s" % func_max  # sup 
     165    tag = 'maximum' # sup 
     166  print "func_%s: %s" % (tag,func_max) 
    158167  print "func_evals: %s" % func_evals 
    159168 
     
    194203  h_upper = [1.0]; a_upper = [0.0];  v_upper = [0.0] 
    195204 
    196  #XXX XXX: EDITED TO USE npts=(2,1,1) *AND* FIX Y1 == Y_lower 
     205 #XXX XXX: EDITED TO FIX Y1 == Y_lower 
    197206  lower_bounds = (nx * w_lower) + (nx * h_lower) \ 
    198207               + (ny * w_lower) + (ny * a_lower) \ 
     
    262271  print "sum_wts: %s == 1.0" % [sum(w) for w in c.wts] 
    263272 
     273  try: _Cx = max(Cx) 
     274  except TypeError: _Cx = Cx 
    264275  from mystic.math.paramtrans import graphical_distance 
    265276  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 
    266   print "vertical_distance: %s <= %s" % (Ry, Cy + max(Cx)) 
     277  print "vertical_distance: %s <= %s" % (Ry, Cy + _Cx) 
    267278  Rv = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=imax_c) 
    268279  print "graphical_distance: %s <= %s" % (Rv, Cy) 
  • branches/UQ/math/legacy/TEST_OUQ_StAlData.py

    r575 r585  
    8888  # generate primary constraints function 
    8989  def constraints(rv): 
     90    rrv = range(len(rv)) 
     91    # impose range constraints: first try bounce-back to maintain randomness 
     92    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     93    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     94    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     95    rv = [max(rv[i], lb[i]) for i in rrv] 
     96    rv = [min(rv[i], ub[i]) for i in rrv] 
     97 
    9098    c = scenario() 
    9199    c.load(rv, npts) 
     
    157165 
    158166  if MINMAX == 1: 
    159     print "func_minimum: %s" % func_max # inf 
     167    tag = 'minimum' # inf 
    160168  else: 
    161     print "func_maximum: %s" % func_max  # sup 
     169    tag = 'maximum' # sup 
     170  print "func_%s: %s" % (tag,func_max) 
    162171  print "func_evals: %s" % func_evals 
    163172 
  • branches/UQ/math/legacy/TEST_OUQ_StStSurr_Cy.py

    r582 r585  
    8787  # generate primary constraints function 
    8888  def constraints(rv): 
     89    rrv = range(len(rv)) 
     90    # impose range constraints: first try bounce-back to maintain randomness 
     91    rv = [2*lb[i]-rv[i] if max(rv[i], lb[i]) == lb[i] else rv[i] for i in rrv] 
     92    rv = [2*ub[i]-rv[i] if min(rv[i], ub[i]) == ub[i] else rv[i] for i in rrv] 
     93    # if bounceback fails, then use a hard cutoff  #FIXME: breaks randomness 
     94    rv = [max(rv[i], lb[i]) for i in rrv] 
     95    rv = [min(rv[i], ub[i]) for i in rrv] 
     96 
    8997    c = scenario() 
    9098    c.load(rv, npts) 
     
    153161 
    154162  if MINMAX == 1: 
    155     print "func_minimum: %s" % func_max # inf 
     163    tag = 'minimum' # inf 
    156164  else: 
    157     print "func_maximum: %s" % func_max  # sup 
     165    tag = 'maximum' # sup 
     166  print "func_%s: %s" % (tag,func_max) 
    158167  print "func_evals: %s" % func_evals 
    159168 
     
    194203  h_upper = [105.0]; a_upper = [30.0]; v_upper = [2.8] 
    195204 
    196  #XXX XXX: EDITED TO USE npts=(2,1,1) *AND* FIX Y1 == Y_lower 
     205 #XXX XXX: EDITED TO FIX Y1 == Y_lower 
    197206  lower_bounds = (nx * w_lower) + (nx * h_lower) \ 
    198207               + (ny * w_lower) + (ny * a_lower) \ 
     
    262271  print "sum_wts: %s == 1.0" % [sum(w) for w in c.wts] 
    263272 
     273  try: _Cx = max(Cx) 
     274  except TypeError: _Cx = Cx 
    264275  from mystic.math.paramtrans import graphical_distance 
    265276  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 
    266   print "vertical_distance: %s <= %s" % (Ry, Cy + max(Cx)) 
     277  print "vertical_distance: %s <= %s" % (Ry, Cy + _Cx) 
    267278  Rv = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=imax_c) 
    268279  print "graphical_distance: %s <= %s" % (Rv, Cy) 
Note: See TracChangeset for help on using the changeset viewer.