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

Compute Hessian of MbP dynamics function #13586

Open
hongkai-dai opened this issue Jun 22, 2020 · 6 comments
Open

Compute Hessian of MbP dynamics function #13586

hongkai-dai opened this issue Jun 22, 2020 · 6 comments
Assignees

Comments

@hongkai-dai
Copy link
Contributor

hongkai-dai commented Jun 22, 2020

If I have a function f(u, q, v, v̇, λ) = M * v̇ + C(q, v) - Bu - J'λ, I wish to compute the Hessian of this function f w.r.t u, q, v, v̇, λ. Some of the Hessian terms are easy to compute, but to compute ∂² f / ∂ q², it requires computing the Hessian of ∂² M / ∂ q² and ∂² C / ∂ q², which I don't know how to do yet.

I guess the easiest solution might be to instantiate MBP with nested AutoDiffScalar.

@sherm1

@sherm1
Copy link
Member

sherm1 commented Jun 22, 2020

Since f is a vector function, ∂f / ∂q is a matrix. That makes ∂²f / ∂q² a hypermatrix. Is that what you're looking for?

@hongkai-dai
Copy link
Contributor Author

I should have been more clear, I mean ∂²f(i) / ∂q², namely the second order derivative of the i'th entry of f w.r.t q.

@sherm1
Copy link
Member

sherm1 commented Jun 22, 2020

We don't have a way to calculate just a single generalized force f(i) so the nested AutoDiff calculation would give { ∂²f(i)/∂q² | i ∈ 0..n-1 }. (That's a way to represent the 3D hypermatrix.) I'm not seeing an easier way to get that though.

You don't have u in the functional dependence of f. Should it be there?

@hongkai-dai
Copy link
Contributor Author

You don't have u in the functional dependence of f. Should it be there?

Yes u should be there also.

We don't have a way to calculate just a single generalized force f(i) so the nested AutoDiff calculation would give { ∂²f(i)/∂q² | i ∈ 0..n-1 }. (That's a way to represent the 3D hypermatrix.) I'm not seeing an easier way to get that though.

Makes sense. I think if we use nested autodiff, we can still return f as an Eigen::Vector, where the i'th entry of this f contains the value of f, the gradient and the Hessian.

@sherm1
Copy link
Member

sherm1 commented Jun 23, 2020

Yes, each entry would contain its value, gradient, and Hessian.
Added u in the issue description.

BTW @edrumwri wrote a document on AutoDiffing that has a Hessian section.

Assigning to @rpoyner-tri for now as vaguely related to #10991 -- this is an application that would really stretch AutoDiff performance!

@sherm1 sherm1 added component: multibody plant MultibodyPlant and supporting code component: system framework System, Context, and supporting code type: feature request labels Jun 23, 2020
@jwnimmer-tri jwnimmer-tri removed the component: system framework System, Context, and supporting code label Nov 11, 2021
@jwnimmer-tri jwnimmer-tri changed the title Compute Hessian of MBP dynamics function Compute Hessian of MbP dynamics function Nov 12, 2021
@rpoyner-tri
Copy link
Contributor

Given where our thinking about autodiff is going, I'm handing this back to @hongkai-dai for further consideration.

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

No branches or pull requests

4 participants