JuliaDiff / ForwardDiff.jl

Forward Mode Automatic Differentiation for Julia
Other
894 stars 148 forks source link

recommended method for unit testing #284

Open tpapp opened 6 years ago

tpapp commented 6 years ago

Suppose I write a function f(x, y). Is there a recommended API for unit testing that it works (at least runs) with ForwardDiff? For example, the minimum requirement would be that it is capable of handling Dual numbers, and returns Duals too (is there anything else?).

Currently I am just generating arguments of random Duals and then check that the return type has the same element type. But it is pretty ad hoc, and I would prefer to do the right thing.

jrevels commented 6 years ago

This is a very good question. Currently, ForwardDiff uses finite differencing to check against its test suite, but it would be quite useful to have a more formal verification tool that could prove a target Julia program's differentiability. Testing against finite differencing is really annoying due to its approximation error.

cossio commented 6 years ago

Another possibility is complex step differentiation, https://blogs.mathworks.com/cleve/2013/10/14/complex-step-differentiation/