Skip to content
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

Derivative of a function of derivatives #673

Open
tlorance opened this issue Nov 16, 2023 · 7 comments
Open

Derivative of a function of derivatives #673

tlorance opened this issue Nov 16, 2023 · 7 comments

Comments

@tlorance
Copy link

First, for context: I am new to both Julia and ForwardDiff, but I am experienced at coding. For my project, I need to compute the first derivative of a 2x2 determinant where the elements of the determinant are second-order partial derivatives; specifically, I need CodeCogsEqn (1) and CodeCogsEqn (2) where
CodeCogsEqn
I am not sure why the two mixed partial derivatives don't cancel; it might have something to do with the fact that this is a ternary data system (where x1 + x2 + x3 is constrained to equal 1).
At any rate, is this possible in ForwardDiff, or do I need to do finite differentiation on the sigma obtained from a ForwardDiff hessian?

@mcabbott
Copy link
Member

The obvious thing here is ForwardDiff.gradient(x -> det(ForwardDiff.hessian(g, x)), x). Does this fail?

@tlorance
Copy link
Author

That might work; I didn't know you could do that. Just to be clear, though, my determinant is not the full determinant of the hessian (which would be a 3x3), so I'm still not sure how to construct it. I will experiment with the ForwardDiff.hessian function, see how its output is formatted, and see if I can select the first two rows and columns via an inline method.

@tlorance
Copy link
Author

I am new enough to Julia that I am not entirely sure which "x"s in your formula should be replaced with my input and which should be left alone (since my function is defined as g(x::Vector)=...). However, it was easy to select the first two rows and columns via an inline method, so I'm sure this will work, as soon as I figure it out.

@tlorance
Copy link
Author

Final question: is the partial derivative in row 2, column 1 of my formula in the corresponding location in the hessian?

@tlorance
Copy link
Author

Well, the code runs and appears to function, but the answer is very different from what I obtained by hand-coding a finite difference, so I think I screwed something up.

@longemen3000
Copy link

is this related to criticality conditions?

@tlorance
Copy link
Author

I found an example in a journal article, coded the example, and managed to replicate it, so perhaps the code is OK and my hand-coded version is wrong. I still have issues, but they seem to be chemistry issues, not numerical methods issues, so: thank you very much, your solution worked like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants