test_activations.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:MLAlgorithms 作者: rushter 项目源码 文件源码
def test_softplus():
    # np.exp(z_max) will overflow
    z_max = np.log(sys.float_info.max) + 1.0e10
    # 1.0 / np.exp(z_min) will overflow
    z_min = np.log(sys.float_info.min) - 1.0e10
    inputs = np.array([0.0, 1.0, -1.0, z_min, z_max])
    # naive implementation of np.log(1 + np.exp(z_max)) will overflow
    # naive implementation of z + np.log(1 + 1 / np.exp(z_min)) will
    # throw ZeroDivisionError
    outputs = np.array([
      np.log(2.0),
      np.log1p(np.exp(1.0)),
      np.log1p(np.exp(-1.0)),
      0.0,
      z_max
    ])

    assert np.allclose(outputs, softplus(inputs))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号