Mercurial Hosting > traffic-intelligence
changeset 1105:e62c2f5e25e6
added sampling function
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 14 Mar 2019 17:08:05 -0400 |
parents | 1c59091853e0 |
children | 799ef82caa1a |
files | trafficintelligence/utils.py |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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)