Search code examples
drake

How to hold decision variables fixed in Drake


I want to perform Lyapunov function coefficient optimization using alternations, which requires holding a subset of decision variables fixed while optimizing another subset. How do I hold certain decision variables fixed in Drake?


Solution

  • When you do bilinear alternation in Lyapunov analysis, the approach will alternate between the two steps:

    1. Fix the Lyapunov function to a constant value, and search for the Lagrangian multiplier.
    2. Fix the Lagrangian multiplier to a constant value, and search for the Lyapunov function (or the sub-level set).

    I would suggest you to create a helper function like this

    def lyapunov_derivative(lyap, dynamics, x, lagrangian, rho):
      # Return the polynomial -Vdot - lagrangian * (rho - V)
      dVdx = np.array([lyap.Differentiate(x[i]) for i in range(x.shape[0])])
      Vdot = dVdx @ dynamics
      return -Vdot - lagrangian * (rho - V)
    

    Let's say you have found the Lyapunov function, you will then need to evaluate this Lyapunov function, substituting all its decision variables with the values you found. You can do this through

    result = Solve(prog)
    lyap_sol = result.GetSolution(lyap)
    rho_sol = result.GetSolution(rho)
    

    where lyap is a polynomial whose decision variable values were just found by solving the mathematical program. Now lyap_sol doesn't contain any decision variables (it still contains indeterminates). Now you can call lyapunov_derivative(lyap_sol, dynamics, x, lagrangian, rho_sol) that will return you a polynomial with lagrangian as the unknown terms. You can then solve a mathematical program to find the value of the lagrangian multiplier coefficients, and then call lyapunov_derivative function with that lagrangian solution, find the Lyapunov function, and proceed to the next iteration.