Advanced Computing Platform for Theoretical Physics

Commit 5b33ec83 authored by Maximilian Soelch's avatar Maximilian Soelch
Browse files

IsNan stopping criterion works with gnumpy now

added isnan to climin.mathadapt to this end; moreover, some
documentation was added.
parent 0e42a903
......@@ -96,3 +96,11 @@ def scalar(x):
if not x.size == 1:
raise ValueError('size is %i instead of 1' % x.size)
return x.reshape((1,))[0]
def isnan(x):
"""Delegate to gnumpy.isnan or numpy.isnan depending on the type of `x`."""
if not isinstance(x, np.ndarray):
return gp.isnan(x)
else:
return np.isnan(x)
......@@ -32,6 +32,8 @@ import time
import numpy as np
from climin.mathadapt import isnan
class AfterNIterations(object):
"""AfterNIterations class.
......@@ -195,13 +197,31 @@ class NotBetterThanAfter(object):
class IsNaN(object):
"""Stop criterion that returns True if any value corresponding to user-specified keys is NaN."""
"""Stop criterion that returns True if any value corresponding to
user-specified keys is NaN.
Attributes
----------
keys : list
List of keys to check whether nan or not
Examples
--------
>>> stop = S.IsNaN(['test']); stop({'test': 0})
False
>>> stop({'test': numpy.nan})
True
>>> stop({'test': gnumpy.as_garray(numpy.nan)})
True
"""
def __init__(self, keys=[]):
self.keys = keys
def __call__(self, info):
return any([np.isnan(info.get(key, 0)) for key in self.keys])
return any([isnan(info.get(key, 0)) for key in self.keys])
class Patience(object):
......
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