Page 1 of 1

Range of design variables

Posted: Mon Nov 06, 2023 7:17 am
by rosshm
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

Re: Range of design variables

Posted: Mon Nov 06, 2023 11:13 am
by bogert
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

Re: Range of design variables

Posted: Mon Nov 06, 2023 2:15 pm
by nbianco
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

Re: Range of design variables

Posted: Tue Nov 07, 2023 3:41 pm
by rosshm
Thanks both! That is a nice new feature.