Automatic differentiation seems a little like magic. ?OnceDifferentiable
is not very informative. Experimenting with it, I want to see, e.g., what happens if my function uses abs()
. As always, I want to start with something simple:
julia> using Optim
julia> myfun(x::Vector{Float64})= (x[1]-2)^2 + (x[2]-3)^2 + (x[1]*x[2])^2;
julia> od = OnceDifferentiable(myfun, [ 0.0, 0.0 ]; autodiff = :forward);
I hope my two questions now are simple:
-
Why does an automatic differentiator need an initial_x value, at all? Is it to understand the dimensionality of the function (here 2)? Would it be better, then, to have an int argument requesting the length?
-
How can I use the resulting
od
object to request the gradient at a particular location? I can useod.f( 2.0, 3.0 )
to use the function, but how do I obtain the two gradients at point[ 2.0, 3.0]
?
Advice appreciated.
PS: Does Optim.DifferentiableFunction
still exist?