Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/utils.py @ 1105:e62c2f5e25e6
added sampling function
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 14 Mar 2019 17:08:05 -0400 |
| parents | 7594802f281a |
| children | 91faf679e898 |
comparison
equal
deleted
inserted
replaced
| 1104:1c59091853e0 | 1105:e62c2f5e25e6 |
|---|---|
| 628 headers.append('{}{}'.format(method,c)) | 628 headers.append('{}{}'.format(method,c)) |
| 629 else: | 629 else: |
| 630 aggFunctions[method] = aggregationFunction(method) | 630 aggFunctions[method] = aggregationFunction(method) |
| 631 headers.append(method) | 631 headers.append(method) |
| 632 return aggFunctions, headers | 632 return aggFunctions, headers |
| 633 | |
| 634 def maxSumSample(d, maxSum): | |
| 635 '''Generates a sample from distribution d (type scipy.stats, using rvs method) | |
| 636 until the sum of all elements is larger than maxSum''' | |
| 637 s = 0 # sum | |
| 638 sample = [] | |
| 639 while s < maxSum: | |
| 640 x = d.rvs() | |
| 641 sample.append(x) | |
| 642 s += x | |
| 643 return sample | |
| 633 | 644 |
| 634 ######################### | 645 ######################### |
| 635 # regression analysis using statsmodels (and pandas) | 646 # regression analysis using statsmodels (and pandas) |
| 636 ######################### | 647 ######################### |
| 637 | 648 |
