Fix compounding and decaying utils

This commit is contained in:
Matthew Honnibal 2017-05-25 17:15:39 -05:00
parent df8015f05d
commit 80cf42e33b
1 changed files with 2 additions and 2 deletions

View File

@ -326,7 +326,7 @@ def compounding(start, stop, compound):
>>> assert next(sizes) == 1.5 * 1.5 >>> assert next(sizes) == 1.5 * 1.5
''' '''
def clip(value): def clip(value):
return max(value, stop) if (start>stop) else min(value, start) return max(value, stop) if (start>stop) else min(value, stop)
curr = float(start) curr = float(start)
while True: while True:
yield clip(curr) yield clip(curr)
@ -336,7 +336,7 @@ def compounding(start, stop, compound):
def decaying(start, stop, decay): def decaying(start, stop, decay):
'''Yield an infinite series of linearly decaying values.''' '''Yield an infinite series of linearly decaying values.'''
def clip(value): def clip(value):
return max(value, stop) if (start>stop) else min(value, start) return max(value, stop) if (start>stop) else min(value, stop)
nr_upd = 1. nr_upd = 1.
while True: while True:
yield clip(start * 1./(1. + decay * nr_upd)) yield clip(start * 1./(1. + decay * nr_upd))