Skip to content
Advertisement

Solve a linear system of equations with bounds using LSQR/LSMR SciPy

Question is quite straight forward. I have an overdetermined system I am attempting to use SciPy LSQR (or LSMR) to solve. However, I cannot find anywhere in the docs on how to set restraints for the minimization.

E.G. Let’s say this is the output:

The matrix A has 469 rows and 3 columns
damp = 0.00000000000000e+00

atol = 1.00e-06                 conlim = 1.00e+08

btol = 1.00e-06             maxiter =        3

 
   itn      x(1)       norm r    norm Ar  compatible   LS      norm A   cond A
     0  0.00000e+00  1.150e-01  2.291e-02   1.0e+00  1.7e+00
     1  3.33741e-01  9.411e-03  5.359e-05   8.2e-02  2.8e-02  2.0e-01  5.0e+00
     2  2.73042e-01  8.440e-03  3.281e-06   7.3e-02  1.9e-03  2.0e-01  7.8e+01
     3 -1.70218e-01  8.332e-03  3.197e-12   7.2e-02  1.9e-09  2.0e-01  4.1e+02
 
LSMR finished
The least-squares solution is good enough, given atol     
istop =       2    normr = 8.3e-03
    normA = 2.0e-01    normAr = 3.2e-12
itn   =       3    condA = 4.1e+02
    normx = 8.7e-01
     3 -1.70218e-01   8.332e-03  3.197e-12
   7.2e-02  1.9e-09   2.0e-01  4.1e+02

We can see the solution arrive to -0.1, which is great. However, I’d like to set bounds such that x(1) >= 0. Therefore, the iteration would stop when x(1) = 0.27. I cannot find anywhere on the documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html regarding how to do this.

Any help would greatly be appreciated!

Advertisement

Answer

The functions lsqr and lsmr in scipy.sparse.linalg do not have options for adding constraints. You might be able to use scipy.optimize.lsq_linear instead.

Advertisement