You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to make use of OSQP for a fairly straight forward least squares problem in python. This is the example given in the docs
import osqp
import numpy as np
import scipy as sp
from scipy import sparse
# Generate problem data
# sp.random.seed(1)
m = 30
n = 20
Ad = sparse.random(m, n, density=0.7, format='csc')
b = np.random.randn(m)
# OSQP data
P = sparse.block_diag([sparse.csc_matrix((n, n)), sparse.eye(m)], format='csc')
q = np.zeros(n+m)
A = sparse.bmat([[Ad, -sparse.eye(m)],
[sparse.eye(n), None]], format='csc')
l = np.hstack([b, np.zeros(n)])
u = np.hstack([b, np.ones(n)])
# Create an OSQP object
prob = osqp.OSQP()
# Setup workspace
prob.setup(P, q, A, l, u)
# Solve problem
res = prob.solve()
note that I had to comment out sp.random.seed(1) because scipy has no module named random. There are no additional comments or discussions for this examples, just a note at the top that we are minimizing ||Ax - b|| subject to 0 < x < 1. Needless to say, I am confused and have many questions... but generally, just a discussion about what is going on here would be an excellent addition to the documentation.
I think my biggest hang up is translating from the general problem described on the home page of the docs https://osqp.org/docs/solver/index.html to the least squares examples listed here https://osqp.org/docs/examples/least-squares.html. My biggest confusion is around how to handle A and b. It looks like b just becomes part of x and the limits are used to "set" what "b" should be, but it isn't super clear to me. So, for example, if you are controlling a dynamic system, the "b" term takes the from of the force / torque residuals in the least squares phrasing of the problem. You expand X to include these terms and the limits on that part of X becomes L = U = command residual. Am I at least thinking about this the right way?
Can anyone here walk me through what this example above is doing exactly? The transition between the two formulations is especially confusing for me.
thanks!
Gus
The text was updated successfully, but these errors were encountered:
Hello all!
I am trying to make use of OSQP for a fairly straight forward least squares problem in python. This is the example given in the docs
note that I had to comment out
sp.random.seed(1)
because scipy has no module named random. There are no additional comments or discussions for this examples, just a note at the top that we are minimizing ||Ax - b|| subject to 0 < x < 1. Needless to say, I am confused and have many questions... but generally, just a discussion about what is going on here would be an excellent addition to the documentation.I think my biggest hang up is translating from the general problem described on the home page of the docs https://osqp.org/docs/solver/index.html to the least squares examples listed here https://osqp.org/docs/examples/least-squares.html. My biggest confusion is around how to handle A and b. It looks like b just becomes part of x and the limits are used to "set" what "b" should be, but it isn't super clear to me. So, for example, if you are controlling a dynamic system, the "b" term takes the from of the force / torque residuals in the least squares phrasing of the problem. You expand X to include these terms and the limits on that part of X becomes L = U = command residual. Am I at least thinking about this the right way?
Can anyone here walk me through what this example above is doing exactly? The transition between the two formulations is especially confusing for me.
thanks!
Gus
The text was updated successfully, but these errors were encountered: