# HG changeset patch # User Nicolas Saunier # Date 1551464264 18000 # Node ID 7594802f281abc9fbccb9b9f08b2f357b8f5cce3 # Parent cdf1773ba89e0824c9626349be9d19aec1a98d53 added constant distribution diff -r cdf1773ba89e -r 7594802f281a trafficintelligence/utils.py --- 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