-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Add rev functor to compute hessian-times-vector by finite differences #2914
Conversation
I don't think it is valid to choose a different epsilon for each dimension, wouldn't that just change the vector we multiply the hessian with? |
I think you're right - this just so happened to have worked because the Do you think there is a better way of automatically deciding an epsilon, or should I just skip the call to |
I don't know of any better way, but that doesn't mean there isn't one... :-) |
stan/math/rev/functor/finite_diff_hessian_times_vector_auto.hpp
Outdated
Show resolved
Hide resolved
stan/math/rev/functor/finite_diff_hessian_times_vector_auto.hpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@andrjohns mind re-approving? The auto formatting commit dismissed your last review |
Summary
This adds a function analogous to
finite_diff_hessian_auto
for computing Hessian-vector products of functions which only supportrev
mode types. This can be done with only two calls togradient
, compared to the2N
calls needed for the naive approach of usingfinite_diff_hessian_auto
and then multiplying.The approach is described by @justindomke here: https://justindomke.wordpress.com/2009/01/17/hessian-vector-products/
In short,
If$g(x) = \frac{\partial f}{\partial x} f(x)$ , then $g(x+\Delta x) \approx g(x) + H(x)\Delta x$
$H(x)v \approx \frac{g(x + rv) - g(x - rv)}{2r}$
So
See also: discussion in roualdes/bridgestan#126
Tests
I have duplicated the existing test used for autodiff Hessian-vector products. There is only one, so more might be nice.
Side Effects
None
Release notes
New function in
stan::math::internal
,finite_diff_hessian_vector_product_auto
Checklist
Math issue: closes Hessian-vector product with central finite differences #2913
Copyright holder: Simons Foundation
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested