Mercurial > hg > nsaunier > traffic-intelligence
comparison python/utils.py @ 588:c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 05 Dec 2014 00:54:38 -0500 |
| parents | e24eeb244698 |
| children | 0954aaf28231 |
comparison
equal
deleted
inserted
replaced
| 587:cf578ba866da | 588:c5406edbcf12 |
|---|---|
| 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 ''' |
