Opensim vs Moco optimization algorithm

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Sun Jun 25, 2023 8:57 am

Hello,

Hope you are doing well. I have a question regarding the optimization algorithm applied in moco vs opensim.
1) Is there a difference and if yes, what are the key differences?
2) Would the differences affect the residual error being calculated?

Additionally, in the documentation, it was mentioned that moco uses two models (one without constraints and one with constraints ) to calculate multipliers for forces and muscle activations. If my focus is just on residual error, what is the difference between OpenSim's IK and moco's track?

Thanks

User avatar
Nicholas Bianco
Posts: 1025
Joined: Thu Oct 04, 2012 8:09 pm

Re: Opensim vs Moco optimization algorithm

Post by Nicholas Bianco » Mon Jun 26, 2023 1:20 pm

Hello Radhakrishnan,

Moco uses direct collocation to solve optimal control problems. This method takes an optimal control problem and converts it to a non-linear program, which can be solved with off-the-shelf solvers like IPOPT.

OpenSim's inverse kinematics solver is also a non-linear optimization problem, but it does not use direct collocation. In the IK problem, the joint angles are the optimization varibles and the cost function is the error between model and experimental markers. IK does not include the model dynamics, so there are no residual forces.

-Nick

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Mon Jun 26, 2023 1:23 pm

Hello Nicholas,

Thanks for your response.

If my focus is just on marker residual errors, would there be a difference between IK and MOCO results? For example, if I do not provide grf data.

Thanks
Vignesh

User avatar
Nicholas Bianco
Posts: 1025
Joined: Thu Oct 04, 2012 8:09 pm

Re: Opensim vs Moco optimization algorithm

Post by Nicholas Bianco » Mon Jun 26, 2023 1:24 pm

Hi Radhakrishnan,

Thanks for the clarification. In that case, you can just use inverse kinematics. It will be faster than Moco for just minimize marker errors.

-Nick

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Mon Jun 26, 2023 1:28 pm

Hi Nick,

Thank yoi. I shall do that. Out of curiosity:

1) Would there be a difference in residual errors calculated using MOCO and IK? From another post, IK uses different solvers based on the constraints and coordinates such as LBFGS, LBFGSB method and IPOPT. There hasnt been any information on how this changes the residual error, so I am curious

Thanks,
vignesh

User avatar
Nicholas Bianco
Posts: 1025
Joined: Thu Oct 04, 2012 8:09 pm

Re: Opensim vs Moco optimization algorithm

Post by Nicholas Bianco » Mon Jun 26, 2023 1:42 pm

You could probably achieve similar marker errors, but would likely get different solutions since the methods are fundamentally different.

With Moco, you would get a "dynamically-consistent" inverse kinematics solutions since Moco will enforce dynamic consistency as part of the optimization problem. Whereas with IK, the solver is just posing the model in different configurations to minimize marker errors.

IPOPT settings (e.g., LBFGS) are less important than the differences in the two methods here.

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Mon Jun 26, 2023 1:44 pm

Thanks a lot for the clarification.

Regards,
Vignesh

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Wed Jul 12, 2023 3:12 am

Hi Nicholas,

I have two additional questions sorry:

1) When you mention 'dynamically-consistent', what exactly do you mean by that? What are the optimisation variables in MOCO? And if my model had just a pelvis and femur, would the angles between IK and MOCO differ?

2) Is there any influence of scaling in MOCO? None of the examples, mention scaling or a scaled model. So does scaling not influence the results of MOCO ?

Thanks

User avatar
Nicholas Bianco
Posts: 1025
Joined: Thu Oct 04, 2012 8:09 pm

Re: Opensim vs Moco optimization algorithm

Post by Nicholas Bianco » Wed Jul 12, 2023 10:15 am

Hi Vignesh,

1) "Dynamically-consistent" means that the joint angles and speeds produced by Moco are consistent with the forces acting at the model joints. Inverse kinematics just finds a set of joint angles that minimizes marker error and doesn't consider model forces. As long as the model has forces acting at the pelvis and hip joint, Moco should produce similar results.

2) Moco uses the model that you provide to solve an optimization problem. If you want to study the motion of a specific subject, then you should use a model scaled to that subject. Whether or not a model is scaled will not change how a problem is solved, but it will certainly affect results.

Best,
Nick

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Opensim vs Moco optimization algorithm

Post by Radhakrishnan Vignesh » Wed Jul 12, 2023 10:59 am

Hi Nicholas,

Thanks a lot for your reply. Sorry, I have one additional question. I understand that the algorithm used between OpenSim IK and Moco differ, I would like to know, how the optimisation function works in detail. Specifically,

1) What is the optimisation function for marker tracking or track? How are the mobilizers integrated in them? I think, that reduction of marker error is still he cost function, so are the mobilizers used as conditions to be matched.

2) Are there any rigid body constraints? For example, ensuring segment length is fixed, joint centre location etc? How is this accounted for and where in the code can this be studied? Does scaling of the model play into rigid body constraints?

3) I understand that the free joint is currently not supported in MOCO but if I use a custom joint with 6DoF, I would expect really small residual errors? Is my understanding wrong? If the residual errors are large, which part of the optimisation function prevents the reduction in marker error in a 6DoF joint.

I have asked a similar question in OpenSim's forum. But would like to understand Moco;s too

Thanks
Vignesh

POST REPLY