Mercurial Hosting > traffic-intelligence
changeset 1103:7594802f281a
added constant distribution
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 01 Mar 2019 13:17:44 -0500 |
parents | cdf1773ba89e |
children | 1c59091853e0 |
files | trafficintelligence/utils.py |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/utils.py Wed Feb 27 16:28:08 2019 -0500 +++ b/trafficintelligence/utils.py Fri Mar 01 13:17:44 2019 -0500 @@ -136,6 +136,17 @@ '''Returns the Chi2 statistics''' return sum([((e-o)*(e-o))/float(e) for e, o in zip(expected, observed)]) +class ConstantDistribution(object): + '''Distribution returning always the same value for the random variable ''' + def __init__(self, value): + self.value = value + + def rvs(self, size = 1): + if size == 1: + return self.value + else: + return array([self.value]*size) + class EmpiricalContinuousDistribution(rv_continuous): def __init__(self, values, probabilities, **kwargs): '''The values (and corresponding probabilities) are supposed to be sorted by value