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

(stess)test derivatives

Open tpapp opened this issue 6 years ago • 2 comments

DynamicHMC does not deal well with incorrect deriatives. These can result from AD errors (conceptual errors in mature AD libraries are rare, but numerical corner cases can still happen), or bugs in manually coded derivatives.

There should be functionality to test for these things. Ideally independently of AD, eg with finite differences, possibly using Richardson extrapolation (is there a package for that?).

Decisions to make: should this be part of stresstest, or something else?

tpapp avatar Apr 09 '19 15:04 tpapp

I do think this would be useful.

The problem I had in the other issue was resolved, and the result of misspecified analytical gradients/Jacobian which was used by AD. The bias was subtle, because it was in the log determinant contribution of a variance parameter in a matrix normal distribution. This can be swamped by the quadratic form when far from the posterior mode (eg, as when just evaluating it at randn(dimension(ℓ))).

Calculus.jl already has a check_gradient function. While check_gradient doesn't use it, they also have taylor finite difference, which looks worth considering.

chriselrod avatar Apr 10 '19 08:04 chriselrod

I find https://github.com/JuliaDiff/FiniteDifferences.jl excellent for calculating derivatives (explicitly avoiding AD, because very often that's what I want to test), so we could support that.

tpapp avatar Dec 15 '23 16:12 tpapp