-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross derivatives of a multivariate function? #205
Comments
Hey @daisukeadachi, If using LinearAlgebra
using FiniteDifferences
m = central_fdm(5, 1)
# Don't use adaptation for the inner method.
m_no_adapt = central_fdm(5, 1, adapt=0)
f(x) = [dot(x, x), 2dot(x, x)]
d = jacobian(m, x -> jacobian(m_no_adapt, f, x)[1], x)[1]
d = reshape(d, 2, 3, 3) # Undo the vectorisation. The two outputs come first.
# Hessian for the first output:
@assert isapprox(d[1, :, :], 2I)
# Hessian for the second output:
@assert isapprox(d[2, :, :], 4I) |
Does this generalise straightforwardly to higher dimensions? E.g. I have a 5x5x5 array, where each entry depends on 5 parameters and I want to differentiate it w.r.t. those 5 parameters to get a 5x5x5x5 array, where e.g. the derivative w.r.t. the first parameter is stored in the first sub-array :
I would assume this is achieved in the same way, i.e.
I am unsure because I fear that the indices could get all messed up in the process of vectorising and reshaping at higher dimensions. |
Hey @paulc-git! I believe this should readily generalise to higher dimensions in the way you describe. You’re right that it’s not obvious whether the indexing just works out, but I believe that it should. |
Hello,
I hope all is well. I have a question about the title. I am interested in computing a$M\times N \times N$ three-way array of derivatives:
where$f$ is a $M$ vector of functions $f_i \ (i=1,\ldots,M)$ , and each $f_i$ takes $x \in \mathbb{R}^N$ as its arguments. What is the best way to compute this object in
FiniteDifferences.jl
?This is clearly not a Jacobian, but I tried to do$M\times N \times N$ array but an $M\times N$ array. So what is it supposed to compute?
jacobian(central_fdm(5,2), myfun, myval)
just to what it gives. It did not give an error or anBest,
Daisuke
The text was updated successfully, but these errors were encountered: