Advanced Computing Platform for Theoretical Physics

Commit a039f11b authored by Justin Bayer's avatar Justin Bayer
Browse files

added way to add deep keys for Patience criterion

parent 9a68fd42
......@@ -247,6 +247,10 @@ class Patience(object):
i = info['n_iter']
if isinstance(self.func_or_key, (str, unicode)):
loss = info[self.func_or_key]
elif isinstance(self.func_or_key, (tuple, list)):
loss = info
for j in self.func_or_key:
loss = loss[j]
else:
loss = self.func_or_key()
......
......@@ -28,3 +28,14 @@ def test_patience_increase():
assert not stopper({'n_iter': 4})
assert not stopper({'n_iter': 5})
assert stopper({'n_iter': 6})
def test_patience_deep():
vals = iter([{'foo': {'bar': 10}}] * 4).next
func = iter([10, 10, 10, 10]).next
stopper = Patience(('foo', 'bar'), 3, 2)
assert not stopper({'n_iter': 0, 'foo': {'bar': 10}})
assert not stopper({'n_iter': 1, 'foo': {'bar': 10}})
assert not stopper({'n_iter': 2, 'foo': {'bar': 10}})
assert stopper({'n_iter': 3, 'foo': {'bar': 10}}), 'initial patience should be over'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment