Simple and small performance improvements

This commit is contained in:
Grant Sanderson
2018-08-18 20:13:49 -07:00
parent 6f57a8bc5e
commit 039f7ffe58
3 changed files with 29 additions and 5 deletions

View File

@ -8,6 +8,17 @@ def sigmoid(x):
return 1.0 / (1 + np.exp(-x))
CHOOSE_CACHE = {}
def choose_using_cache(n, r):
if n not in CHOOSE_CACHE:
CHOOSE_CACHE[n] = {}
if r not in CHOOSE_CACHE[n]:
CHOOSE_CACHE[n][r] = choose(n, r)
return CHOOSE_CACHE[n][r]
def choose(n, r):
if n < r:
return 0