# HG changeset patch # User Nicolas Saunier # Date 1552597685 14400 # Node ID e62c2f5e25e63960a1410c944b440791ce8b89ad # Parent 1c59091853e0ae5775a6cff8b1ddffea1da631e3 added sampling function diff -r 1c59091853e0 -r e62c2f5e25e6 trafficintelligence/utils.py --- a/trafficintelligence/utils.py Mon Mar 11 15:41:05 2019 -0400 +++ b/trafficintelligence/utils.py Thu Mar 14 17:08:05 2019 -0400 @@ -630,6 +630,17 @@ aggFunctions[method] = aggregationFunction(method) headers.append(method) return aggFunctions, headers + +def maxSumSample(d, maxSum): + '''Generates a sample from distribution d (type scipy.stats, using rvs method) + until the sum of all elements is larger than maxSum''' + s = 0 # sum + sample = [] + while s < maxSum: + x = d.rvs() + sample.append(x) + s += x + return sample ######################### # regression analysis using statsmodels (and pandas)