Changeset 687
- Timestamp:
- 06/15/13 18:43:09 (3 years ago)
- Files:
-
- 30 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/UQ/math/examples2/TEST4d_OUQ_surrogate_diam.py
r575 r687 68 68 69 69 from mystic.math.measures import split_param 70 from mystic.math.di rac_measure import product_measure70 from mystic.math.discrete import product_measure 71 71 from mystic.math import almostEqual 72 72 from numpy import inf … … 114 114 # impose expectation on product measure 115 115 ##################### begin function-specific ##################### 116 E = float(c. get_expect(model))116 E = float(c.expect(model)) 117 117 if not (E <= float(target[0] + error[0])) \ 118 118 or not (float(target[0] - error[0]) <= E): … … 130 130 #XXX: apply 'filters' to catch errors in constraints solver (necessary ?) 131 131 ##################### begin function-specific ##################### 132 E = float(c. get_expect(model))132 E = float(c.expect(model)) 133 133 if E > (target[0] + error[0]) or E < (target[0] - error[0]): 134 134 if debug: print "skipping expect: %s" % E … … 238 238 239 239 from numpy import array 240 from mystic.math.di rac_measure import product_measure240 from mystic.math.discrete import product_measure 241 241 c = product_measure() 242 242 c.load(solved,npts) … … 246 246 247 247 # XXX: 4D-expect 248 print "expect: %s" % str( c. get_expect(model) )248 print "expect: %s" % str( c.expect(model) ) 249 249 print "var (x): %s" % str( c[0].var ) # var(h) 250 250 print "mean(x): %s" % str( c[0].mean ) # mean(h) -
branches/UQ/math/examples2/TEST_OUQ_surrogate_diam.py
r575 r687 68 68 69 69 from mystic.math.measures import split_param 70 from mystic.math.di rac_measure import product_measure70 from mystic.math.discrete import product_measure 71 71 from mystic.math import almostEqual 72 72 from numpy import inf … … 94 94 # impose expectation on product measure 95 95 ##################### begin function-specific ##################### 96 E = float(c. get_expect(model))96 E = float(c.expect(model)) 97 97 if not (E <= float(target[0] + error[0])) \ 98 98 or not (float(target[0] - error[0]) <= E): … … 106 106 c = product_measure() 107 107 c.load(rv, npts) 108 E = float(c. get_expect(model))108 E = float(c.expect(model)) 109 109 if E > (target[0] + error[0]) or E < (target[0] - error[0]): 110 110 if debug: print "skipping expect: %s" % E … … 190 190 191 191 from numpy import array 192 from mystic.math.di rac_measure import product_measure192 from mystic.math.discrete import product_measure 193 193 c = product_measure() 194 194 c.load(solved,npts) … … 197 197 print "solved: [wz,z]\n%s" % array(zip(c[2].weights,c[2].coords)) 198 198 199 print "expect: %s" % str( c. get_expect(model) )199 print "expect: %s" % str( c.expect(model) ) 200 200 201 201 # EOF -
branches/UQ/math/legacy/MINMAX_StAlData.py
r585 r687 67 67 def maximize(params,npts,bounds): 68 68 69 from mystic.math.di rac_measure import scenario69 from mystic.math.discrete import scenario 70 70 from numpy import inf 71 71 target,error = params … … 104 104 ##################### begin function-specific ##################### 105 105 # impose norm on the weights of the discrete measures 106 from mystic.math.di rac_measure import norm_wts_constraintsFactory as factory106 from mystic.math.discrete import norm_wts_constraintsFactory as factory 107 107 constrain = factory(npts) 108 108 … … 167 167 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 168 168 npts = (nx,ny,nz) 169 from mystic.math. paramtransimport _npts169 from mystic.math.distance import _npts 170 170 _n = _npts(npts) 171 171 … … 229 229 230 230 from numpy import array 231 from mystic.math.di rac_measure import scenario231 from mystic.math.discrete import scenario 232 232 c = scenario() 233 233 c.load(solved,npts) -
branches/UQ/math/legacy/MM_OUQ_StAlData.py
r675 r687 75 75 def maximize(params,npts,bounds): 76 76 77 from mystic.math.di rac_measure import scenario77 from mystic.math.discrete import scenario 78 78 from numpy import inf 79 79 target,error = params … … 112 112 ##################### begin function-specific ##################### 113 113 # impose mean on the values of the product measure 114 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory114 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 115 115 constrain = factory((target[0],error[0]), npts) 116 116 … … 196 196 nz = 2 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 197 197 npts = (nx,ny,nz) 198 from mystic.math. paramtransimport _npts198 from mystic.math.distance import _npts 199 199 _n = _npts(npts) 200 200 … … 260 260 261 261 from numpy import array 262 from mystic.math.di rac_measure import scenario262 from mystic.math.discrete import scenario 263 263 c = scenario() 264 264 c.load(solved,npts) -
branches/UQ/math/legacy/TEST_OUQ_1dData.py
r585 r687 71 71 def maximize(params,npts,bounds): 72 72 73 from mystic.math.di rac_measure import scenario73 from mystic.math.discrete import scenario 74 74 from numpy import inf 75 75 target,error = params … … 108 108 ##################### begin function-specific ##################### 109 109 # impose mean on the values of the product measure 110 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory110 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 111 111 constrain = factory((target[0],error[0]), npts) 112 112 … … 192 192 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 193 193 npts = (nx,ny,nz) 194 from mystic.math. paramtransimport _npts194 from mystic.math.distance import _npts 195 195 _n = _npts(npts) 196 196 … … 256 256 257 257 from numpy import array 258 from mystic.math.di rac_measure import scenario258 from mystic.math.discrete import scenario 259 259 c = scenario() 260 260 c.load(solved,npts) -
branches/UQ/math/legacy/TEST_OUQ_1dSurr_CxCy.py
r588 r687 73 73 def maximize(params,npts,bounds,printmon=None,**kwds): 74 74 75 from mystic.math.di rac_measure import scenario75 from mystic.math.discrete import scenario 76 76 from numpy import inf 77 77 target,error = params … … 110 110 ##################### begin function-specific ##################### 111 111 # impose mean on the values of the product measure 112 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory112 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 113 113 constrain = factory((target[0],error[0]), npts) 114 114 … … 203 203 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 204 204 npts = (nx,ny,nz) 205 from mystic.math. paramtransimport _npts205 from mystic.math.distance import _npts 206 206 _n = _npts(npts) 207 207 … … 271 271 272 272 from numpy import array 273 from mystic.math.di rac_measure import scenario273 from mystic.math.discrete import scenario 274 274 c = scenario() 275 275 c.load(solved,npts) … … 294 294 try: _Cx = max(Cx) 295 295 except TypeError: _Cx = Cx 296 from mystic.math. paramtransimport graphical_distance296 from mystic.math.distance import graphical_distance 297 297 Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, 298 298 imax=0, hausdorff=hausdorff) -
branches/UQ/math/legacy/TEST_OUQ_1dSurr_Cy.py
r586 r687 73 73 def maximize(params,npts,bounds,printmon=None,**kwds): 74 74 75 from mystic.math.di rac_measure import scenario75 from mystic.math.discrete import scenario 76 76 from numpy import inf 77 77 target,error = params … … 110 110 ##################### begin function-specific ##################### 111 111 # impose mean on the values of the product measure 112 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory112 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 113 113 constrain = factory((target[0],error[0]), npts) 114 114 … … 202 202 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 203 203 npts = (nx,ny,nz) 204 from mystic.math. paramtransimport _npts204 from mystic.math.distance import _npts 205 205 _n = _npts(npts) 206 206 … … 270 270 271 271 from numpy import array 272 from mystic.math.di rac_measure import scenario272 from mystic.math.discrete import scenario 273 273 c = scenario() 274 274 c.load(solved,npts) … … 292 292 try: _Cx = max(Cx) 293 293 except TypeError: _Cx = Cx 294 from mystic.math. paramtransimport graphical_distance294 from mystic.math.distance import graphical_distance 295 295 Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 296 296 printmon.info("vertical_distance: %s <= %s" % (Ry, Cy + _Cx)) -
branches/UQ/math/legacy/TEST_OUQ_StAlData.py
r585 r687 71 71 def maximize(params,npts,bounds): 72 72 73 from mystic.math.di rac_measure import scenario73 from mystic.math.discrete import scenario 74 74 from numpy import inf 75 75 target,error = params … … 108 108 ##################### begin function-specific ##################### 109 109 # impose mean on the values of the product measure 110 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory110 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 111 111 constrain = factory((target[0],error[0]), npts) 112 112 … … 193 193 nz = 2 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 194 194 npts = (nx,ny,nz) 195 from mystic.math. paramtransimport _npts195 from mystic.math.distance import _npts 196 196 _n = _npts(npts) 197 197 … … 257 257 258 258 from numpy import array 259 from mystic.math.di rac_measure import scenario259 from mystic.math.discrete import scenario 260 260 c = scenario() 261 261 c.load(solved,npts) -
branches/UQ/math/legacy/TEST_OUQ_StStSurr_Cy.py
r585 r687 70 70 def maximize(params,npts,bounds): 71 71 72 from mystic.math.di rac_measure import scenario72 from mystic.math.discrete import scenario 73 73 from numpy import inf 74 74 target,error = params … … 107 107 ##################### begin function-specific ##################### 108 108 # impose mean on the values of the product measure 109 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory109 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 110 110 constrain = factory((target[0],error[0]), npts) 111 111 … … 194 194 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 195 195 npts = (nx,ny,nz) 196 from mystic.math. paramtransimport _npts196 from mystic.math.distance import _npts 197 197 _n = _npts(npts) 198 198 … … 257 257 258 258 from numpy import array 259 from mystic.math.di rac_measure import scenario259 from mystic.math.discrete import scenario 260 260 c = scenario() 261 261 c.load(solved,npts) … … 273 273 try: _Cx = max(Cx) 274 274 except TypeError: _Cx = Cx 275 from mystic.math. paramtransimport graphical_distance275 from mystic.math.distance import graphical_distance 276 276 Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, imax=0) 277 277 print "vertical_distance: %s <= %s" % (Ry, Cy + _Cx) -
branches/UQ/math/legacy/envelope/Looper_BoLiSurr_Cy.py
r675 r687 98 98 def maximize(params,npts,bounds,initial=None,job='',printmon=None): 99 99 100 from mystic.math.di rac_measure import scenario100 from mystic.math.discrete import scenario 101 101 from numpy import inf 102 102 target,error = params … … 140 140 ##################### begin function-specific ##################### 141 141 # impose mean on the values of the product measure 142 from mystic.math.di rac_measure import mean_y_norm_wts_constraintsFactory as factory142 from mystic.math.discrete import mean_y_norm_wts_constraintsFactory as factory 143 143 constrain = factory((target[0],error[0]), npts) 144 144 … … 250 250 251 251 npts = (nx,ny,nz) 252 from mystic.math. paramtransimport _npts252 from mystic.math.distance import _npts 253 253 _n = _npts(npts) 254 254 … … 316 316 317 317 from numpy import array 318 from mystic.math.di rac_measure import scenario318 from mystic.math.discrete import scenario 319 319 c = scenario() 320 320 c.load(solved,npts) … … 333 333 # try: _Cx = max(Cx) 334 334 # except TypeError: _Cx = Cx 335 from mystic.math. paramtransimport graphical_distance335 from mystic.math.distance import graphical_distance 336 336 Ry = graphical_distance(model, c, ytol=Cy, xtol=Cx, cutoff=0.0, \ 337 337 imax=0, ipop=cde, hausdorff=hausdorff) -
branches/UQ/math/legacy/envelope/conf_hausd.py
r592 r687 36 36 37 37 # COMPUTING HAUSDORFF DISTANCES 38 from mystic.math. paramtransimport graphical_distance38 from mystic.math.distance import graphical_distance 39 39 d_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)) 40 40 if debug: -
branches/UQ/math/legacy/envelope/envelope.py
r675 r687 15 15 debug = False 16 16 17 from mystic.math. paramtransimport infeasibility, _get_xy17 from mystic.math.distance import infeasibility, _get_xy 18 18 19 19 def graphical_distance(model, points, **kwds): -
branches/UQ/math/legacy/envelope/hausdorff.py
r621 r687 19 19 20 20 # build a scenario 21 from mystic.math.di rac_measure import scenario21 from mystic.math.discrete import scenario 22 22 c = scenario() 23 23 c.load(solved, npts) … … 53 53 #""" 54 54 55 #from mystic.math. paramtransimport graphical_distance55 #from mystic.math.distance import graphical_distance 56 56 from envelope import graphical_distance 57 57 from numpy import set_printoptions -
branches/UQ/math/legacy/envelope/sausage.py
r601 r687 18 18 exec("%s = %s" % (str(k),repr(v))) #XXX: HACK 19 19 20 from mystic.math.di rac_measure import scenario20 from mystic.math.discrete import scenario 21 21 c = scenario() 22 22 c.load(params, pts) … … 28 28 yo = asarray(c.values) 29 29 30 from mystic.math.di rac_measure import impose_valid30 from mystic.math.discrete import impose_valid 31 31 32 32 # fixed x values as bounds -
branches/UQ/math/legacy/test_ExampleDataset.py
r569 r687 31 31 32 32 # Check shortness 33 from mystic.math. paramtransimport lipschitz_distance, graphical_distance33 from mystic.math.distance import lipschitz_distance, graphical_distance 34 34 print("\nshort: %s" % ex1d_data.short()) 35 35 L = ex1d_data.lipschitz; -
branches/UQ/math/legacy/test_StAlDataset.py
r569 r687 21 21 22 22 # Check shortness 23 from mystic.math. paramtransimport lipschitz_distance, graphical_distance23 from mystic.math.distance import lipschitz_distance, graphical_distance 24 24 print("\nshort: %s" % st_al_data.short()) 25 25 L = st_al_data.lipschitz; -
branches/UQ/math/legacy/test_graph_dist.py
r588 r687 33 33 for i in d: print i 34 34 35 from mystic.math. paramtransimport graphical_distance35 from mystic.math.distance import graphical_distance 36 36 from numpy import set_printoptions 37 37 set_printoptions(suppress=True) -
branches/UQ/math/sausage/TEST_OUQ_1dSurr_diam.py
r588 r687 72 72 def maximize(params,npts,bounds): 73 73 74 from mystic.math.di rac_measure import scenario74 from mystic.math.discrete import scenario 75 75 from mystic.math import almostEqual 76 76 from numpy import inf … … 189 189 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 190 190 npts = (nx,ny,nz) 191 from mystic.math. paramtransimport _npts191 from mystic.math.distance import _npts 192 192 _n = _npts(npts) 193 193 … … 253 253 254 254 from numpy import array 255 from mystic.math.di rac_measure import scenario255 from mystic.math.discrete import scenario 256 256 c = scenario() 257 257 c.load(solved,npts) -
branches/UQ/math/sausage/TEST_OUQ_StStSurr.py
r588 r687 71 71 def maximize(params,npts,bounds): 72 72 73 from mystic.math.di rac_measure import scenario73 from mystic.math.discrete import scenario 74 74 from mystic.math import almostEqual 75 75 from numpy import inf … … 201 201 nz = 1 #NOTE: SET THE NUMBER OF 'v' POINTS HERE! 202 202 npts = (nx,ny,nz) 203 from mystic.math. paramtransimport _npts203 from mystic.math.distance import _npts 204 204 _n = _npts(npts) 205 205 … … 265 265 266 266 from numpy import array 267 from mystic.math.di rac_measure import scenario267 from mystic.math.discrete import scenario 268 268 c = scenario() 269 269 c.load(solved,npts) -
branches/collapse/TEST_OUQ_surrogate_diam_collapse.py
r576 r687 58 58 59 59 from mystic.math.measures import split_param 60 from mystic.math.di rac_measure import product_measure60 from mystic.math.discrete import product_measure 61 61 from mystic.math import almostEqual 62 62 from numpy import inf … … 84 84 # impose expectation on product measure 85 85 ##################### begin function-specific ##################### 86 E = float(c. get_expect(model))86 E = float(c.expect(model)) 87 87 if not (E <= float(target[0] + error[0])) \ 88 88 or not (float(target[0] - error[0]) <= E): … … 96 96 c = product_measure() 97 97 c.load(rv, npts) 98 E = float(c. get_expect(model))98 E = float(c.expect(model)) 99 99 if E > (target[0] + error[0]) or E < (target[0] - error[0]): 100 100 if debug: print "skipping expect: %s" % E … … 188 188 189 189 from numpy import array 190 from mystic.math.di rac_measure import product_measure190 from mystic.math.discrete import product_measure 191 191 c = product_measure() 192 192 c.load(solved,npts) … … 195 195 print "solved: [wz,z]\n%s" % array(zip(c[2].weights,c[2].coords)) 196 196 197 print "expect: %s" % str( c. get_expect(model) )197 print "expect: %s" % str( c.expect(model) ) 198 198 199 199 elapsed = (clock() - start) -
branches/collapse/collapse_code.py
r576 r687 37 37 38 38 def _set_weight_to_zero(rv, npts, axisW, indexW): 39 from mystic.math.di rac_measure import product_measure39 from mystic.math.discrete import product_measure 40 40 c = product_measure() 41 41 c.load(rv, npts) … … 44 44 45 45 def _set_same_positions(rv, npts, axisP, index1, index2): 46 from mystic.math.di rac_measure import product_measure46 from mystic.math.discrete import product_measure 47 47 c = product_measure() 48 48 c.load(rv, npts) -
mystic/_math/__init__.py
r468 r687 35 35 # backward compatibility 36 36 from approx import approx_equal 37 import discrete as dirac_measure 38 import distance as paramtrans 37 39 38 40 # end of file -
mystic/_math/discrete.py
r584 r687 1 1 #! /usr/bin/env python 2 2 """ 3 Classes for Diracmeasure data objects.4 Includes point , dirac_measure, product_measure, and scenario classes.3 Classes for discrete measure data objects. 4 Includes point_mass, measure, product_measure, and scenario classes. 5 5 """ 6 6 # Adapted from seesaw2d.py in branches/UQ/math/examples2/ … … 10 10 from mystic.math.measures import impose_spread, impose_variance 11 11 from mystic.math.measures import impose_weight_norm 12 13 class point(object): 14 """ 1-d object with weight and position 12 from __builtin__ import max as _max 13 from __builtin__ import min as _min 14 15 class point_mass(object): 16 """ a point_mass object with weight and position 15 17 16 18 queries: … … 24 26 """ 25 27 26 def __init__(self, position, weight ):28 def __init__(self, position, weight=1.0): 27 29 self.weight = weight 28 30 self.position = position … … 41 43 pass 42 44 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 45 class 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 48 49 49 50 queries: 50 51 s.weights -- returns list of weights 51 s. coords -- returns list of positions52 s.npts -- returns the number of point s52 s.positions -- returns list of positions 53 s.npts -- returns the number of point_masses 53 54 s.mass -- calculates sum of weights 54 s. mean-- calculates sum of weights*positions55 s.center_mass -- calculates sum of weights*positions 55 56 s.range -- calculates |max - min| for positions 56 57 s.var -- calculates mean( |positions - mean(positions)|**2 ) … … 58 59 settings: 59 60 s.weights = [w1, w2, ..., wn] -- set the weights 60 s. coords = [x1, x2, ..., xn] -- set the positions61 s.positions = [x1, x2, ..., xn] -- set the positions 61 62 s.normalize() -- normalize the weights to 1.0 62 s. mean(R) -- set the mean63 s.center_mass(R) -- set the center of mass 63 64 s.range(R) -- set the range 64 65 s.var(R) -- set the variance 65 66 66 67 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 68 75 s.set_expect((center,delta), f) -- impose expectation by adjusting positions 69 76 70 77 notes: 71 78 - 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 85 Inputs: 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 94 Inputs: 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) 74 99 75 100 def __weights(self): … … 89 114 def __mean(self): 90 115 from mystic.math.measures import mean 91 return mean(self. coords, self.weights)116 return mean(self.positions, self.weights) 92 117 93 118 def __range(self): 94 119 from mystic.math.measures import spread 95 return spread(self. coords)120 return spread(self.positions) 96 121 97 122 def __variance(self): 98 123 from mystic.math.measures import variance 99 return variance(self. coords, self.weights)124 return variance(self.positions, self.weights) 100 125 101 126 def __set_weights(self, weights): … … 110 135 111 136 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) 113 139 return 114 140 115 141 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) 117 143 return 118 144 119 145 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) 121 147 return 122 148 123 149 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 156 Inputs: 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 165 Inputs: 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 175 Inputs: 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 184 Inputs: 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): 128 192 """calculate the expectation for a given function 129 193 … … 131 195 f -- a function that takes a list and returns a number 132 196 """ #XXX: maybe more natural if f takes a positional value x, not a list x ? 133 134 197 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) 137 200 138 201 def set_expect(self, (m,D), f, bounds=None, constraints=None): … … 145 208 constraints -- a function that takes a product_measure c' = constraints(c) 146 209 """ #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 ? 148 211 149 212 if constraints: # then need to adjust interface for 'impose_expectation' … … 153 216 return decompose(c)[0] 154 217 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, \ 156 219 self.weights, constraints=cnstr) 157 220 from numpy import array 158 self. coords = list(array(coords)[:,0])221 self.positions = list(array(positions)[:,0]) 159 222 #from numpy import squeeze 160 #self. coords = list(squeeze(coords))223 #self.positions = list(squeeze(positions)) 161 224 return 162 225 163 226 # interface 164 227 weights = property(__weights, __set_weights) 165 coords = property(__positions, __set_positions)228 positions = property(__positions, __set_positions) 166 229 ###XXX: why not use 'points' also/instead? 167 230 npts = property(__n ) 168 231 mass = property(__mass ) 169 232 range = property(__range, __set_range) 170 mean= property(__mean, __set_mean)233 center_mass = property(__mean, __set_mean) 171 234 var = property(__variance, __set_variance) 235 236 # backward compatibility 237 coords = positions 238 get_expect = expect 239 mean = center_mass 172 240 pass 173 241 174 242 class product_measure(list): #FIXME: meant to only accept sets... 175 """ a N-d product measure, a collection of diracmeasures243 """ a N-d measure-theoretic product of discrete measures 176 244 c = product_measure([measure1, measure2, ..., measureN]) 177 245 where all measures are orthogonal 178 246 179 247 queries: 180 c.npts -- returns total number of point s248 c.npts -- returns total number of point_masses 181 249 c.weights -- returns list of weights 182 c. coords -- returns list of position tuples250 c.positions -- returns list of position tuples 183 251 c.mass -- returns list of weight norms 184 c.pts -- returns number of point s for each discrete measure252 c.pts -- returns number of point_masses for each discrete measure 185 253 c.wts -- returns list of weights for each discrete measure 186 254 c.pos -- returns list of positions for each discrete measure 187 255 188 256 settings: 189 c. coords = [(x1,y1,z1),...] -- set thepositions (tuples in product measure)257 c.positions = [(x1,y1,z1),...] -- set positions (tuples in product measure) 190 258 191 259 methods: 192 260 c.pof(f) -- calculate the probability of failure 193 c.sampled_pof(f, npts) -- calculate the pof using sampled point s194 c. get_expect(f) -- calculate the expectation261 c.sampled_pof(f, npts) -- calculate the pof using sampled point_masses 262 c.expect(f) -- calculate the expectation 195 263 c.set_expect((center,delta), f) -- impose expectation by adjusting positions 196 264 c.flatten() -- convert measure to a flat list of parameters … … 201 269 - constraints impose expect (center - delta) <= E <= (center + delta) 202 270 - 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) 204 272 - weight wxi should be same for each (yj,zk) at xi; similarly for wyi & wzi 205 273 """ 206 274 def __val(self): 207 raise NotImplementedError, "'value' is undefined in a dirac_measure"275 raise NotImplementedError, "'value' is undefined in a measure" 208 276 209 277 def __pts(self): … … 214 282 215 283 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 217 294 218 295 def __n(self): 219 296 from numpy import product 220 297 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) 221 306 222 307 def __weights(self): … … 233 318 return _pack(self.pos) 234 319 235 def __set_positions(self, coords):320 def __set_positions(self, positions): 236 321 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] 240 325 return 241 326 … … 249 334 return [self[i].mass for i in range(len(self))] 250 335 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): 252 349 """calculate the expectation for a given function 253 350 … … 256 353 """ 257 354 from mystic.math.measures import expectation 258 return expectation(f, self. coords, self.weights)355 return expectation(f, self.positions, self.weights) 259 356 260 357 def set_expect(self, (m,D), f, bounds=None, constraints=None): … … 275 372 return decompose(c)[0] 276 373 else: cnstr = constraints # 'should' be None 277 self. coords = impose_expectation((m,D), f, self.pts, bounds, self.weights, \278 374 self.positions = impose_expectation((m,D), f, self.pts, bounds, \ 375 self.weights, constraints=cnstr) 279 376 return 280 377 … … 287 384 """ 288 385 u = 0 289 set = zip(self. coords, self.weights)386 set = zip(self.positions, self.weights) 290 387 for x in set: 291 388 if f(x[0]) <= 0.0: … … 293 390 return u 294 391 # for i in range(self.npts): 295 # #if f(self. coords[i]) > 0.0: #NOTE: f(x) > 0.0 yields prob of success296 # if f(self. coords[i]) <= 0.0: #NOTE: f(x) <= 0.0 yields prob of failure392 # #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 297 394 # u += self.weights[i] 298 395 # return u #XXX: does this need to be normalized? … … 304 401 Inputs: 305 402 f -- a function that returns True for 'success' and False for 'failure' 306 npts -- number of point s sampled from the underlying discrete measures403 npts -- number of point_masses sampled from the underlying discrete measures 307 404 """ 308 405 from mystic.math.samples import _pof_given_samples 309 pts = self.s upport(npts)406 pts = self.sampled_support(npts) 310 407 return _pof_given_samples(f, pts) 311 408 312 def s upport(self, npts=10000):409 def sampled_support(self, npts=10000): ##XXX: was 'def support' 313 410 """randomly select support points from the underlying discrete measures 314 411 … … 322 419 pts = [] 323 420 for i in range(npts): 324 # for a single trial, select coords from all sets325 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] ) 326 423 327 424 # convert pts to len(prod_meas) lists, each of len(npts) 328 425 from numpy import transpose 329 return transpose(pts) #XXX: assumes ' coords' is a list of floats426 return transpose(pts) #XXX: assumes 'positions' is a list of floats 330 427 331 428 def update(self, params): … … 349 446 Inputs: 350 447 params -- a list of parameters (see 'notes') 351 pts -- number of point s in each of the underlying discrete measures448 pts -- number of point_masses in each of the underlying discrete measures 352 449 353 450 Notes: … … 405 502 406 503 def select(self, *index, **kwds): 407 """generator for product measure coords due to selected position indicies504 """generator for product measure positions due to selected position indicies 408 505 (NOTE: only works for product measures of dimension 2^K) 409 506 … … 428 525 npts = property(__n ) 429 526 weights = property(__weights ) 430 coords = property(__positions, __set_positions ) 527 positions = property(__positions, __set_positions ) 528 center_mass = property(__mean, __set_mean) 431 529 #center = property(__get_center ) #FIXME: remove c.center and c.delta... or 432 530 #delta = property(__get_delta ) # replace with c._params (e.g. (m,D)) … … 436 534 wts = property(__wts ) 437 535 pos = property(__pos ) 536 537 # backward compatibility 538 coords = positions 539 get_expect = expect 438 540 pass 439 541 … … 442 544 """ a N-d product measure (collection of dirac measures) with values 443 545 s = scenario(product_measure, [value1, value2, ..., valueN]) 444 where each point in the product measure is paried with a value546 where each point_mass in the product measure is paried with a value 445 547 (essentially, a dataset in product_measure representation) 446 548 447 549 queries: 448 s.npts -- returns total number of point s550 s.npts -- returns total number of point_masse 449 551 s.weights -- returns list of weights 450 s. coords -- returns list of position tuples552 s.positions -- returns list of position tuples 451 553 s.values -- returns list of values 452 554 s.mass -- returns list of weight norms 453 s.pts -- returns number of point s for each discrete measure555 s.pts -- returns number of point_masses for each discrete measure 454 556 s.wts -- returns list of weights for each discrete measure 455 557 s.pos -- returns list of positions for each discrete measure 456 558 457 559 settings: 458 s. coords = [(x1,y1,z1),...] -- set thepositions (tuples in product measure)560 s.positions = [(x1,y1,z1),...] -- set positions (tuples in product measure) 459 561 s.values = [v1,v2,v3,...] -- set the values (correspond to position tuples) 460 562 … … 463 565 s.pof_value(f) -- calculate the probability of failure using the values 464 566 s.sampled_pof(f, npts) -- calculate the pof using sampled points 465 s. get_expect(f) -- calculate the expectation567 s.expect(f) -- calculate the expectation 466 568 s.set_expect((center,delta), f) -- impose expectation by adjusting positions 467 s. get_mean_value() -- calculate the mean values for a scenario569 s.mean_value() -- calculate the mean values for a scenario 468 570 s.set_mean_value(m) -- impose mean value by adjusting values 469 571 s.set_feasible(data) -- impose shortness by adjusting positions and values … … 479 581 - constraints impose expect (center - delta) <= E <= (center + delta) 480 582 - 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) 482 584 - weight wxi should be same for each (yj,zk) at xi; similarly for wyi & wzi 483 585 """ … … 488 590 self.load(pm.flatten(), pm.pts) 489 591 if not values: values = [] 490 self.__Y = values # storage for values of s. coords592 self.__Y = values # storage for values of s.positions 491 593 return 492 594 … … 498 600 return 499 601 500 def get_mean_value(self): # get mean of y's602 def mean_value(self): # get mean of y's 501 603 """calculate the mean of the associated values for a scenario""" 502 604 from mystic.math.measures import mean … … 540 642 from mystic.math.legacydata import dataset 541 643 data = dataset() 542 data.load(self. coords, self.values)644 data.load(self.positions, self.values) 543 645 #data.lipschitz = L 544 646 for i in range(len(data)): … … 574 676 from mystic.math.legacydata import dataset 575 677 data = dataset() 576 data.load(self. coords, self.values)678 data.load(self.positions, self.values) 577 679 data.lipschitz = L 578 680 for i in range(len(data)): … … 609 711 from mystic.math.legacydata import dataset 610 712 _self = dataset() 611 _self.load(self. coords, self.values)713 _self.load(self.positions, self.values) 612 714 _self.lipschitz = data.lipschitz 613 715 for i in range(len(_self)): … … 748 850 # interface 749 851 values = property(__values, __set_values ) 852 get_mean_value = mean_value 750 853 pass 751 854 … … 763 866 >>> wts = [[.4,.2,.4],[.5,.5],[1.]] 764 867 >>> c = compose(samples, weights) 765 >>> d = _mimic(c. coords, c.weights)766 >>> c[0]. mean == d[0].mean868 >>> d = _mimic(c.positions, c.weights) 869 >>> c[0].center_mass == d[0].center_mass 767 870 True 768 871 >>> c[1].range == d[1].range … … 799 902 if not weights: weights = _uniform_weights(samples) 800 903 for i in range(len(samples)): 801 next = dirac_measure()904 next = measure() 802 905 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] )) 804 907 total.append(next) 805 908 return total … … 827 930 # """Generate a scenario object from a dataset. The scenario will have 828 931 #uniformly distributed weights and have dimensions given by pts.""" 829 # coords,values = data.fetch()932 # positions,values = data.fetch() 830 933 # from mystic.math.measures import _unpack 831 # pm = compose( _unpack( coords, npts) )934 # pm = compose( _unpack(positions, npts) ) 832 935 # return scenario(pm, values[:pm.npts]) 833 936 … … 844 947 def flatten(c): 845 948 """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] 847 950 # now flatten list of lists into just a list 848 951 return list(chain(*chain(*rv))) # faster than mystic.tools.flatten … … 876 979 - normalizes weights 877 980 """ 878 #from dirac_measure import scenario981 #from measure import scenario 879 982 def constrain(rv): 880 983 "constrain: sum(wi)_{k} = 1 for each k in K" … … 898 1001 - normalizes weights 899 1002 """ 900 #from dirac_measure import scenario1003 #from measure import scenario 901 1004 from mystic.math.measures import mean, impose_mean 902 1005 #target[0] is target mean … … 944 1047 from numpy import sum, asarray 945 1048 from mystic.math.legacydata import dataset 946 from mystic.math. paramtransimport lipschitz_distance, infeasibility, _npts1049 from mystic.math.distance import lipschitz_distance, infeasibility, _npts 947 1050 if guess is None: 948 1051 message = "Requires a guess scenario, or a tuple of scenario dimensions." … … 1000 1103 _pm.load(rv, pts) # here rv is param: w,x,y 1001 1104 if not long_form: 1002 coords = _pm.select(*range(npts))1003 else: coords = _pm.coords1004 _data.load( data.coords, data.values ) 1105 positions = _pm.select(*range(npts)) 1106 else: positions = _pm.positions 1107 _data.load( data.coords, data.values ) # LOAD static 1005 1108 if _self: 1006 _data.load( coords, _pm.values )# LOAD dynamic1007 _data.lipschitz = data.lipschitz 1109 _data.load( positions, _pm.values ) # LOAD dynamic 1110 _data.lipschitz = data.lipschitz # LOAD L 1008 1111 Rv = lipschitz_distance(_data.lipschitz, _pm, _data, tol=cutoff, **kwds) 1009 1112 v = infeasibility(Rv, cutoff) … … 1080 1183 """ 1081 1184 from numpy import sum as _sum, asarray 1082 from mystic.math. paramtransimport graphical_distance, infeasibility, _npts1185 from mystic.math.distance import graphical_distance, infeasibility, _npts 1083 1186 if guess is None: 1084 1187 message = "Requires a guess scenario, or a tuple of scenario dimensions." … … 1178 1281 1179 1282 1283 # backward compatibility 1284 point = point_mass 1285 dirac_measure = measure 1286 1287 1180 1288 if __name__ == '__main__': 1181 from mystic.math. paramtransimport *1289 from mystic.math.distance import * 1182 1290 model = lambda x:sum(x) 1183 1291 a = [0,1,9,8, 1,0,4,6, 1,0,1,2, 0,1,2,3,4,5,6,7] … … 1195 1303 pm = scenario() 1196 1304 pm.load(a, pts) 1197 pc = pm. coords1305 pc = pm.positions 1198 1306 pv = pm.values 1199 1307 #--- -
mystic/_math/distance.py
r589 r687 1 1 #! /usr/bin/env python 2 2 """ 3 ...associated transformations forlegacy data module3 distances and norms for the legacy data module 4 4 5 5 lipschitz_distance: ... … … 470 470 print "\nbuilding a scenario from the params..." 471 471 # [store Y as 'values' OR register(F) for Y=F(X) OR points store y as 'val' ?] 472 from mystic.math.di rac_measure import scenario472 from mystic.math.discrete import scenario 473 473 pm = scenario() 474 474 pm.load(param1, pts) … … 579 579 # member calls # 580 580 print "\ntesting mean_value..." 581 print "mean_value: %s" % pm. get_mean_value()581 print "mean_value: %s" % pm.mean_value() 582 582 pm.set_mean_value(5.0) 583 print "mean_value: %s" % pm. get_mean_value()583 print "mean_value: %s" % pm.mean_value() 584 584 585 585 print "\ntesting shortness, feasibility, validity..." -
mystic/_math/legacydata.py
r584 r687 328 328 if L is None: L = self.lipschitz 329 329 if data is None: data = self 330 from mystic.math. paramtransimport lipschitz_distance, is_feasible330 from mystic.math.distance import lipschitz_distance, is_feasible 331 331 # calculate the shortness 332 332 Rv = lipschitz_distance(L, self, data, **kwds) … … 376 376 elif cutoff is False: cutoff = None 377 377 378 from mystic.math. paramtransimport graphical_distance, is_feasible378 from mystic.math.distance import graphical_distance, is_feasible 379 379 # calculate the model validity 380 380 Rv = graphical_distance(model, self, **kwds) -
mystic/_math/measures.py
r686 r687 10 10 from mystic.symbolic import generate_conditions, generate_penalty 11 11 from mystic.math import almostEqual 12 from __builtin__ import max as _max 13 from __builtin__ import min as _min 12 14 13 15 def weighted_select(samples, weights, mass=1.0): … … 39 41 samples -- a list of sample points 40 42 """ 41 return max(samples) -min(samples)43 return _max(samples) - _min(samples) 42 44 43 45 def norm(weights): … … 49 51 return mean(weights) 50 52 53 def max(f, samples): 54 """calculate the max of function for the given list of points 55 56 Inputs: 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 63 def ess_max(f, samples, weights=None, tol=0.): 64 """calculate the max of function for support on the given list of points 65 66 Inputs: 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 76 def min(f, samples): 77 """calculate the min of function for the given list of points 78 79 Inputs: 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 86 def 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 51 91 def expectation(f, samples, weights=None, tol=0.0): 52 92 """calculate the (weighted) expectation of a function for a list of points … … 56 96 samples -- a list of sample points 57 97 weights -- a list of sample weights 58 tol -- weight tolerance, where any weight >= tol is ignored98 tol -- weight tolerance, where any weight <= tol is ignored 59 99 """ 60 100 if weights == None: … … 88 128 from numpy import inf 89 129 return ssum * inf # protect against ZeroDivision 130 131 def support_index(weights, tol=0): 132 return [i for (i,w) in enumerate(weights) if w > tol] 133 134 def support(samples, weights, tol=0): 135 return [samples[i] for (i,w) in enumerate(weights) if w > tol] 90 136 91 137 def variance(samples, weights=None): #, _mean=None): -
mystic/_math/rounding.py
r669 r687 6 6 __all__ = ['deep_round', 'shallow_round', 'simple_round'] 7 7 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 8 from mystic.tools import isiterable 20 9 #FIXME: these seem *slow*... and a bit convoluted. Maybe rewrite as classes? 21 10 -
mystic/mystic/tools.py
r677 r687 11 11 12 12 Main functions exported are:: 13 - isiterable: check if an object is iterable 13 14 - flatten: flatten a sequence 14 15 - flatten_array: flatten an array … … 26 27 `mystic.mystic.filters` and `mystic.models.poly` 27 28 """ 29 30 def 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__') 28 41 29 42 def list_or_tuple(x): -
mystic/scripts/support_hypercube_scenario.py
r578 r687 324 324 # would be nice to use meta = ['wx','wx2','x','x2','wy',...] 325 325 326 from mystic.math.di rac_measure import scenario326 from mystic.math.discrete import scenario 327 327 from mystic.math.legacydata import dataset 328 328 try: # select whether to plot the cones -
mystic/tests/test_1d2d_expect.py
r508 r687 1 1 from mystic.math.measures import * 2 from mystic.math.di rac_measure import *2 from mystic.math.discrete import * 3 3 from mystic.math import almostEqual 4 4 def f(x): return sum(x)/len(x) 5 5 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)])6 d2 = measure([point_mass(1.0, 1.0), point_mass(3.0, 2.0)]) 7 d1 = measure([point_mass(3.0, 2.0)]) 8 d2b = measure([point_mass(2.0, 4.0), point_mass(4.0, 2.0)]) 9 9 p1 = product_measure([d1]) 10 10 p1b = product_measure([d2]) … … 13 13 14 14 15 # get_expect for product_measure and dirac_measure16 assert almostEqual(d2. get_expect(f), 2.3333333333333335)17 assert almostEqual(p2. get_expect(f), 2.5)15 # expect for product_measure and measure 16 assert almostEqual(d2.expect(f), 2.3333333333333335) 17 assert almostEqual(p2.expect(f), 2.5) 18 18 19 # set_expect for dirac_measure19 # set_expect for measure 20 20 d2.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)21 assert almostEqual(d2.expect(f), 2.0, tol=0.001) 22 #print p2.expect(f) 23 23 24 24 # set_expect for product_measure 25 25 p2.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)26 assert almostEqual(p2.expect(f), 5.0, tol=0.001) 27 27 28 28 29 29 # again, but for single-point measures 30 # get_expect for product_measure and dirac_measure31 assert almostEqual(d1. get_expect(f), 3.0)32 assert almostEqual(p1. get_expect(f), 3.0)30 # expect for product_measure and measure 31 assert almostEqual(d1.expect(f), 3.0) 32 assert almostEqual(p1.expect(f), 3.0) 33 33 34 # set_expect for dirac_measure34 # set_expect for measure 35 35 d1.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)36 assert almostEqual(d1.expect(f), 2.0, tol=0.001) 37 #print p1.expect(f) 38 38 39 39 # set_expect for product_measure 40 40 p1.set_expect((5.0,0.001), f, bounds=([0.],[10.])) 41 assert almostEqual(p1. get_expect(f), 5.0, tol=0.001)41 assert almostEqual(p1.expect(f), 5.0, tol=0.001) 42 42 43 43 44 44 # again, but for mixed measures 45 45 p21.set_expect((6.0,0.001), f) 46 assert almostEqual(p21. get_expect(f), 6.0, tol=0.001)46 assert almostEqual(p21.expect(f), 6.0, tol=0.001) 47 47 -
mystic/tests/test_dirac_measure.py
r472 r687 2 2 """ 3 3 TESTS for Dirac measure data objects. 4 Includes point , dirac_measure, and product_measure classes.4 Includes point_mass, measure, and product_measure classes. 5 5 """ 6 6 # Adapted from seesaw2d.py in branches/UQ/math/examples2/ 7 7 # For usage example, see seesaw2d_inf_example.py . 8 8 9 from mystic.math.di rac_measure importpoint10 from mystic.math.di rac_measure import dirac_measure as set11 from mystic.math.di rac_measure import product_measure as collection9 from mystic.math.discrete import point_mass as point 10 from mystic.math.discrete import measure as set 11 from mystic.math.discrete import product_measure as collection 12 12 from mystic.math.samples import random_samples 13 13 from mystic.math.grid import samplepts … … 202 202 203 203 print "mass: %s" % c.mass 204 print "expect: %s" % c. get_expect(f)204 print "expect: %s" % c.expect(f) 205 205 206 206 #print "center: %s" % c.center … … 218 218 print "y_coords: %s" % c[1].coords 219 219 print "z_coords: %s" % c[2].coords 220 print "expect: %s" % c. get_expect(f)220 print "expect: %s" % c.expect(f) 221 221 222 222 _mean = 85.0 … … 226 226 print "mean: %s" % _mean 227 227 print "range: %s" % _range 228 print "expect: %s" % c. get_expect(f)228 print "expect: %s" % c.expect(f) 229 229 230 230 # a test function for probability of failure … … 246 246 247 247 # flatten and unflatten 248 from mystic.math.di rac_measure import flatten, unflatten248 from mystic.math.discrete import flatten, unflatten 249 249 d = unflatten(flatten(c), c.pts) 250 250 … … 264 264 265 265 # decompose and compose 266 from mystic.math.di rac_measure import decompose, compose266 from mystic.math.discrete import decompose, compose 267 267 b = compose(*decompose(c)) 268 268 … … 275 275 276 276 if __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() 280 280 test_collection_behavior() 281 #test_flatten_unflatten()281 test_flatten_unflatten() 282 282 pass 283 283 -
mystic/tests/test_expectation.py
r449 r687 111 111 print "impose: mean[z] = %s +/- %s" % (str(v_mean),str(v_error)) 112 112 def constraints(x, w): 113 from mystic.math.di rac_measure import compose, decompose113 from mystic.math.discrete import compose, decompose 114 114 c = compose(x,w) 115 115 E = float(c[0].mean)
Note: See TracChangeset
for help on using the changeset viewer.