Changeset 822
- Timestamp:
- 08/17/15 05:56:16 (9 months ago)
- Location:
- mystic/_math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/_math/distance.py
r792 r822 15 15 """ 16 16 debug = False 17 18 def Lnorm(weights, p=1): 19 "calculate L-p norm of weights" 20 # weights is a numpy array 21 # p is an int 22 if not p: 23 w = float(len(weights[weights != 0.0])) # total number of nonzero elements 24 else: 25 w = float(sum(abs(weights**p)))**(1./p) 26 return w 17 27 18 28 def absolute_distance(x, xp, up=False, dmin=0): -
mystic/_math/measures.py
r821 r822 15 15 from mystic.symbolic import generate_conditions, generate_penalty 16 16 from mystic.math import almostEqual 17 from mystic.math.distance import Lnorm 17 18 18 19 def weighted_select(samples, weights, mass=1.0): … … 388 389 389 390 390 def Lnorm(weights, n=1):391 "calculate L-n norm of weights"392 # weights is a numpy array393 # n is an int394 if not n:395 w = float(len(weights[weights != 0.0])) # total number of nonzero elements396 else:397 w = float(sum(abs(weights**n)))**(1./n)398 return w399 400 401 391 def normalize(weights, mass='l2', zsum=False, zmass=1.0): 402 392 """normalize a list of points (e.g. normalize to 1.0) … … 575 565 weights -- a list of sample weights 576 566 """ 577 s = sarray(samples)567 s = asarray(samples) 578 568 return median(abs(s - median(samples,weights)),weights) # * scale 579 569
Note: See TracChangeset
for help on using the changeset viewer.