Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 615:0954aaf28231
Merge
| author | MohamedGomaa |
|---|---|
| date | Wed, 10 Dec 2014 14:12:06 -0500 |
| parents | 84690dfe5560 c5406edbcf12 |
| children | c9a0b72979fd |
comparison
equal
deleted
inserted
replaced
| 613:306db0f3c7a2 | 615:0954aaf28231 |
|---|---|
| 59 | 59 |
| 60 class EmpiricalDistribution: | 60 class EmpiricalDistribution: |
| 61 def nSamples(self): | 61 def nSamples(self): |
| 62 return sum(self.counts) | 62 return sum(self.counts) |
| 63 | 63 |
| 64 def cumulativeDensityFunction(sample): | 64 def cumulativeDensityFunction(sample, normalized = False): |
| 65 '''Returns the cumulative density function of the sample of a random variable''' | 65 '''Returns the cumulative density function of the sample of a random variable''' |
| 66 from numpy.core.multiarray import array | 66 from numpy import arange, cumsum |
| 67 from numpy.lib.function_base import unique | 67 xaxis = sorted(sample) |
| 68 from numpy.core.fromnumeric import sum | 68 counts = arange(1,len(sample)+1) # dtype = float |
| 69 a = array(sample) | 69 if normalized: |
| 70 a.sort() | 70 counts /= float(len(sample)) |
| 71 xaxis = unique(a) | |
| 72 counts = [sum(a <= x) for x in xaxis] | |
| 73 return xaxis, counts | 71 return xaxis, counts |
| 74 | 72 |
| 75 class EmpiricalDiscreteDistribution(EmpiricalDistribution): | 73 class EmpiricalDiscreteDistribution(EmpiricalDistribution): |
| 76 '''Class to represent a sample of a distribution for a discrete random variable | 74 '''Class to represent a sample of a distribution for a discrete random variable |
| 77 ''' | 75 ''' |
