diff --git a/src/yapsut/__init__.py b/src/yapsut/__init__.py index bc7d5e9cd22c746be058ffe5c8977ea0d9207e7a..ddc8eb0cdb3630b0e4b13c08c83594f9764ddbbc 100644 --- a/src/yapsut/__init__.py +++ b/src/yapsut/__init__.py @@ -14,6 +14,7 @@ from .nearly_even_split import nearly_even_split from .geometry import ElipsoidTriangulation from .template_subs import discoverKeys, templateFiller from .periodic_stats import periodic_stats, periodic_centroid +from .stats import CumulativeOfData #from import .grep #import .intervalls diff --git a/src/yapsut/stats.py b/src/yapsut/stats.py new file mode 100644 index 0000000000000000000000000000000000000000..de76405442552a7f2d23de72e04153409dcd4cff --- /dev/null +++ b/src/yapsut/stats.py @@ -0,0 +1,43 @@ +""" +Simple stats +""" + +import numpy as np + +class CumulativeOfData : + """strucuture to handle the cumulative of 1d data""" + @property + def cdf(self) : + """the cdf """ + return self._cdf + @property + def x(self) : + """the score""" + return self._x + @property + def N(self) : + """the number of finite samples""" + return self._N + def __init__(self,X) : + """:X: 1d array of scores""" + idx=np.where(np.isfinite(X)) + xf=X[idx] + self._Nin=len(X) + self._N=len(xf) + self._x=np.sort(X) + self._eff=np.arange(self._N)/(self._N-1) + def cdf(self,x) : + """returns the cdf at a given score + + :x: the score + """ + return np.interp(x,self._x,self._eff,left=0.,right=1.) + def percentile(self,eff) : + """computes the percentile of samples for which x<=percentile(eff) + + :eff: the required percentile [0,1] + if eff<0 the result is -infty + if eff>0 the result is +infty + """ + return np.interp(eff,self._eff,self._x,left=-np.infty,right=np.infty) +