Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect hessian returned for prod #120

Open
sethaxen opened this issue Jan 27, 2022 · 1 comment
Open

Incorrect hessian returned for prod #120

sethaxen opened this issue Jan 27, 2022 · 1 comment

Comments

@sethaxen
Copy link

The (i,j)th element of the Hessian of y=prod(x) is y/x[i]/x[j] for i ≠ j and 0 for i==j, i.e. its diagonal is zero. However,

julia> x = randn(3)
3-element Vector{Float64}:
  0.11546090256645888
  2.4121509171945448
 -1.6103562544798857

julia> Tracker.hessian(prod, x)
Tracked 3×3 Matrix{Float64}:
 33.6428  0.0        0.0
  0.0     0.0770819  0.0
  0.0     0.0        0.172949

I believe this stems from the custom rule Tracker uses for prod.

@sethaxen sethaxen changed the title Incorrect hessians rteturned for prod Incorrect hessian returned for prod Jan 27, 2022
@MariusDrulea
Copy link

I believe this stems from the custom rule Tracker uses for prod.

You mean this function? Seem to be correct.

@grad function prod(xs; dims=:)
  p = prod(data(xs); dims=dims)
  p, Δ -> (p ./ xs .* Δ,)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants