test_2nd_order_grads.py 文件源码

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

项目:Theano-Deep-learning 作者: GeekLiB 项目源码 文件源码
def test_jacobian_disconnected_inputs():
    """
    Test that disconnected inputs are properly handled by jacobian.
    """
    v1 = tensor.vector()
    v2 = tensor.vector()
    jacobian_v = theano.gradient.jacobian(1 + v1, v2, disconnected_inputs='ignore')
    func_v = theano.function([v1, v2], jacobian_v)
    val = numpy.arange(4.0).astype(theano.config.floatX)
    assert numpy.allclose(func_v(val, val), numpy.zeros((4, 4)))

    s1 = tensor.scalar()
    s2 = tensor.scalar()
    jacobian_s = theano.gradient.jacobian(1 + s1, s2, disconnected_inputs='ignore')
    func_s = theano.function([s2], jacobian_s)
    val = numpy.array(1.0).astype(theano.config.floatX)
    assert numpy.allclose(func_s(val), numpy.zeros(1))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号