Skip to content

The quadprog package

3 messages · thomas.schwander at mvv.de, Berwin A Turlach, Moshe Olshansky

#
G'day Thomas,

On Mon, 3 Sep 2007 10:08:08 +0200
<thomas.schwander at mvv.de> wrote:

            
library(quadprog) ? :)
With the commands above, I get on my system:
Error in solve.QP(Dmat, dvec, Amat = t(Amat), bvec = bvec, meq = 2) : 
	constraints are inconsistent, no solution!

Which is a bit strange, since Dmat is the identity matrix, so there
should be little room for numerical problems.

OTOH, it is known that the Goldfarb-Idnani algorithm can have problem
in rare occasions if the problem is "ill-scaled"; see the work of
Powell. 

Changing the definition of Amat to
leads to a successful call to solve.QP.  And since mu=0, I really
wonder why you scaled up the vector mu_r by a factor of 7 when putting
it into Amat.... :)
Now, with the solution I obtained the rest of your commands show:
[,1]
[1,] 6.068172e-15
[1] 1
a<-loesung$solution[i]>=0
	print(a)
}
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] FALSE
[1] FALSE
[1] TRUE
 
But:
a<-loesung$solution[i]>=- .Machine$double.eps*1000
	print(a)
}

[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] TRUE
[1] 0
[1] 0
[1] 1
[1] 0
[1] -4.669169e-17
[1] -1.436586e-17
[1] 8.881784e-16

This is a consequence of finite precision arithmetic.  Just as you
should not compare to numeric numbers directly for equality but rather
that the absolute value of their difference is smaller than an
appropriate chosen threshold, you should not check whether a number is
bigger or equal to zero, but whether it is bigger or equal to an
appropriately chosen negative threshold.  More information are given in
FAQ 7.31.

HTH.

Cheers,

	Berwin

=========================== Full address =============================
Berwin A Turlach                            Tel.: +65 6515 4416 (secr)
Dept of Statistics and Applied Probability        +65 6515 6650 (self)
Faculty of Science                          FAX : +65 6872 3919       
National University of Singapore     
6 Science Drive 2, Blk S16, Level 7          e-mail: statba at nus.edu.sg
Singapore 117546                    http://www.stat.nus.edu.sg/~statba
#
Hi Thomas,

On my computer the solution is (0,0,1,0,0,0,0) (within
machine accuracy) and it satisfies the constraints.
--- thomas.schwander at mvv.de wrote:

            
Amat<-matrix(c(matrix(1,1,7),7*mu_r,diag(1,7,7)),9,7,byrow=T)
loesung<-solve.QP(Dmat,dvec,Amat=t(Amat),bvec=bvec,meq=2)