Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 197:2788b2827670
simple cumulatie function distribution computation
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 08 Feb 2012 15:02:30 -0500 |
| parents | c06379f25ab8 |
| children | ca9d9104afba |
comparison
equal
deleted
inserted
replaced
| 196:aeab0b88c9b6 | 197:2788b2827670 |
|---|---|
| 67 | 67 |
| 68 class EmpiricalDistribution: | 68 class EmpiricalDistribution: |
| 69 def nSamples(self): | 69 def nSamples(self): |
| 70 return sum(self.counts) | 70 return sum(self.counts) |
| 71 | 71 |
| 72 def cumulativeDensityFunction(sample): | |
| 73 'Returns the cumulative density function of the sample of a random variable' | |
| 74 from numpy.core.multiarray import array | |
| 75 from numpy.lib.function_base import unique | |
| 76 from numpy.core.fromnumeric import sum | |
| 77 a = array(sample) | |
| 78 a.sort() | |
| 79 xaxis = unique(a) | |
| 80 counts = [sum(a <= x) for x in xaxis] | |
| 81 return xaxis, counts | |
| 72 | 82 |
| 73 class EmpiricalDiscreteDistribution(EmpiricalDistribution): | 83 class EmpiricalDiscreteDistribution(EmpiricalDistribution): |
| 74 '''Class to represent a sample of a distribution for a discrete random variable | 84 '''Class to represent a sample of a distribution for a discrete random variable |
| 75 ''' | 85 ''' |
| 76 from numpy.core.fromnumeric import sum | 86 from numpy.core.fromnumeric import sum |
