Skip to content
Snippets Groups Projects
Commit cb590328 authored by Stephan Kuschel's avatar Stephan Kuschel
Browse files

add weighted quantile and median.

parent 9c55f055
No related branches found
Tags v0.1.0
No related merge requests found
......@@ -577,6 +577,25 @@ class ParticleAnalyzer(object):
m = np.average(data, weights=w)
return np.average((data - m)**2, weights=w)
def quantile(self, func, q, weights=1.0):
'''
The qth-quantile of the distribution.
'''
if q < 0 or q > 1:
raise ValueError('Quantile q ({:}) must be in range [0, 1]'.format(q))
w = self.weight() * weights
data = func(self)
sortidx = np.argsort(data)
wcs = np.cumsum(w[sortidx])
idx = np.searchsorted(wcs, wcs[-1]*np.array(q))
return data[sortidx[idx]]
def median(self, func, weights=1.0):
'''
The median
'''
return self.quantile(func, 0.5, weights=weights)
# ---- Functions to create a Histogram. ---
def createHistgram1d(self, scalarfx, optargsh={'bins': 300},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment