AutoGrad.jl icon indicating copy to clipboard operation
AutoGrad.jl copied to clipboard

missing Jacobian and Hessian methods

Open CarloLucibello opened this issue 7 years ago • 2 comments

eventually trough Jacobian-vector product. Nice related blog post https://j-towns.github.io/2017/06/12/A-new-trick.html

CarloLucibello avatar Feb 20 '18 13:02 CarloLucibello

I see in @CarloLucibello's PR #57 how to compute hessians with the old interface. Is there an easy way to compute hessians also with the new interface?

jbrea avatar Oct 10 '19 08:10 jbrea

You can still use the old interface, here is an example from our SGDDynamics project:

function hessian(loss,w,x,y)
    ∇loss = grad(loss)
    ∇lossi(w,x,y,i) = ∇loss(w,x,y)[i]
    ∇∇lossi = grad(∇lossi)
    w = value(w)
    n = length(w)
    h = similar(Array(w),n,n)
    for i in progress(1:n)
        h[:,i] .= Array(vec(∇∇lossi(w,x,y,i)))
    end
    return h
end

denizyuret avatar Oct 14 '19 06:10 denizyuret