提交 fbac37c6 authored 作者: James Bergstra's avatar James Bergstra

Fixed the numeric-gradient algorithm to return Inf error if any of the numeric…

Fixed the numeric-gradient algorithm to return Inf error if any of the numeric errors is NaN or Inf.
上级 61182725
...@@ -3470,7 +3470,10 @@ class numeric_grad: ...@@ -3470,7 +3470,10 @@ class numeric_grad:
raise ValueError('argument element %i has wrong shape %s' %(i,str((a.shape, raise ValueError('argument element %i has wrong shape %s' %(i,str((a.shape,
b.shape)))) b.shape))))
errs.append(numpy.max(numeric_grad.abs_rel_err(a,b))) errs.append(numpy.max(numeric_grad.abs_rel_err(a,b)))
return numpy.max(errs), numpy.argmax(errs) if numpy.all(numpy.isfinite(errs)):
return numpy.max(errs), numpy.argmax(errs)
else:
return float('inf'), 0
def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast_to_output_type=False): def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast_to_output_type=False):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论