diff python/utils.py @ 615:0954aaf28231

Merge
author MohamedGomaa
date Wed, 10 Dec 2014 14:12:06 -0500
parents 84690dfe5560 c5406edbcf12
children c9a0b72979fd
line wrap: on
line diff
--- a/python/utils.py	Thu Dec 04 19:07:55 2014 -0500
+++ b/python/utils.py	Wed Dec 10 14:12:06 2014 -0500
@@ -61,15 +61,13 @@
     def nSamples(self):
         return sum(self.counts)
 
-def cumulativeDensityFunction(sample):
+def cumulativeDensityFunction(sample, normalized = False):
     '''Returns the cumulative density function of the sample of a random variable'''
-    from numpy.core.multiarray import array
-    from numpy.lib.function_base import unique
-    from numpy.core.fromnumeric import sum
-    a = array(sample)
-    a.sort()
-    xaxis = unique(a)
-    counts = [sum(a <= x) for x in xaxis]
+    from numpy import arange, cumsum
+    xaxis = sorted(sample)
+    counts = arange(1,len(sample)+1) # dtype = float
+    if normalized:
+        counts /= float(len(sample))
     return xaxis, counts
 
 class EmpiricalDiscreteDistribution(EmpiricalDistribution):