Gradients
The supertype Gradient comprises different ways of taking gradients:
We first start by showing GradientAutodiff:
f(x::AbstractArray) = sum(x .^ 2)
x = rand(3)
grad = GradientAutodiff(f, x)GradientAutodiff{Float64, typeof(Main.f), ForwardDiff.GradientConfig{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3, Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3}}}}(Main.f, ForwardDiff.GradientConfig{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3, Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3}}}((Partials(1.0, 0.0, 0.0), Partials(0.0, 1.0, 0.0), Partials(0.0, 0.0, 1.0)), ForwardDiff.Dual{ForwardDiff.Tag{typeof(Main.f), Float64}, Float64, 3}[Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.94578447815305e-310,6.945784386126e-310,6.94578438612404e-310,6.94578447834356e-310), Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.9457844783416e-310,6.9457844783396e-310,6.9457844783341e-310,6.94578447833684e-310), Dual{ForwardDiff.Tag{typeof(Main.f), Float64}}(6.945784415564e-310,6.9457844783309e-310,6.94578447832775e-310,6.9457844783246e-310)]))Every struct derived from Gradient (including GradientAutodiff) has an associated functor:
grad(x)3-element Vector{Float64}:
1.042427591070766
1.1736135149066969
1.7817573961855622