From ecf2925418b3ffa66bdd1a6b988eb03e30c9b1c5 Mon Sep 17 00:00:00 2001
From: "Michele.Maris" <michele.maris@inaf.it>
Date: Fri, 21 Jul 2023 01:23:48 +0200
Subject: [PATCH] u added stats.py

---
 src/yapsut/__init__.py |  1 +
 src/yapsut/stats.py    | 43 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 src/yapsut/stats.py

diff --git a/src/yapsut/__init__.py b/src/yapsut/__init__.py
index bc7d5e9..ddc8eb0 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 0000000..de76405
--- /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)
+   
-- 
GitLab