Range of design variables

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
POST REPLY
User avatar
Ross Miller
Posts: 373
Joined: Tue Sep 22, 2009 2:02 pm

Range of design variables

Post by Ross Miller » Mon Nov 06, 2023 7:17 am

Hi all,

In most simulations that most of us do in Moco, the variables that are optimized (i.e. the "design variables) all vary over a range of approximately [-1, +1], for example muscle excitations, muscle activations, CC lengths, normalized SEC forces, joint angles in radians, etc.

In a current simulation, I have one variable, stiffness of a spring, whose range is much larger in magnitude, about [10,000, 30,000].

Is this bad for convergence? Is it better to have it such that all variables in the solution space are optimized/searched for over approximately the same range?

Ross
Last edited by Ross Miller on Mon Nov 06, 2023 11:39 am, edited 1 time in total.

User avatar
Ton van den Bogert
Posts: 165
Joined: Thu Apr 27, 2006 11:37 am

Re: Range of design variables

Post by Ton van den Bogert » Mon Nov 06, 2023 11:13 am

Ross,

In my experience, it can make a large difference. I once spent two weeks trying to find an error in my code, when an optimization problem would not solve. Turned out my code was correct after all, I just needed to change my force units to kN and it solved immediately.

I don't know if this is generally the case, but to be safe, it is a good idea to scale the problem well. Gradient-based optimization methods are all based on Newton's method, and are developed and tested by mathematicians who never think about units.

Ton van den Bogert

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

Re: Range of design variables

Post by Nicholas Bianco » Mon Nov 06, 2023 2:15 pm

Hi Ross,

I find this blog post from the CasADi developers on the topic of NLP scaling helpful: https://web.casadi.org/blog/nlp-scaling/.

Last year we added to Moco support for automatic variable scaling when using CasADi solver via the 'scaling_variables_using_bounds' property:

Code: Select all

solver = study.initCasADiSolver();
solver.set_scale_variables_using_bounds(true);
Give it a try and see if it helps with convergence in your problem.

Best,
Nick

User avatar
Ross Miller
Posts: 373
Joined: Tue Sep 22, 2009 2:02 pm

Re: Range of design variables

Post by Ross Miller » Tue Nov 07, 2023 3:41 pm

Thanks both! That is a nice new feature.

POST REPLY