opensim-org / opensim-moco

Solve optimal control problems for musculoskeletal models using OpenSim and direct collocation.
https://opensim.stanford.edu/moco
Apache License 2.0
58 stars 16 forks source link

[WIP]: Huber loss function #649

Closed antoinefalisse closed 4 years ago

antoinefalisse commented 4 years ago

@chrisdembia and @nickbianco, this is a first try for the Huber loss function. It is not yet complete but I would be interested to have feedback on a few things:

  1. Would you keep both smoothing options available, ie tanh vs Huber loss?

  2. I thought I solved it but I am actually still struggling with one case. For the shortening heat rate, when use_force_dependent_shortening_prop_constant is true, the shortening heat rate is not 0 when the fiber velocity is > 0 (see curves Figure 1 (left) below). This makes a little trickier the use of the Huber loss function as I implemented it. What I did is that I rotated the curve, used the Huber loss function, and the rotated back. As you can see in the figure, this looks good (although very steep). However, I did not think that, in practice, we do not have access to the value before rotation, since that value depends on a if-statement that we want to avoid...So basically, for now, my ugly code implementing this rotation thing depends on a value I get out of this if-statement, which is certainly not what we want. I think it should be feasible to avoid this rotation and to directly apply the Huber loss function (this might also allow having a smoother transition I think). Any ideas?

  3. I have tried to keep the same structure (i.e., m_conditional) when implementing the Huber loss function. Not sure this is what we want.

  4. All the tests pass but the problem did not converge (point 2 above did not matter, since use_force_dependent_shortening_prop_constant wastrue). I got restoration failed after about 1h. Maybe it is to steep, not sure...

I attach the MATLAB code I used if you want to give it a shot. If you run it, you should get the figures for the different cases where smoothing is applied.

Those are my thought for now. Thanks in advance. I hope we can get that bhargava_smooth PR done soon, it is getting long :)

ShorteningRate

testMetabolicEnergyModel_HuberLoss4.zip

Brief summary of changes

Give option to use a Huber loss function rather than a tanh function.

Details (optional)

CHANGELOG.md (choose one)


This change is Reviewable

antoinefalisse commented 4 years ago

@nickbianco, thanks for the quick response. Quick reply to 4, no it did not converge... For 2, it might indeed make sense to use a tanh in any case, since it goes negative when vM > 0. Using both smoothing options will require some changes but I will give it a shot.