Nonlinear Costs in Python Interface

Hello,

After reading that a non-linear cost formulation is added to the python interface, I wanted to try out that option. For that I have a few questions:

  1. Which non-linear cost formulations are allowed?

  2. How can they be implemented in python interface? Up to now, the only variables to be specified are the numerical matrix values for Vx, Vu and Vz and the numerical y_ref values

Thanks and Cheers!
Can

1 Like

Hey Can, did you have a look at this example? https://github.com/acados/acados/blob/master/examples/acados_python/pendulum_example/generate_c_code.py

1 Like

Hey Andrea,

I haven’t looked at that example prior to asking the question, since I assumed there would not be any documentation or examples for the python interface yet. After looking at the example, I think that I understand how the costs are implemented. However I have two points which need to be clear. I would appreciate if you can confirm or correct them:

  1. The Vx, Vu and Vz costs do not serve a purpose in Nonlinear Least Squares, since everything can now be expressed as W and the cost_r terms

  2. The Nonlinear Least Squares allows for costs expressed as sum of weighted squares of residual functions r(), which can only depend on state x and control u and time t, e.g. r(x,u,t). This formulations does not allow for negative or linear cost terms and trying to implement a linear cost c(x,u,t) by defining the residuals as square root of c() would cause numerical problems

Thanks and Cheers,

Can

Hey Can,

  1. Vx, Vu, Vz are indeed useless, I should fix this asap, sorry.
  2. I am not sure that I understand this. An NLS cost term by definition cannot be negative nor linear. Maybe you are trying to implement economic costs?

Hey Andrea,

As for the second question, I am just trying to understand the exact limitations of the Nonlinear Cost Functions. I am interested in Economic Costs or Arbitrary Cost formulations and I inquired about a “hack” that would make linear costs possible to implement with NLS limitations and what the downside of such a “hack” would be.

Thanks,

Can

Hey Can,

I have merged a fix regarding the usage of Vx, Vu and Vz. Regarding the “hack” that would not really work since (sqrt(x))^2 is not equal to x.

Hey Can,

just an addition:
If you want to penalize something in a linear way using the NLS module, the best way is probably to do this with a slack variable reformulation.