Created
January 28, 2020 16:36
-
-
Save emtwo/95b420b21041db47efb5b331011e43b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def exponential_range(min, max, bucket_count): | |
log_max = math.log(max); | |
ranges = [] | |
current = min; | |
if current == 0: | |
current = 1 | |
# undeflow bucket | |
ranges.append(0) | |
ranges.append(current) | |
for i in range(2, bucket_count): | |
log_current = math.log(current) | |
log_ratio = (log_max - log_current) / (bucket_count - i) | |
log_next = log_current + log_ratio | |
next_value = round(math.exp(log_next)) | |
current = next_value if next_value > current else current + 1 | |
ranges.append(current) | |
return ranges | |
def exponential_bucketing(): | |
print(exponential_range(0, 10000, 50)) | |
exponential_bucketing() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment