MoCoInverse : Objective Function not Converging

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Sivaprasad Kunnath
Posts: 11
Joined: Mon Jun 03, 2024 2:13 am

MoCoInverse : Objective Function not Converging

Post by Sivaprasad Kunnath » Tue Jun 04, 2024 9:28 pm

Hi,

I am trying to run MocoInverse for an Upper limb arm model. I have the joint kinematics, and external forces file in sto format. I also defined an xml file for estimating inverse dynamics using mocoInverse. I defined the model as follow

Code: Select all

try {
		MocoInverse inverse;
		inverse.setName("matLab_motion");

		ModelProcessor modelProcessor(model);
		modelProcessor.append(ModOpAddExternalLoads(extFrc_path));
		modelProcessor.append(ModOpAddReserves());
		modelProcessor.append(ModOpIgnoreTendonCompliance());
		inverse.setModel(modelProcessor);
		
		inverse.setKinematics(TableProcessor(ik_path));
		inverse.set_mesh_interval(0.002);
		inverse.set_initial_time(0);
		inverse.set_final_time(1.2);
		MocoInverseSolution solution = inverse.solve();
		solution.getMocoSolution().write("MocoInverse_solution.sto");

	}
	catch (const std::exception& ex) {
		std::cout << "Exception: " << ex.what() << std::endl;
		return 1;
	}
	catch (...) {
		std::cout << "UNRECOGNIZED EXCEPTION" << std::endl;
		return 1;
	}
This runs without error, but doesn't converge to the solution. I have searched for similar posts about solution not converging and couldn't find any relevant posts. I also attach the txt file with the output. I am unsure how to move forward and would appreciate any guidance to relevant documentation.

Thanks for the support.
Attachments
Output_noConverg.txt
(49.04 KiB) Downloaded 61 times

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

Re: MoCoInverse : Objective Function not Converging

Post by Nicholas Bianco » Thu Jun 06, 2024 9:06 am

Hi Sivaprasad,

Most likely, the model is not strong enough to match the prescribed motion and applied ground reaction forces. Alternatively, there could be issues with the input data causing the problem to be badly conditioned. The ground reaction forces can often be problematic not filtered properly or if the centers of pressure are incorrect.

I would recommend taking a look at trajectory in your failed solution to see which actuators are hitting their bounds as a guide on how to modify the model. To do this, you need to "unseal" the solution:

Code: Select all

solutionSealed = solution.getMocoSolution();
solution = solutionSealed.unseal();
solution.write("MocoInverse_solution.sto");
Best,
Nick

User avatar
Sivaprasad Kunnath
Posts: 11
Joined: Mon Jun 03, 2024 2:13 am

Re: MoCoInverse : Objective Function not Converging

Post by Sivaprasad Kunnath » Mon Jul 01, 2024 8:20 pm

Hey Nicholas,

I tried to troubleshoot the data and the model as suggested. I am applying a constant force to the model to generate the motion. The motion was generated in matlab and extended to opensim model by generating a 2 DOF motion at 2 joints. I tried to roughly run it in Opensim, and the Inverse dynamics performed generated the expected results in Opensim GUI. This suggests that the ground reaction forces are correctly applied to the model.

Static optimisation to find muscle contributions however failed to provide results, and the message suggested the model being weak. I'm encountering the error for the first time, and would appreciate any insights on how to troubleshoot.

Regarding analysing the output, I tried to unseal the convergence solution, but the iterations seems to go on until 600 and more and had to be manually killed. Do you recommend to run more iterations until it fails?

Hope to hear from you soon. Thank you.

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

Re: MoCoInverse : Objective Function not Converging

Post by Nicholas Bianco » Fri Jul 05, 2024 9:47 am

Hi Sivaprasad,

It's hard to say how many iterations a problem will require, but 600 is not an usually high number.

If you can unseal the solution, have you tried plotting all the results? Are any model actuator controls hitting their variable bounds? If so, have you tried adding strong reserve actuators to all joints? See ModOpAddReserves.

Best,
Nick

User avatar
Sivaprasad Kunnath
Posts: 11
Joined: Mon Jun 03, 2024 2:13 am

Re: MoCoInverse : Objective Function not Converging

Post by Sivaprasad Kunnath » Thu Aug 01, 2024 3:38 pm

Hey Nicholas,

I have been running multiple iterations with varying parameter's after analysing the results and these are my observations.

1. The objective function diverged to bigger values when I keep my reserve actuator limits from (-inf,inf). When i narrow it to 0 to 1. It lowers down to smaller values.

2. I had to relax the convergence tolerance to the order of 10e0, to get a solution that converges for static trials, when the reserve actuators are constrained to the aforementioned range. The results in activation when analysed give the expected results.

None of the bounds are being hit or violated during the trials. For trials which has movements, without external force some are near feasible, not converging. No output file is being produced for such results unfortunately hence can't plot the muscle action for analysis. Please advice on what the problem can be at this moment. Thank you for the support.

Regards,
Siva

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

Re: MoCoInverse : Objective Function not Converging

Post by Nicholas Bianco » Tue Aug 06, 2024 9:37 am

Hi Siva,

I realized that I had a typo in my last response. I meant to say that "600 is not an unusually high number".
1. The objective function diverged to bigger values when I keep my reserve actuator limits from (-inf,inf). When i narrow it to 0 to 1. It lowers down to smaller values.
If bounding reserve actuators, they should be between [-1, 1], not [0, 1], since they need to apply forces in both directions. This may explain why convergence is currently unreliable.

Best,
Nick

User avatar
Sivaprasad Kunnath
Posts: 11
Joined: Mon Jun 03, 2024 2:13 am

Re: MoCoInverse : Objective Function not Converging

Post by Sivaprasad Kunnath » Thu Aug 08, 2024 1:40 am

Hi Nicholas,

Thanks for your reply. I will be trying a couple of iterations with the modified settings. Also, I wanted to ask, whether it can be considered to use the mocoInverse to find the Joint forces by switching off all muscles and taking just the reserve actuators. If it's possible, how can I scale to find the exact joint forces and torques, as at present it's been normalised between -1 and 1.

Thanks and regards,
Siva

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

Re: MoCoInverse : Objective Function not Converging

Post by Nicholas Bianco » Thu Aug 08, 2024 9:50 am

Hi Siva,
Also, I wanted to ask, whether it can be considered to use the mocoInverse to find the Joint forces by switching off all muscles and taking just the reserve actuators. If it's possible, how can I scale to find the exact joint forces and torques, as at present it's been normalised between -1 and 1.
With this approach, you can simply multiply the reserve actuator control by the reserve actuator optimal force.

Best,
Nick

User avatar
Sivaprasad Kunnath
Posts: 11
Joined: Mon Jun 03, 2024 2:13 am

Re: MoCoInverse : Objective Function not Converging

Post by Sivaprasad Kunnath » Tue Aug 13, 2024 1:14 am

Hi Nicholas,

Thank you for your prompt reply. I performed a couple more iterations following your advice. I assigned the bounds to be [-1,1], but am unsure what values to assign for the reserve actuator optimal force. Right now, it's at it's default value of 1.

I will also attach here a brief introduction to what I am trying to achieve, eventhough we are deep into the discussion.

OBJECTIVE: Finding the joint forces, torques, muscle forces and activations involved in an upper-limb movement.

MOVEMENT:
-------------
Starting Position:
Elbow: Half-flexed (approximately 90).
Shoulder: Fully relaxed (Arm is by the side of the body)

Movement:
Elbow Extension: You extend your elbow from the half-flexed position to a fully extended position, (straightening the arm.)
Shoulder Elevation: Simultaneously, Raise your arm from its relaxed position (by the side of your body) to shoulder level (horizontal, parallel to the ground).

PARAMETERS ASSIGNED:

Using the MOBL-ARM model with fully defined arm muscles and 7DOF model, mass is assigned to be 54 KG for the whole model with 4.5 KG for the total mass of the arm.

- A constant force is applied as an external force to the proximal_row body in the model for a time-series. The corresponding kinematics is aforementioned. This force is an assistive force against gravity value to be around (150) as sown in the attached image.
Screenshot 2024-08-13 181353.png
Screenshot 2024-08-13 181353.png (18.12 KiB) Viewed 994 times
- 7 Reserve actuators to mimic 7 joint movements with bounds [-1,1] with optimal force of 1. ( Tried with values upto 1000, didn't converge).

Results and Observations:

- Iterations converged when the optim_converg_tolerances are assigned a value of 1, anything below didn't converge.

- When muscles are turned off, the problem doesn't converge at all.

This is our project in brief. Hope to hear from you soon. Thanks for the continuing support and help.

Regards,
Siva

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

Re: MoCoInverse : Objective Function not Converging

Post by Nicholas Bianco » Tue Aug 13, 2024 5:41 pm

Hi Siva,

I would recommend starting with larger reserve actuator strengths and then plotting the results of each simulation to try to better understand why the problem did not converge or achieve the expected motion. I would also try running the simulation with and without the constant applied force to see if that is the main thing preventing convergence.

Best,
Nick

POST REPLY