Changeset 687


Ignore:
Timestamp:
06/15/13 18:43:09 (3 years ago)
Author:
mmckerns
Message:

renaming of some of the measure methods, including dirac_measure to measure
moved dirac_measure.py to discrete.py, and paramtrans to distance
added isinstance to tools; added min, max, ess_min, ess_max to measures
moved dirac_measure.coords to dirac_measure.positions

Files:
30 edited
2 moved

Legend:

Unmodified
Added
Removed
  • branches/UQ/math/examples2/TEST4d_OUQ_surrogate_diam.py

    r575 r687  
    6868 
    6969  from mystic.math.measures import split_param 
    70   from mystic.math.dirac_measure import product_measure 
     70  from mystic.math.discrete import product_measure 
    7171  from mystic.math import almostEqual 
    7272  from numpy import inf 
     
    114114    # impose expectation on product measure 
    115115    ##################### begin function-specific ##################### 
    116     E = float(c.get_expect(model)) 
     116    E = float(c.expect(model)) 
    117117    if not (E <= float(target[0] + error[0])) \ 
    118118    or not (float(target[0] - error[0]) <= E): 
     
    130130    #XXX: apply 'filters' to catch errors in constraints solver (necessary ?) 
    131131    ##################### begin function-specific ##################### 
    132     E = float(c.get_expect(model)) 
     132    E = float(c.expect(model)) 
    133133    if E > (target[0] + error[0]) or E < (target[0] - error[0]): 
    134134      if debug: print "skipping expect: %s" % E 
     
    238238 
    239239  from numpy import array 
    240   from mystic.math.dirac_measure import product_measure 
     240  from mystic.math.discrete import product_measure 
    241241  c = product_measure() 
    242242  c.load(solved,npts) 
     
    246246  
    247247  # XXX: 4D-expect 
    248   print "expect: %s" % str( c.get_expect(model) ) 
     248  print "expect: %s" % str( c.expect(model) ) 
    249249  print "var (x): %s" % str( c[0].var )   # var(h) 
    250250  print "mean(x): %s" % str( c[0].mean )  # mean(h) 
  • branches/UQ/math/examples2/TEST_OUQ_surrogate_diam.py

    r575 r687  
    6868 
    6969  from mystic.math.measures import split_param 
    70   from mystic.math.dirac_measure import product_measure 
     70  from mystic.math.discrete import product_measure 
    7171  from mystic.math import almostEqual 
    7272  from numpy import inf 
     
    9494    # impose expectation on product measure 
    9595    ##################### begin function-specific ##################### 
    96     E = float(c.get_expect(model)) 
     96    E = float(c.expect(model)) 
    9797    if not (E <= float(target[0] + error[0])) \ 
    9898    or not (float(target[0] - error[0]) <= E): 
     
    106106    c = product_measure() 
    107107    c.load(rv, npts) 
    108     E = float(c.get_expect(model)) 
     108    E = float(c.expect(model)) 
    109109    if E > (target[0] + error[0]) or E < (target[0] - error[0]): 
    110110      if debug: print "skipping expect: %s" % E 
     
    190190 
    191191  from numpy import array 
    192   from mystic.math.dirac_measure import product_measure 
     192  from mystic.math.discrete import product_measure 
    193193  c = product_measure() 
    194194  c.load(solved,npts) 
     
    197197  print "solved: [wz,z]\n%s" % array(zip(c[2].weights,c[2].coords)) 
    198198 
    199   print "expect: %s" % str( c.get_expect(model) ) 
     199  print "expect: %s" % str( c.expect(model) ) 
    200200 
    201201# EOF 
  • branches/UQ/math/legacy/MINMAX_StAlData.py

    r585 r687  
    6767def maximize(params,npts,bounds): 
    6868 
    69   from mystic.math.dirac_measure import scenario 
     69  from mystic.math.discrete import scenario 
    7070  from numpy import inf 
    7171  target,error = params 
     
    104104    ##################### begin function-specific ##################### 
    105105    # impose norm on the weights of the discrete measures 
    106     from mystic.math.dirac_measure import norm_wts_constraintsFactory as factory 
     106    from mystic.math.discrete import norm_wts_constraintsFactory as factory 
    107107    constrain = factory(npts) 
    108108 
     
    167167  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    168168  npts = (nx,ny,nz) 
    169   from mystic.math.paramtrans import _npts 
     169  from mystic.math.distance import _npts 
    170170  _n = _npts(npts) 
    171171 
     
    229229 
    230230  from numpy import array 
    231   from mystic.math.dirac_measure import scenario 
     231  from mystic.math.discrete import scenario 
    232232  c = scenario() 
    233233  c.load(solved,npts) 
  • branches/UQ/math/legacy/MM_OUQ_StAlData.py

    r675 r687  
    7575def maximize(params,npts,bounds): 
    7676 
    77   from mystic.math.dirac_measure import scenario 
     77  from mystic.math.discrete import scenario 
    7878  from numpy import inf 
    7979  target,error = params 
     
    112112    ##################### begin function-specific ##################### 
    113113    # impose mean on the values of the product measure 
    114     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     114    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    115115    constrain = factory((target[0],error[0]), npts) 
    116116 
     
    196196  nz = 2  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    197197  npts = (nx,ny,nz) 
    198   from mystic.math.paramtrans import _npts 
     198  from mystic.math.distance import _npts 
    199199  _n = _npts(npts) 
    200200 
     
    260260 
    261261  from numpy import array 
    262   from mystic.math.dirac_measure import scenario 
     262  from mystic.math.discrete import scenario 
    263263  c = scenario() 
    264264  c.load(solved,npts) 
  • branches/UQ/math/legacy/TEST_OUQ_1dData.py

    r585 r687  
    7171def maximize(params,npts,bounds): 
    7272 
    73   from mystic.math.dirac_measure import scenario 
     73  from mystic.math.discrete import scenario 
    7474  from numpy import inf 
    7575  target,error = params 
     
    108108    ##################### begin function-specific ##################### 
    109109    # impose mean on the values of the product measure 
    110     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     110    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    111111    constrain = factory((target[0],error[0]), npts) 
    112112 
     
    192192  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    193193  npts = (nx,ny,nz) 
    194   from mystic.math.paramtrans import _npts 
     194  from mystic.math.distance import _npts 
    195195  _n = _npts(npts) 
    196196 
     
    256256 
    257257  from numpy import array 
    258   from mystic.math.dirac_measure import scenario 
     258  from mystic.math.discrete import scenario 
    259259  c = scenario() 
    260260  c.load(solved,npts) 
  • branches/UQ/math/legacy/TEST_OUQ_1dSurr_CxCy.py

    r588 r687  
    7373def maximize(params,npts,bounds,printmon=None,**kwds): 
    7474 
    75   from mystic.math.dirac_measure import scenario 
     75  from mystic.math.discrete import scenario 
    7676  from numpy import inf 
    7777  target,error = params 
     
    110110    ##################### begin function-specific ##################### 
    111111    # impose mean on the values of the product measure 
    112     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     112    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    113113    constrain = factory((target[0],error[0]), npts) 
    114114 
     
    203203  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    204204  npts = (nx,ny,nz) 
    205   from mystic.math.paramtrans import _npts 
     205  from mystic.math.distance import _npts 
    206206  _n = _npts(npts) 
    207207 
     
    271271 
    272272  from numpy import array 
    273   from mystic.math.dirac_measure import scenario 
     273  from mystic.math.discrete import scenario 
    274274  c = scenario() 
    275275  c.load(solved,npts) 
     
    294294  try: _Cx = max(Cx) 
    295295  except TypeError: _Cx = Cx 
    296   from mystic.math.paramtrans import graphical_distance 
     296  from mystic.math.distance import graphical_distance 
    297297  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, 
    298298                          imax=0, hausdorff=hausdorff) 
  • branches/UQ/math/legacy/TEST_OUQ_1dSurr_Cy.py

    r586 r687  
    7373def maximize(params,npts,bounds,printmon=None,**kwds): 
    7474 
    75   from mystic.math.dirac_measure import scenario 
     75  from mystic.math.discrete import scenario 
    7676  from numpy import inf 
    7777  target,error = params 
     
    110110    ##################### begin function-specific ##################### 
    111111    # impose mean on the values of the product measure 
    112     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     112    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    113113    constrain = factory((target[0],error[0]), npts) 
    114114 
     
    202202  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    203203  npts = (nx,ny,nz) 
    204   from mystic.math.paramtrans import _npts 
     204  from mystic.math.distance import _npts 
    205205  _n = _npts(npts) 
    206206 
     
    270270 
    271271  from numpy import array 
    272   from mystic.math.dirac_measure import scenario 
     272  from mystic.math.discrete import scenario 
    273273  c = scenario() 
    274274  c.load(solved,npts) 
     
    292292  try: _Cx = max(Cx) 
    293293  except TypeError: _Cx = Cx 
    294   from mystic.math.paramtrans import graphical_distance 
     294  from mystic.math.distance import graphical_distance 
    295295  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 
    296296  printmon.info("vertical_distance: %s <= %s" % (Ry, Cy + _Cx)) 
  • branches/UQ/math/legacy/TEST_OUQ_StAlData.py

    r585 r687  
    7171def maximize(params,npts,bounds): 
    7272 
    73   from mystic.math.dirac_measure import scenario 
     73  from mystic.math.discrete import scenario 
    7474  from numpy import inf 
    7575  target,error = params 
     
    108108    ##################### begin function-specific ##################### 
    109109    # impose mean on the values of the product measure 
    110     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     110    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    111111    constrain = factory((target[0],error[0]), npts) 
    112112 
     
    193193  nz = 2  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    194194  npts = (nx,ny,nz) 
    195   from mystic.math.paramtrans import _npts 
     195  from mystic.math.distance import _npts 
    196196  _n = _npts(npts) 
    197197 
     
    257257 
    258258  from numpy import array 
    259   from mystic.math.dirac_measure import scenario 
     259  from mystic.math.discrete import scenario 
    260260  c = scenario() 
    261261  c.load(solved,npts) 
  • branches/UQ/math/legacy/TEST_OUQ_StStSurr_Cy.py

    r585 r687  
    7070def maximize(params,npts,bounds): 
    7171 
    72   from mystic.math.dirac_measure import scenario 
     72  from mystic.math.discrete import scenario 
    7373  from numpy import inf 
    7474  target,error = params 
     
    107107    ##################### begin function-specific ##################### 
    108108    # impose mean on the values of the product measure 
    109     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     109    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    110110    constrain = factory((target[0],error[0]), npts) 
    111111 
     
    194194  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    195195  npts = (nx,ny,nz) 
    196   from mystic.math.paramtrans import _npts 
     196  from mystic.math.distance import _npts 
    197197  _n = _npts(npts) 
    198198 
     
    257257 
    258258  from numpy import array 
    259   from mystic.math.dirac_measure import scenario 
     259  from mystic.math.discrete import scenario 
    260260  c = scenario() 
    261261  c.load(solved,npts) 
     
    273273  try: _Cx = max(Cx) 
    274274  except TypeError: _Cx = Cx 
    275   from mystic.math.paramtrans import graphical_distance 
     275  from mystic.math.distance import graphical_distance 
    276276  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 
    277277  print "vertical_distance: %s <= %s" % (Ry, Cy + _Cx) 
  • branches/UQ/math/legacy/envelope/Looper_BoLiSurr_Cy.py

    r675 r687  
    9898def maximize(params,npts,bounds,initial=None,job='',printmon=None): 
    9999 
    100   from mystic.math.dirac_measure import scenario 
     100  from mystic.math.discrete import scenario 
    101101  from numpy import inf 
    102102  target,error = params 
     
    140140    ##################### begin function-specific ##################### 
    141141    # impose mean on the values of the product measure 
    142     from mystic.math.dirac_measure import mean_y_norm_wts_constraintsFactory as factory 
     142    from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 
    143143    constrain = factory((target[0],error[0]), npts) 
    144144 
     
    250250 
    251251  npts = (nx,ny,nz) 
    252   from mystic.math.paramtrans import _npts 
     252  from mystic.math.distance import _npts 
    253253  _n = _npts(npts) 
    254254 
     
    316316 
    317317  from numpy import array 
    318   from mystic.math.dirac_measure import scenario 
     318  from mystic.math.discrete import scenario 
    319319  c = scenario() 
    320320  c.load(solved,npts) 
     
    333333# try: _Cx = max(Cx) 
    334334# except TypeError: _Cx = Cx 
    335   from mystic.math.paramtrans import graphical_distance 
     335  from mystic.math.distance import graphical_distance 
    336336  Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, \ 
    337337                          imax=0, ipop=cde, hausdorff=hausdorff) 
  • branches/UQ/math/legacy/envelope/conf_hausd.py

    r592 r687  
    3636      
    3737# COMPUTING HAUSDORFF DISTANCES 
    38 from mystic.math.paramtrans import graphical_distance 
     38from mystic.math.distance import graphical_distance 
    3939d_hausdorff = graphical_distance(model, d, ytol=0, xtol=(2.5,2.5, 0.0), cutoff=0.0, imax=100, hausdorff=(5.0, 5.0, 0.0, 25.0)) 
    4040if debug: 
  • branches/UQ/math/legacy/envelope/envelope.py

    r675 r687  
    1515debug = False 
    1616 
    17 from mystic.math.paramtrans import infeasibility, _get_xy 
     17from mystic.math.distance import infeasibility, _get_xy 
    1818 
    1919def graphical_distance(model, points, **kwds): 
  • branches/UQ/math/legacy/envelope/hausdorff.py

    r621 r687  
    1919 
    2020# build a scenario 
    21 from mystic.math.dirac_measure import scenario 
     21from mystic.math.discrete import scenario 
    2222c = scenario() 
    2323c.load(solved, npts) 
     
    5353#""" 
    5454 
    55 #from mystic.math.paramtrans import graphical_distance 
     55#from mystic.math.distance import graphical_distance 
    5656from envelope import graphical_distance 
    5757from numpy import set_printoptions 
  • branches/UQ/math/legacy/envelope/sausage.py

    r601 r687  
    1818    exec("%s = %s" % (str(k),repr(v))) #XXX: HACK 
    1919 
    20   from mystic.math.dirac_measure import scenario 
     20  from mystic.math.discrete import scenario 
    2121  c = scenario() 
    2222  c.load(params, pts) 
     
    2828  yo = asarray(c.values) 
    2929 
    30   from mystic.math.dirac_measure import impose_valid 
     30  from mystic.math.discrete import impose_valid 
    3131 
    3232  # fixed x values as bounds 
  • branches/UQ/math/legacy/test_ExampleDataset.py

    r569 r687  
    3131 
    3232  # Check shortness 
    33   from mystic.math.paramtrans import lipschitz_distance, graphical_distance 
     33  from mystic.math.distance import lipschitz_distance, graphical_distance 
    3434  print("\nshort: %s" % ex1d_data.short()) 
    3535  L = ex1d_data.lipschitz; 
  • branches/UQ/math/legacy/test_StAlDataset.py

    r569 r687  
    2121 
    2222  # Check shortness 
    23   from mystic.math.paramtrans import lipschitz_distance, graphical_distance 
     23  from mystic.math.distance import lipschitz_distance, graphical_distance 
    2424  print("\nshort: %s" % st_al_data.short()) 
    2525  L = st_al_data.lipschitz; 
  • branches/UQ/math/legacy/test_graph_dist.py

    r588 r687  
    3333for i in d: print i 
    3434 
    35 from mystic.math.paramtrans import graphical_distance 
     35from mystic.math.distance import graphical_distance 
    3636from numpy import set_printoptions 
    3737set_printoptions(suppress=True) 
  • branches/UQ/math/sausage/TEST_OUQ_1dSurr_diam.py

    r588 r687  
    7272def maximize(params,npts,bounds): 
    7373 
    74   from mystic.math.dirac_measure import scenario 
     74  from mystic.math.discrete import scenario 
    7575  from mystic.math import almostEqual 
    7676  from numpy import inf 
     
    189189  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    190190  npts = (nx,ny,nz) 
    191   from mystic.math.paramtrans import _npts 
     191  from mystic.math.distance import _npts 
    192192  _n = _npts(npts) 
    193193 
     
    253253 
    254254  from numpy import array 
    255   from mystic.math.dirac_measure import scenario 
     255  from mystic.math.discrete import scenario 
    256256  c = scenario() 
    257257  c.load(solved,npts) 
  • branches/UQ/math/sausage/TEST_OUQ_StStSurr.py

    r588 r687  
    7171def maximize(params,npts,bounds): 
    7272 
    73   from mystic.math.dirac_measure import scenario 
     73  from mystic.math.discrete import scenario 
    7474  from mystic.math import almostEqual 
    7575  from numpy import inf 
     
    201201  nz = 1  #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 
    202202  npts = (nx,ny,nz) 
    203   from mystic.math.paramtrans import _npts 
     203  from mystic.math.distance import _npts 
    204204  _n = _npts(npts) 
    205205 
     
    265265 
    266266  from numpy import array 
    267   from mystic.math.dirac_measure import scenario 
     267  from mystic.math.discrete import scenario 
    268268  c = scenario() 
    269269  c.load(solved,npts) 
  • branches/collapse/TEST_OUQ_surrogate_diam_collapse.py

    r576 r687  
    5858 
    5959  from mystic.math.measures import split_param 
    60   from mystic.math.dirac_measure import product_measure 
     60  from mystic.math.discrete import product_measure 
    6161  from mystic.math import almostEqual 
    6262  from numpy import inf 
     
    8484    # impose expectation on product measure 
    8585    ##################### begin function-specific ##################### 
    86     E = float(c.get_expect(model)) 
     86    E = float(c.expect(model)) 
    8787    if not (E <= float(target[0] + error[0])) \ 
    8888    or not (float(target[0] - error[0]) <= E): 
     
    9696    c = product_measure() 
    9797    c.load(rv, npts) 
    98     E = float(c.get_expect(model)) 
     98    E = float(c.expect(model)) 
    9999    if E > (target[0] + error[0]) or E < (target[0] - error[0]): 
    100100      if debug: print "skipping expect: %s" % E 
     
    188188 
    189189  from numpy import array 
    190   from mystic.math.dirac_measure import product_measure 
     190  from mystic.math.discrete import product_measure 
    191191  c = product_measure() 
    192192  c.load(solved,npts) 
     
    195195  print "solved: [wz,z]\n%s" % array(zip(c[2].weights,c[2].coords)) 
    196196 
    197   print "expect: %s" % str( c.get_expect(model) ) 
     197  print "expect: %s" % str( c.expect(model) ) 
    198198   
    199199  elapsed = (clock() - start) 
  • branches/collapse/collapse_code.py

    r576 r687  
    3737 
    3838def _set_weight_to_zero(rv, npts, axisW, indexW): 
    39     from mystic.math.dirac_measure import product_measure 
     39    from mystic.math.discrete import product_measure 
    4040    c = product_measure() 
    4141    c.load(rv, npts) 
     
    4444   
    4545def _set_same_positions(rv, npts, axisP, index1, index2): 
    46     from mystic.math.dirac_measure import product_measure 
     46    from mystic.math.discrete import product_measure 
    4747    c = product_measure() 
    4848    c.load(rv, npts) 
  • mystic/_math/__init__.py

    r468 r687  
    3535# backward compatibility 
    3636from approx import approx_equal 
     37import discrete as dirac_measure 
     38import distance as paramtrans 
    3739 
    3840# end of file 
  • mystic/_math/discrete.py

    r584 r687  
    11#! /usr/bin/env python 
    22""" 
    3 Classes for Dirac measure data objects. 
    4 Includes point, dirac_measure, product_measure, and scenario classes. 
     3Classes for discrete measure data objects. 
     4Includes point_mass, measure, product_measure, and scenario classes. 
    55""" 
    66# Adapted from seesaw2d.py in branches/UQ/math/examples2/  
     
    1010from mystic.math.measures import impose_spread, impose_variance 
    1111from mystic.math.measures import impose_weight_norm 
    12  
    13 class point(object): 
    14   """ 1-d object with weight and position 
     12from __builtin__ import max as _max 
     13from __builtin__ import min as _min 
     14 
     15class point_mass(object): 
     16  """ a point_mass object with weight and position 
    1517 
    1618 queries: 
     
    2426""" 
    2527 
    26   def __init__(self, position, weight): 
     28  def __init__(self, position, weight=1.0): 
    2729    self.weight = weight 
    2830    self.position = position 
     
    4143  pass 
    4244 
    43  
    44 class dirac_measure(list):  #FIXME: meant to only accept points... 
    45   """ a 1-d collection of points forming a 'discrete_measure' 
    46   s = dirac_measure([point1, point2, ..., pointN])   
    47     where a point has weight and position 
     45class measure(list):  #FIXME: meant to only accept point_masses... 
     46  """ a 1-d collection of point_masses forming a 'discrete_measure' 
     47  s = measure([point_mass1, point_mass2, ..., point_massN])   
     48    where a point_mass has weight and position 
    4849 
    4950 queries: 
    5051  s.weights   --  returns list of weights 
    51   s.coords  --  returns list of positions 
    52   s.npts  --  returns the number of points 
     52  s.positions  --  returns list of positions 
     53  s.npts  --  returns the number of point_masses 
    5354  s.mass  --  calculates sum of weights 
    54   s.mean  --  calculates sum of weights*positions 
     55  s.center_mass  --  calculates sum of weights*positions 
    5556  s.range  --  calculates |max - min| for positions 
    5657  s.var  --  calculates mean( |positions - mean(positions)|**2 ) 
     
    5859 settings: 
    5960  s.weights = [w1, w2, ..., wn]  --  set the weights 
    60   s.coords = [x1, x2, ..., xn]  --  set the positions 
     61  s.positions = [x1, x2, ..., xn]  --  set the positions 
    6162  s.normalize()  --  normalize the weights to 1.0 
    62   s.mean(R)  --  set the mean 
     63  s.center_mass(R)  --  set the center of mass 
    6364  s.range(R)  --  set the range 
    6465  s.var(R)  --  set the variance 
    6566 
    6667 methods: 
    67   s.get_expect(f)  --  calculate the expectation 
     68  s.support()  -- get the positions that have corresponding non-zero weights 
     69  s.support_index()  --  get the indicies of positions that have support 
     70  s.max(f)  --  calculate the maximum for a given function 
     71  s.min(f)  --  calculate the minimum for a given function 
     72  s.ess_max(f)  --  calculate the maximum for the support of a given function 
     73  s.ess_min(f)  --  calculate the minimum for the support of a given function 
     74  s.expect(f)  --  calculate the expectation 
    6875  s.set_expect((center,delta), f)  --  impose expectation by adjusting positions 
    6976 
    7077 notes: 
    7178  - constraints should impose that sum(weights) should be 1.0 
    72   - assumes that s.n = len(s.coords) == len(s.weights) 
    73 """ 
     79  - assumes that s.n = len(s.positions) == len(s.weights) 
     80""" 
     81 
     82  def support_index(self, tol=0): 
     83    """get the indicies of the positions which have non-zero weight 
     84 
     85Inputs: 
     86    tol -- weight tolerance, where any weight <= tol is considered zero 
     87""" 
     88    from measures import support_index 
     89    return support_index(self.weights, tol) 
     90 
     91  def support(self, tol=0): 
     92    """get the positions which have non-zero weight 
     93 
     94Inputs: 
     95    tol -- weight tolerance, where any weight <= tol is considered zero 
     96""" 
     97    from measures import support 
     98    return support(self.positions, self.weights, tol) 
    7499 
    75100  def __weights(self): 
     
    89114  def __mean(self): 
    90115    from mystic.math.measures import mean 
    91     return mean(self.coords, self.weights)  
     116    return mean(self.positions, self.weights)  
    92117 
    93118  def __range(self): 
    94119    from mystic.math.measures import spread 
    95     return spread(self.coords) 
     120    return spread(self.positions) 
    96121 
    97122  def __variance(self): 
    98123    from mystic.math.measures import variance 
    99     return variance(self.coords, self.weights) 
     124    return variance(self.positions, self.weights) 
    100125 
    101126  def __set_weights(self, weights): 
     
    110135 
    111136  def normalize(self): 
    112     self.coords, self.weights = impose_weight_norm(self.coords, self.weights) 
     137    """normalize the weights""" 
     138    self.positions, self.weights = impose_weight_norm(self.positions, self.weights) 
    113139    return 
    114140 
    115141  def __set_mean(self, m): 
    116     self.coords = impose_mean(m, self.coords, self.weights) 
     142    self.positions = impose_mean(m, self.positions, self.weights) 
    117143    return 
    118144 
    119145  def __set_range(self, r): 
    120     self.coords = impose_spread(r, self.coords, self.weights) 
     146    self.positions = impose_spread(r, self.positions, self.weights) 
    121147    return 
    122148 
    123149  def __set_variance(self, v): 
    124     self.coords = impose_variance(v, self.coords, self.weights) 
    125     return 
    126  
    127   def get_expect(self, f): 
     150    self.positions = impose_variance(v, self.positions, self.weights) 
     151    return 
     152 
     153  def max(self, f): 
     154    """calculate the maximum for a given function 
     155 
     156Inputs: 
     157    f -- a function that takes a list and returns a number 
     158""" 
     159    from measures import max 
     160    return max(f, self.positions) 
     161 
     162  def ess_max(self, f, tol=0.): 
     163    """calculate the maximum for the support of a given function 
     164 
     165Inputs: 
     166    f -- a function that takes a list and returns a number 
     167    tol -- weight tolerance, where any weight <= tol is considered zero 
     168""" 
     169    from measures import ess_max 
     170    return ess_max(f, self.positions, self.weights, tol) 
     171 
     172  def min(self, f): 
     173    """calculate the minimum for a given function 
     174 
     175Inputs: 
     176    f -- a function that takes a list and returns a number 
     177""" 
     178    from measures import min 
     179    return min(f, self.positions) 
     180 
     181  def ess_min(self, f, tol=0.): 
     182    """calculate the minimum for the support of a given function 
     183 
     184Inputs: 
     185    f -- a function that takes a list and returns a number 
     186    tol -- weight tolerance, where any weight <= tol is considered zero 
     187""" 
     188    from measures import ess_min 
     189    return ess_min(f, self.positions, self.weights, tol) 
     190 
     191  def expect(self, f): 
    128192    """calculate the expectation for a given function 
    129193 
     
    131195    f -- a function that takes a list and returns a number 
    132196""" #XXX: maybe more natural if f takes a positional value x, not a list x ? 
    133  
    134197    from mystic.math.measures import expectation 
    135     coords = [(i,) for i in self.coords] 
    136     return expectation(f, coords, self.weights) 
     198    positions = [(i,) for i in self.positions] 
     199    return expectation(f, positions, self.weights) 
    137200 
    138201  def set_expect(self, (m,D), f, bounds=None, constraints=None): 
     
    145208    constraints -- a function that takes a product_measure  c' = constraints(c) 
    146209""" #XXX: maybe more natural if f takes a positional value x, not a list x ? 
    147 #XXX: maybe also natural c' = constraints(c) where c is a dirac_measure ? 
     210    #XXX: maybe also natural c' = constraints(c) where c is a measure ? 
    148211 
    149212    if constraints:  # then need to adjust interface for 'impose_expectation' 
     
    153216        return decompose(c)[0] 
    154217    else: cnstr = constraints  # 'should' be None 
    155     coords = impose_expectation((m,D), f, [self.npts], bounds, \ 
     218    positions = impose_expectation((m,D), f, [self.npts], bounds, \ 
    156219                                           self.weights,  constraints=cnstr)  
    157220    from numpy import array 
    158     self.coords = list(array(coords)[:,0]) 
     221    self.positions = list(array(positions)[:,0]) 
    159222   #from numpy import squeeze 
    160    #self.coords = list(squeeze(coords)) 
     223   #self.positions = list(squeeze(positions)) 
    161224    return 
    162225 
    163226  # interface 
    164227  weights = property(__weights, __set_weights) 
    165   coords = property(__positions, __set_positions) 
     228  positions = property(__positions, __set_positions) 
    166229  ###XXX: why not use 'points' also/instead? 
    167230  npts = property(__n ) 
    168231  mass = property(__mass ) 
    169232  range = property(__range, __set_range) 
    170   mean = property(__mean, __set_mean) 
     233  center_mass = property(__mean, __set_mean) 
    171234  var = property(__variance, __set_variance) 
     235 
     236  # backward compatibility 
     237  coords = positions 
     238  get_expect = expect 
     239  mean = center_mass 
    172240  pass 
    173241 
    174242class product_measure(list):  #FIXME: meant to only accept sets... 
    175   """ a N-d product measure, a collection of dirac measures 
     243  """ a N-d measure-theoretic product of discrete measures 
    176244  c = product_measure([measure1, measure2, ..., measureN])   
    177245    where all measures are orthogonal 
    178246 
    179247 queries: 
    180   c.npts  --  returns total number of points 
     248  c.npts  --  returns total number of point_masses 
    181249  c.weights   --  returns list of weights 
    182   c.coords  --  returns list of position tuples 
     250  c.positions  --  returns list of position tuples 
    183251  c.mass  --  returns list of weight norms 
    184   c.pts  --  returns number of points for each discrete measure 
     252  c.pts  --  returns number of point_masses for each discrete measure 
    185253  c.wts  --  returns list of weights for each discrete measure 
    186254  c.pos  --  returns list of positions for each discrete measure 
    187255 
    188256 settings: 
    189   c.coords = [(x1,y1,z1),...]  --  set the positions (tuples in product measure) 
     257  c.positions = [(x1,y1,z1),...]  --  set positions (tuples in product measure) 
    190258 
    191259 methods: 
    192260  c.pof(f)  --  calculate the probability of failure 
    193   c.sampled_pof(f, npts) -- calculate the pof using sampled points 
    194   c.get_expect(f)  --  calculate the expectation 
     261  c.sampled_pof(f, npts) -- calculate the pof using sampled point_masses 
     262  c.expect(f)  --  calculate the expectation 
    195263  c.set_expect((center,delta), f)  --  impose expectation by adjusting positions 
    196264  c.flatten()  --  convert measure to a flat list of parameters 
     
    201269  - constraints impose expect (center - delta) <= E <= (center + delta) 
    202270  - constraints impose sum(weights) == 1.0 for each set 
    203   - assumes that c.npts = len(c.coords) == len(c.weights) 
     271  - assumes that c.npts = len(c.positions) == len(c.weights) 
    204272  - weight wxi should be same for each (yj,zk) at xi; similarly for wyi & wzi 
    205273""" 
    206274  def __val(self): 
    207     raise NotImplementedError, "'value' is undefined in a dirac_measure" 
     275    raise NotImplementedError, "'value' is undefined in a measure" 
    208276 
    209277  def __pts(self): 
     
    214282 
    215283  def __pos(self): 
    216     return [i.coords for i in self] 
     284    return [i.positions for i in self] 
     285 
     286  def __mean(self): 
     287    return [i.center_mass for i in self] 
     288 
     289  def __set_mean(self, center_masses): 
     290    [i._measure__set_mean(center_masses[m]) for (m,i) in enumerate(self)] 
     291   #for i in range(len(center_masses)): 
     292   #  self[i].center_mass = center_masses[i] 
     293    return 
    217294 
    218295  def __n(self): 
    219296    from numpy import product 
    220297    return product(self.pts) 
     298 
     299  def support_index(self, tol=0): 
     300    from measures import support_index 
     301    return support_index(self.weights, tol) 
     302 
     303  def support(self, tol=0): #XXX: better if generated positions only when needed 
     304    from measures import support 
     305    return support(self.positions, self.weights, tol) 
    221306 
    222307  def __weights(self): 
     
    233318    return _pack(self.pos) 
    234319 
    235   def __set_positions(self, coords): 
     320  def __set_positions(self, positions): 
    236321    from mystic.math.measures import _unpack 
    237     coords = _unpack(coords, self.pts) 
    238     for i in range(len(coords)): 
    239       self[i].coords = coords[i] 
     322    positions = _unpack(positions, self.pts) 
     323    for i in range(len(positions)): 
     324      self[i].positions = positions[i] 
    240325    return 
    241326 
     
    249334    return [self[i].mass for i in range(len(self))] 
    250335 
    251   def get_expect(self, f): 
     336  def max(self, f): #XXX: return max of all or return all max? 
     337    return _max([i.max(f) for i in self]) 
     338 
     339  def min(self, f): #XXX: return min of all or return all min? 
     340    return _min([i.min(f) for i in self]) 
     341 
     342  def ess_max(self, f, tol=0.): #XXX: return max of all or return all max? 
     343    return _max([i.ess_max(f, tol) for i in self]) 
     344 
     345  def ess_min(self, f, tol=0.): #XXX: return min of all or return all min? 
     346    return _min([i.ess_min(f, tol) for i in self]) 
     347 
     348  def expect(self, f): 
    252349    """calculate the expectation for a given function 
    253350 
     
    256353""" 
    257354    from mystic.math.measures import expectation 
    258     return expectation(f, self.coords, self.weights) 
     355    return expectation(f, self.positions, self.weights) 
    259356 
    260357  def set_expect(self, (m,D), f, bounds=None, constraints=None): 
     
    275372        return decompose(c)[0] 
    276373    else: cnstr = constraints  # 'should' be None 
    277     self.coords = impose_expectation((m,D), f, self.pts, bounds, self.weights, \ 
    278                                                         constraints=cnstr)  
     374    self.positions = impose_expectation((m,D), f, self.pts, bounds, \ 
     375                                        self.weights, constraints=cnstr)  
    279376    return 
    280377 
     
    287384""" 
    288385    u = 0 
    289     set = zip(self.coords, self.weights) 
     386    set = zip(self.positions, self.weights) 
    290387    for x in set: 
    291388      if f(x[0]) <= 0.0: 
     
    293390    return u 
    294391  # for i in range(self.npts): 
    295   #   #if f(self.coords[i]) > 0.0:  #NOTE: f(x) > 0.0 yields prob of success 
    296   #   if f(self.coords[i]) <= 0.0:  #NOTE: f(x) <= 0.0 yields prob of failure 
     392  #   #if f(self.positions[i]) > 0.0:  #NOTE: f(x) > 0.0 yields prob of success 
     393  #   if f(self.positions[i]) <= 0.0:  #NOTE: f(x) <= 0.0 yields prob of failure 
    297394  #     u += self.weights[i] 
    298395  # return u  #XXX: does this need to be normalized? 
     
    304401Inputs: 
    305402    f -- a function that returns True for 'success' and False for 'failure' 
    306     npts -- number of points sampled from the underlying discrete measures 
     403    npts -- number of point_masses sampled from the underlying discrete measures 
    307404""" 
    308405    from mystic.math.samples import _pof_given_samples 
    309     pts = self.support(npts) 
     406    pts = self.sampled_support(npts) 
    310407    return _pof_given_samples(f, pts) 
    311408 
    312   def support(self, npts=10000): 
     409  def sampled_support(self, npts=10000): ##XXX: was 'def support' 
    313410    """randomly select support points from the underlying discrete measures 
    314411 
     
    322419    pts = [] 
    323420    for i in range(npts): 
    324       # for a single trial, select coords from all sets 
    325       pts.append( [_select(set.coords, set.weights) for set in self] ) 
     421      # for a single trial, select positions from all sets 
     422      pts.append( [_select(set.positions, set.weights) for set in self] ) 
    326423 
    327424    # convert pts to len(prod_meas) lists, each of len(npts) 
    328425    from numpy import transpose 
    329     return transpose(pts)  #XXX: assumes 'coords' is a list of floats 
     426    return transpose(pts)  #XXX: assumes 'positions' is a list of floats 
    330427 
    331428  def update(self, params): 
     
    349446Inputs: 
    350447    params -- a list of parameters (see 'notes') 
    351     pts -- number of points in each of the underlying discrete measures 
     448    pts -- number of point_masses in each of the underlying discrete measures 
    352449 
    353450Notes: 
     
    405502 
    406503  def select(self, *index, **kwds): 
    407     """generator for product measure coords due to selected position indicies 
     504    """generator for product measure positions due to selected position indicies 
    408505 (NOTE: only works for product measures of dimension 2^K) 
    409506 
     
    428525  npts = property(__n ) 
    429526  weights = property(__weights ) 
    430   coords = property(__positions, __set_positions ) 
     527  positions = property(__positions, __set_positions ) 
     528  center_mass = property(__mean, __set_mean) 
    431529 #center = property(__get_center ) #FIXME: remove c.center and c.delta... or 
    432530 #delta = property(__get_delta )   #       replace with c._params (e.g. (m,D)) 
     
    436534  wts = property(__wts ) 
    437535  pos = property(__pos ) 
     536 
     537  # backward compatibility 
     538  coords = positions 
     539  get_expect = expect 
    438540  pass 
    439541 
     
    442544  """ a N-d product measure (collection of dirac measures) with values 
    443545  s = scenario(product_measure, [value1, value2, ..., valueN])   
    444     where each point in the product measure is paried with a value 
     546    where each point_mass in the product measure is paried with a value 
    445547    (essentially, a dataset in product_measure representation) 
    446548 
    447549 queries: 
    448   s.npts  --  returns total number of points 
     550  s.npts  --  returns total number of point_masse 
    449551  s.weights   --  returns list of weights 
    450   s.coords  --  returns list of position tuples 
     552  s.positions  --  returns list of position tuples 
    451553  s.values  --  returns list of values 
    452554  s.mass  --  returns list of weight norms 
    453   s.pts  --  returns number of points for each discrete measure 
     555  s.pts  --  returns number of point_masses for each discrete measure 
    454556  s.wts  --  returns list of weights for each discrete measure 
    455557  s.pos  --  returns list of positions for each discrete measure 
    456558 
    457559 settings: 
    458   s.coords = [(x1,y1,z1),...]  --  set the positions (tuples in product measure) 
     560  s.positions = [(x1,y1,z1),...]  --  set positions (tuples in product measure) 
    459561  s.values = [v1,v2,v3,...]  --  set the values (correspond to position tuples) 
    460562 
     
    463565  s.pof_value(f)  --  calculate the probability of failure using the values 
    464566  s.sampled_pof(f, npts) -- calculate the pof using sampled points 
    465   s.get_expect(f)  --  calculate the expectation 
     567  s.expect(f)  --  calculate the expectation 
    466568  s.set_expect((center,delta), f)  --  impose expectation by adjusting positions 
    467   s.get_mean_value()  --  calculate the mean values for a scenario 
     569  s.mean_value()  --  calculate the mean values for a scenario 
    468570  s.set_mean_value(m)  --  impose mean value by adjusting values 
    469571  s.set_feasible(data)  --  impose shortness by adjusting positions and values 
     
    479581  - constraints impose expect (center - delta) <= E <= (center + delta) 
    480582  - constraints impose sum(weights) == 1.0 for each set 
    481   - assumes that s.npts = len(s.coords) == len(s.weights) 
     583  - assumes that s.npts = len(s.positions) == len(s.weights) 
    482584  - weight wxi should be same for each (yj,zk) at xi; similarly for wyi & wzi 
    483585""" 
     
    488590      self.load(pm.flatten(), pm.pts) 
    489591    if not values: values = [] 
    490     self.__Y = values # storage for values of s.coords 
     592    self.__Y = values # storage for values of s.positions 
    491593    return 
    492594 
     
    498600    return 
    499601 
    500   def get_mean_value(self):  # get mean of y's 
     602  def mean_value(self):  # get mean of y's 
    501603    """calculate the mean of the associated values for a scenario""" 
    502604    from mystic.math.measures import mean 
     
    540642    from mystic.math.legacydata import dataset  
    541643    data = dataset()  
    542     data.load(self.coords, self.values) 
     644    data.load(self.positions, self.values) 
    543645   #data.lipschitz = L 
    544646    for i in range(len(data)): 
     
    574676    from mystic.math.legacydata import dataset  
    575677    data = dataset()  
    576     data.load(self.coords, self.values) 
     678    data.load(self.positions, self.values) 
    577679    data.lipschitz = L 
    578680    for i in range(len(data)): 
     
    609711    from mystic.math.legacydata import dataset  
    610712    _self = dataset()  
    611     _self.load(self.coords, self.values) 
     713    _self.load(self.positions, self.values) 
    612714    _self.lipschitz = data.lipschitz 
    613715    for i in range(len(_self)): 
     
    748850  # interface 
    749851  values = property(__values, __set_values ) 
     852  get_mean_value = mean_value 
    750853  pass 
    751854 
     
    763866    >>> wts = [[.4,.2,.4],[.5,.5],[1.]] 
    764867    >>> c = compose(samples, weights) 
    765     >>> d = _mimic(c.coords, c.weights) 
    766     >>> c[0].mean == d[0].mean 
     868    >>> d = _mimic(c.positions, c.weights) 
     869    >>> c[0].center_mass == d[0].center_mass 
    767870    True 
    768871    >>> c[1].range == d[1].range 
     
    799902  if not weights: weights = _uniform_weights(samples) 
    800903  for i in range(len(samples)): 
    801     next = dirac_measure() 
     904    next = measure() 
    802905    for j in range(len(samples[i])): 
    803       next.append(point( samples[i][j], weights[i][j] )) 
     906      next.append(point_mass( samples[i][j], weights[i][j] )) 
    804907    total.append(next) 
    805908  return total 
     
    827930#  """Generate a scenario object from a dataset. The scenario will have 
    828931#uniformly distributed weights and have dimensions given by pts.""" 
    829 coords,values = data.fetch() 
     932positions,values = data.fetch() 
    830933#  from mystic.math.measures import _unpack 
    831 #  pm = compose( _unpack(coords, npts) ) 
     934#  pm = compose( _unpack(positions, npts) ) 
    832935#  return scenario(pm, values[:pm.npts]) 
    833936 
     
    844947def flatten(c): 
    845948  """Flattens a product_measure object into a list.""" 
    846   rv = [(i.weights,i.coords) for i in c] 
     949  rv = [(i.weights,i.positions) for i in c] 
    847950  # now flatten list of lists into just a list 
    848951  return list(chain(*chain(*rv))) # faster than mystic.tools.flatten 
     
    876979  - normalizes weights 
    877980""" 
    878  #from dirac_measure import scenario 
     981 #from measure import scenario 
    879982  def constrain(rv): 
    880983    "constrain:  sum(wi)_{k} = 1 for each k in K" 
     
    8981001  - normalizes weights 
    8991002""" 
    900  #from dirac_measure import scenario 
     1003 #from measure import scenario 
    9011004  from mystic.math.measures import mean, impose_mean 
    9021005 #target[0] is target mean 
     
    9441047  from numpy import sum, asarray 
    9451048  from mystic.math.legacydata import dataset 
    946   from mystic.math.paramtrans import lipschitz_distance, infeasibility, _npts 
     1049  from mystic.math.distance import lipschitz_distance, infeasibility, _npts 
    9471050  if guess is None: 
    9481051    message = "Requires a guess scenario, or a tuple of scenario dimensions." 
     
    10001103    _pm.load(rv, pts)      # here rv is param: w,x,y 
    10011104    if not long_form: 
    1002       coords = _pm.select(*range(npts)) 
    1003     else: coords = _pm.coords 
    1004     _data.load( data.coords, data.values )                        # LOAD static 
     1105      positions = _pm.select(*range(npts)) 
     1106    else: positions = _pm.positions 
     1107    _data.load( data.coords, data.values )                   # LOAD static 
    10051108    if _self: 
    1006       _data.load( coords, _pm.values )                            # LOAD dynamic 
    1007     _data.lipschitz = data.lipschitz                              # LOAD L 
     1109      _data.load( positions, _pm.values )                    # LOAD dynamic 
     1110    _data.lipschitz = data.lipschitz                         # LOAD L 
    10081111    Rv = lipschitz_distance(_data.lipschitz, _pm, _data, tol=cutoff, **kwds) 
    10091112    v = infeasibility(Rv, cutoff) 
     
    10801183""" 
    10811184  from numpy import sum as _sum, asarray 
    1082   from mystic.math.paramtrans import graphical_distance, infeasibility, _npts 
     1185  from mystic.math.distance import graphical_distance, infeasibility, _npts 
    10831186  if guess is None: 
    10841187    message = "Requires a guess scenario, or a tuple of scenario dimensions." 
     
    11781281 
    11791282 
     1283# backward compatibility 
     1284point = point_mass 
     1285dirac_measure = measure 
     1286 
     1287 
    11801288if __name__ == '__main__': 
    1181   from mystic.math.paramtrans import * 
     1289  from mystic.math.distance import * 
    11821290  model = lambda x:sum(x) 
    11831291  a = [0,1,9,8, 1,0,4,6, 1,0,1,2, 0,1,2,3,4,5,6,7] 
     
    11951303  pm = scenario() 
    11961304  pm.load(a, pts) 
    1197   pc = pm.coords 
     1305  pc = pm.positions 
    11981306  pv = pm.values 
    11991307  #--- 
  • mystic/_math/distance.py

    r589 r687  
    11#! /usr/bin/env python 
    22""" 
    3 ...associated transformations for legacy data module 
     3distances and norms for the legacy data module 
    44 
    55lipschitz_distance: ... 
     
    470470  print "\nbuilding a scenario from the params..." 
    471471  # [store Y as 'values' OR register(F) for Y=F(X) OR points store y as 'val' ?] 
    472   from mystic.math.dirac_measure import scenario 
     472  from mystic.math.discrete import scenario 
    473473  pm = scenario() 
    474474  pm.load(param1, pts) 
     
    579579  # member calls # 
    580580  print "\ntesting mean_value..." 
    581   print "mean_value: %s" % pm.get_mean_value() 
     581  print "mean_value: %s" % pm.mean_value() 
    582582  pm.set_mean_value(5.0) 
    583   print "mean_value: %s" % pm.get_mean_value() 
     583  print "mean_value: %s" % pm.mean_value() 
    584584 
    585585  print "\ntesting shortness, feasibility, validity..." 
  • mystic/_math/legacydata.py

    r584 r687  
    328328    if L is None: L = self.lipschitz 
    329329    if data is None: data = self 
    330     from mystic.math.paramtrans import lipschitz_distance, is_feasible 
     330    from mystic.math.distance import lipschitz_distance, is_feasible 
    331331    # calculate the shortness 
    332332    Rv = lipschitz_distance(L, self, data, **kwds) 
     
    376376    elif cutoff is False: cutoff = None 
    377377 
    378     from mystic.math.paramtrans import graphical_distance, is_feasible 
     378    from mystic.math.distance import graphical_distance, is_feasible 
    379379    # calculate the model validity 
    380380    Rv = graphical_distance(model, self, **kwds) 
  • mystic/_math/measures.py

    r686 r687  
    1010from mystic.symbolic import generate_conditions, generate_penalty 
    1111from mystic.math import almostEqual 
     12from __builtin__ import max as _max 
     13from __builtin__ import min as _min 
    1214 
    1315def weighted_select(samples, weights, mass=1.0): 
     
    3941    samples -- a list of sample points 
    4042""" 
    41   return max(samples) - min(samples) 
     43  return _max(samples) - _min(samples) 
    4244 
    4345def norm(weights): 
     
    4951  return mean(weights) 
    5052 
     53def max(f, samples): 
     54  """calculate the max of function for the given list of points 
     55 
     56Inputs:  
     57    f -- a function that takes a list and returns a number 
     58    samples -- a list of sample points 
     59""" 
     60  y = [f(x) for x in samples] 
     61  return _max(y) 
     62 
     63def ess_max(f, samples, weights=None, tol=0.): 
     64  """calculate the max of function for support on the given list of points 
     65 
     66Inputs:  
     67    f -- a function that takes a list and returns a number 
     68    samples -- a list of sample points 
     69    weights -- a list of sample weights 
     70    tol -- weight tolerance, where any weight <= tol is considered zero 
     71""" 
     72  if weights == None: 
     73    return max(f, samples) 
     74  return max(f, support(samples, weights, tol)) 
     75 
     76def min(f, samples): 
     77  """calculate the min of function for the given list of points 
     78 
     79Inputs:  
     80    f -- a function that takes a list and returns a number 
     81    samples -- a list of sample points 
     82""" 
     83  y = [f(x) for x in samples] 
     84  return _min(y) 
     85 
     86def ess_min(f, samples, weights=None, tol=0.): 
     87  if weights == None: 
     88    return min(f, samples) 
     89  return min(f, support(samples, weights, tol)) 
     90 
    5191def expectation(f, samples, weights=None, tol=0.0): 
    5292  """calculate the (weighted) expectation of a function for a list of points 
     
    5696    samples -- a list of sample points 
    5797    weights -- a list of sample weights 
    58     tol -- weight tolerance, where any weight >= tol is ignored 
     98    tol -- weight tolerance, where any weight <= tol is ignored 
    5999""" 
    60100  if weights == None: 
     
    88128  from numpy import inf 
    89129  return ssum * inf  # protect against ZeroDivision 
     130 
     131def support_index(weights, tol=0): 
     132  return [i for (i,w) in enumerate(weights) if w > tol] 
     133 
     134def support(samples, weights, tol=0): 
     135  return [samples[i] for (i,w) in enumerate(weights) if w > tol] 
    90136 
    91137def variance(samples, weights=None): #, _mean=None): 
  • mystic/_math/rounding.py

    r669 r687  
    66__all__ = ['deep_round', 'shallow_round', 'simple_round'] 
    77 
    8 def isiterable(x): 
    9   """check if an object is iterable""" 
    10  #try: 
    11  #    from collections import Iterable 
    12  #    return isinstance(x, Iterable) 
    13  #except ImportError: 
    14   try: 
    15     iter(x) 
    16     return True 
    17   except TypeError: return False 
    18  #return hasattr(x, '__len__') or hasattr(x, '__iter__') 
    19  
     8from mystic.tools import isiterable 
    209#FIXME: these seem *slow*... and a bit convoluted.  Maybe rewrite as classes? 
    2110 
  • mystic/mystic/tools.py

    r677 r687  
    1111 
    1212Main functions exported are::  
     13    - isiterable: check if an object is iterable 
    1314    - flatten: flatten a sequence 
    1415    - flatten_array: flatten an array  
     
    2627    `mystic.mystic.filters` and `mystic.models.poly` 
    2728""" 
     29 
     30def isiterable(x): 
     31    """check if an object is iterable""" 
     32   #try: 
     33   #    from collections import Iterable 
     34   #    return isinstance(x, Iterable) 
     35   #except ImportError: 
     36    try: 
     37        iter(x) 
     38        return True 
     39    except TypeError: return False 
     40   #return hasattr(x, '__len__') or hasattr(x, '__iter__') 
    2841 
    2942def list_or_tuple(x): 
  • mystic/scripts/support_hypercube_scenario.py

    r578 r687  
    324324    # would be nice to use meta = ['wx','wx2','x','x2','wy',...] 
    325325 
    326   from mystic.math.dirac_measure import scenario 
     326  from mystic.math.discrete import scenario 
    327327  from mystic.math.legacydata import dataset 
    328328  try: # select whether to plot the cones 
  • mystic/tests/test_1d2d_expect.py

    r508 r687  
    11from mystic.math.measures import * 
    2 from mystic.math.dirac_measure import * 
     2from mystic.math.discrete import * 
    33from mystic.math import almostEqual 
    44def f(x): return sum(x)/len(x) 
    55 
    6 d2 = dirac_measure([point(1.0, 1.0), point(3.0, 2.0)]) 
    7 d1 = dirac_measure([point(3.0, 2.0)]) 
    8 d2b = dirac_measure([point(2.0, 4.0), point(4.0, 2.0)]) 
     6d2 = measure([point_mass(1.0, 1.0), point_mass(3.0, 2.0)]) 
     7d1 = measure([point_mass(3.0, 2.0)]) 
     8d2b = measure([point_mass(2.0, 4.0), point_mass(4.0, 2.0)]) 
    99p1 = product_measure([d1]) 
    1010p1b = product_measure([d2]) 
     
    1313 
    1414 
    15 # get_expect for product_measure and dirac_measure 
    16 assert almostEqual(d2.get_expect(f), 2.3333333333333335) 
    17 assert almostEqual(p2.get_expect(f), 2.5) 
     15# expect for product_measure and measure 
     16assert almostEqual(d2.expect(f), 2.3333333333333335) 
     17assert almostEqual(p2.expect(f), 2.5) 
    1818 
    19 # set_expect for dirac_measure 
     19# set_expect for measure 
    2020d2.set_expect((2.0,0.001), f, bounds=([0.,0.], [10.,10.]))  
    21 assert almostEqual(d2.get_expect(f), 2.0, tol=0.001) 
    22 #print p2.get_expect(f) 
     21assert almostEqual(d2.expect(f), 2.0, tol=0.001) 
     22#print p2.expect(f) 
    2323 
    2424# set_expect for product_measure 
    2525p2.set_expect((5.0,0.001), f, bounds=([0.,0.,0.,0.],[10.,10.,10.,10.])) 
    26 assert almostEqual(p2.get_expect(f), 5.0, tol=0.001) 
     26assert almostEqual(p2.expect(f), 5.0, tol=0.001) 
    2727 
    2828 
    2929# again, but for single-point measures 
    30 # get_expect for product_measure and dirac_measure 
    31 assert almostEqual(d1.get_expect(f), 3.0) 
    32 assert almostEqual(p1.get_expect(f), 3.0) 
     30# expect for product_measure and measure 
     31assert almostEqual(d1.expect(f), 3.0) 
     32assert almostEqual(p1.expect(f), 3.0) 
    3333 
    34 # set_expect for dirac_measure 
     34# set_expect for measure 
    3535d1.set_expect((2.0,0.001), f, bounds=([0.], [10.]))  
    36 assert almostEqual(d1.get_expect(f), 2.0, tol=0.001) 
    37 #print p1.get_expect(f) 
     36assert almostEqual(d1.expect(f), 2.0, tol=0.001) 
     37#print p1.expect(f) 
    3838 
    3939# set_expect for product_measure 
    4040p1.set_expect((5.0,0.001), f, bounds=([0.],[10.])) 
    41 assert almostEqual(p1.get_expect(f), 5.0, tol=0.001) 
     41assert almostEqual(p1.expect(f), 5.0, tol=0.001) 
    4242 
    4343 
    4444# again, but for mixed measures 
    4545p21.set_expect((6.0,0.001), f) 
    46 assert almostEqual(p21.get_expect(f), 6.0, tol=0.001) 
     46assert almostEqual(p21.expect(f), 6.0, tol=0.001) 
    4747 
  • mystic/tests/test_dirac_measure.py

    r472 r687  
    22""" 
    33TESTS for Dirac measure data objects. 
    4 Includes point, dirac_measure, and product_measure classes. 
     4Includes point_mass, measure, and product_measure classes. 
    55""" 
    66# Adapted from seesaw2d.py in branches/UQ/math/examples2/  
    77# For usage example, see seesaw2d_inf_example.py . 
    88 
    9 from mystic.math.dirac_measure import point 
    10 from mystic.math.dirac_measure import dirac_measure as set 
    11 from mystic.math.dirac_measure import product_measure as collection 
     9from mystic.math.discrete import point_mass as point 
     10from mystic.math.discrete import measure as set 
     11from mystic.math.discrete import product_measure as collection 
    1212from mystic.math.samples import random_samples 
    1313from mystic.math.grid import samplepts 
     
    202202 
    203203  print "mass: %s" % c.mass 
    204   print "expect: %s" % c.get_expect(f) 
     204  print "expect: %s" % c.expect(f) 
    205205 
    206206 #print "center: %s" % c.center 
     
    218218  print "y_coords: %s" % c[1].coords 
    219219  print "z_coords: %s" % c[2].coords 
    220   print "expect: %s" % c.get_expect(f) 
     220  print "expect: %s" % c.expect(f) 
    221221 
    222222  _mean = 85.0 
     
    226226  print "mean: %s" % _mean 
    227227  print "range: %s" % _range 
    228   print "expect: %s" % c.get_expect(f) 
     228  print "expect: %s" % c.expect(f) 
    229229 
    230230  # a test function for probability of failure 
     
    246246 
    247247  # flatten and unflatten 
    248   from mystic.math.dirac_measure import flatten, unflatten 
     248  from mystic.math.discrete import flatten, unflatten 
    249249  d = unflatten(flatten(c), c.pts) 
    250250 
     
    264264 
    265265  # decompose and compose 
    266   from mystic.math.dirac_measure import decompose, compose 
     266  from mystic.math.discrete import decompose, compose 
    267267  b = compose(*decompose(c)) 
    268268 
     
    275275 
    276276if __name__ == '__main__': 
    277   #test_calculate_methods(npts=2) 
    278   #test_set_behavior() 
    279   #test_pack_unpack() 
     277  test_calculate_methods(npts=2) 
     278  test_set_behavior() 
     279  test_pack_unpack() 
    280280  test_collection_behavior() 
    281   #test_flatten_unflatten() 
     281  test_flatten_unflatten() 
    282282  pass 
    283283 
  • mystic/tests/test_expectation.py

    r449 r687  
    111111    print "impose: mean[z] = %s +/- %s" % (str(v_mean),str(v_error)) 
    112112    def constraints(x, w): 
    113       from mystic.math.dirac_measure import compose, decompose 
     113      from mystic.math.discrete import compose, decompose 
    114114      c = compose(x,w) 
    115115      E = float(c[0].mean) 
Note: See TracChangeset for help on using the changeset viewer.