[R] lsqlin in R package pracma

Hans W Borchers
Wed, 26 Aug 2015 14:10:53 -0000

I am a strong advocate of the *nloptr* package; and "sequential
quadratic programming", i.e. slsqp(), should be a good choice for
least-squares problems. Note that you still have to provide a starting
point.

BUT: this point does not need to lie in the interior of the feasible region.
So you can start with a point that solves the problem on the boundary
(with lsqlin()) and then continue with slsqp().

For the example mentioned above, it looks like this:

    library(pracma)
    x0 <- lsqlin(C, d, A, b)  # starting point on the boundary

    library(nloptr)
    f <- function(x) sum((C %*% x - d)^2)  # objective
    hin <- function(x) -A %*% x + b        # constraint, w/  A x >= 0 !

    slsqp(x0, f, hin = hin)
    # $par
    # [1]  0.1298620 -0.5756944  0.4251035  0.2438448
    #
    # $value
    # [1] 0.01758538
    # ...

The solution is slightly better than the MATLAB one or the constrOptim one.
Of course, all these can be improved by changing some optional parameters.


On Wed, Aug 26, 2015 at 2:18 PM, Wang, Xue, Ph.D. <Wang.Xue at mayo.edu>
wrote:
> Hi Hans,
>
> Thanks for your comments!
>
> I need the linear inequality constraints so nlsLM is not a candidate.
>
> I am also looking at the functions mma and slsqp in R package nloptr.
Compared with constrOptim(), which approach would you recommend?
>
> Thanks,
>
> Xue