JuliaDiff / FiniteDiff.jl

Fast non-allocating calculations of gradients, Jacobians, and Hessians with sparsity support
http://juliadiff.org/FiniteDiff.jl/
Other
247 stars 38 forks source link

Syntax for derivatives in specific directions #149

Closed volkerkarle closed 2 years ago

volkerkarle commented 2 years ago

Hi, first let me thank you for this amazing package, using it heavily now.

So I was thinking what would be the best practice to take specific derivatives. For instance, consider a function f(a,b,c), but I'd like to take the derivative only in one specific direction. Right now I'll write it as

∂(f,x) = FiniteDiff.finite_difference_gradient(f, x)

f(a,b,c) = a^2 + b^2 + c^2 # only example

function ∂f∂b(a,b,c)
    f2(b) = f(a,b,c)
    return ∂(f2,[b])
end

It would be cool to work with this in a more functional (i.e. closer to mathematical syntax) way. Maybe it's already possible, what are your suggestions?

Thanks! v.

ChrisRackauckas commented 2 years ago

https://github.com/JuliaDiff/SparseDiffTools.jl has this as jacvec. num_jacvec(f,x,[0.0,1.0,0.0])

volkerkarle commented 2 years ago

OK Thanks, I'll look into it!