ChainRulesTestUtils.jl
ChainRulesTestUtils.jl copied to clipboard
Testing derivatives via Integral
The fundamental theorem of calculus says that differential problems can also be expressed as Integral problems. Certain functions like clamp, max, min lack a definition of derivatives at every point. When you perform a finite difference approximation the result will certainly be in doubt around these points. Integrals would be mostly immune against those defects.
Do you have any thoughts on idea?
I would be more inclined to suggest using either forwards- or reverse- differencing around discontinuities. i.e you set up your tests so that finite differences avoids the discontinuities. See eg. FiniteDifferences.forward_fdm
and FiniteDifferences.reverse_fdm
.
While I agree that quadrature-based tests are appealing, I would imagine they'll also struggle in the vicinity of discontinuities since they usually assume some form of smoothness.
It's an interesting idea. But I feel like it would be hard to get accuracy. Also really expensive at higher dimensions? Not sure.
Testing both sides of discontinualities is I think pretty standard.
Would be interesting to see it coded up and tested. Even if it doesn't work great, would still make an interesting blog post