Last active
September 24, 2015 07:57
-
-
Save jweinst1/c43a2a59300f1a50200d to your computer and use it in GitHub Desktop.
probability toolkit.py
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
#prob function toolkit | |
from decimal import * | |
#takes a decimal probability | |
def chance(choose, total): | |
getcontext().prec = 6 | |
return float(Decimal(choose)/Decimal(total)) | |
#checks probability of choosing elem from a lst. | |
def occurence(elem, lst): | |
getcontext().prec = 6 | |
size = lst.count(elem) | |
return chance(size, len(lst)) | |
def get_chances(lst): | |
return {x:occurence(x, lst) for x in lst} | |
def best_chance(lst): | |
dict = {occurence(x, lst):x for x in lst} | |
return dict[max(dict.keys())] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment