Closed jchiquet closed 5 years ago
More about this : in the lsei
function, a call to the second type induces a ridge-like regularization, which may explain why this solution was found more stable by @mpierrejean in commit ce6c2f72e78099329cb421d6ee7d1d74e17031ed
else if (type == 2) {
if (!is.null(Wx))
stop("cannot solve least squares problem - weights not implemented for type 2")
if (!is.null(Wa))
stop("cannot solve least squares problem - weights not implemented for type 2")
dvec <- crossprod(A, B)
Dmat <- crossprod(A, A)
diag(Dmat) <- diag(Dmat) + 1e-08
Amat <- t(rbind(E, G))
bvec <- c(F, H)
sol <- solve.QP(Dmat, dvec, Amat, bvec, meq = Neq)
sol$IsError <- FALSE
sol$X <- sol$solution
}
However, it does not solve the expected problem !
This problem is related to the rank deficiency problem: we suggest to add an argument to get.W for the type of solver use, using type = 1L as a default since it corresponds to the expected optimization problem.
Later, we might tweak the following to call quadprog by ourselves and then control the amount of ridge regularization (here arbitrarily set to 1e-8):
else if (type == 2) {
if (!is.null(Wx))
stop("cannot solve least squares problem - weights not implemented for type 2")
if (!is.null(Wa))
stop("cannot solve least squares problem - weights not implemented for type 2")
dvec <- crossprod(A, B)
Dmat <- crossprod(A, A)
diag(Dmat) <- diag(Dmat) + 1e-08
Amat <- t(rbind(E, G))
bvec <- c(F, H)
sol <- solve.QP(Dmat, dvec, Amat, bvec, meq = Neq)
sol$IsError <- FALSE
sol$X <- sol$solution
}
UPDATE 2019-03-02: Moved to Issue #72.
Don't forget to update NEWS - this glooks like a 'SIGNIFICANT CHANGES:' entry since we're changing the default from type=2L
to type=1L
.
I've moved the outstanding future task to new Issue #72.
I don't know why the QP solver was chosen at some point, but it seems significantly slower:
Then it gives
So I suggest changing type = 2L to 1L in get.W