def _logexpm1(x):
"""Stably calculate log(exp(x)-1)."""
with ops.name_scope("logsumexp1"):
eps = np.finfo(x.dtype.as_numpy_dtype).eps
# Choose a small offset that makes gradient calculations stable for
# float16, float32, and float64.
safe_log = lambda y: math_ops.log(y + eps / 1e8) # For gradient stability
return array_ops.where(
math_ops.abs(x) < eps,
safe_log(x) + x/2 + x*x/24, # small x approximation to log(expm1(x))
safe_log(math_ops.exp(x) - 1))
stochastic_gradient_estimators.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录