Changeset 822


Ignore:
Timestamp:
08/17/15 05:56:16 (9 months ago)
Author:
mmckerns
Message:

moved Lnorm to mystic.math.distance; fix: typo in mystic.math.mad

Location:
mystic/_math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mystic/_math/distance.py

    r792 r822  
    1515""" 
    1616debug = False  
     17 
     18def 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 
    1727 
    1828def absolute_distance(x, xp, up=False, dmin=0): 
  • mystic/_math/measures.py

    r821 r822  
    1515from mystic.symbolic import generate_conditions, generate_penalty 
    1616from mystic.math import almostEqual 
     17from mystic.math.distance import Lnorm 
    1718 
    1819def weighted_select(samples, weights, mass=1.0): 
     
    388389 
    389390 
    390 def Lnorm(weights, n=1): 
    391   "calculate L-n norm of weights" 
    392   # weights is a numpy array 
    393   # n is an int 
    394   if not n: 
    395     w = float(len(weights[weights != 0.0])) # total number of nonzero elements 
    396   else: 
    397     w = float(sum(abs(weights**n)))**(1./n) 
    398   return w 
    399  
    400  
    401391def normalize(weights, mass='l2', zsum=False, zmass=1.0): 
    402392  """normalize a list of points (e.g. normalize to 1.0) 
     
    575565    weights -- a list of sample weights 
    576566""" 
    577     s = sarray(samples) 
     567    s = asarray(samples) 
    578568    return median(abs(s - median(samples,weights)),weights) # * scale 
    579569 
Note: See TracChangeset for help on using the changeset viewer.