R - solve.QP.compact - 约束不一致

R - solve.QP.compact - Constraints are Inconsistent

我正在尝试使用 solve.QP.compact 来解决线性约束下的二次问题。最小化函数可以写成 Beta Dmat Beta,其中 Beta 表示应该为正的凸系数(Beta > 0 且 beta 之和 = 1)。 Dmat 如下:

Dmat <- matrix(c(109372234737,56220334574,73429834051,91873541870,71984996802,26694299175,59466668488,72903058589,34863587167,69990189651,56220334574,30472842846,41528929013,47926044961,39275554021,15336150547,31555630939,46390008065,18268007279,37264936709,73429834051,41528929013,66139008296,63287127518,56359545680,23281467618,42187566934,81859897202,23713602850,48982965873,91873541870,47926044961,63287127518,79910583327,62808190600,22813816846,50498032289,61764252981,29834680574,60303335045,71984996802,39275554021,56359545680,62808190600,61526678668,20293546244,40774759080,65131530787,23760877095,48696449409,26694299175,15336150547,23281467618,22813816846,20293546244,10710118459,16315334904,40553546897,8572539401,18248955543,59466668488,31555630939,42187566934,50498032289,40774759080,16315334904,34293058435,49072014208,19333916546,38891422022,72903058589,46390008065,81859897202,61764252981,65131530787,40553546897,49072014208,201860304636,23395941080,50359726205,34863587167,18268007279,23713602850,29834680574,23760877095,8572539401,19333916546,23395941080,11528523792,23285654687,69990189651,37264936709,48982965873,60303335045,48696449409,18248955543,38891422022,50359726205,23285654687,48461629142), nrow=10, ncol=10)

作为solve.QP.compact,求解函数-d^Tb + 1/2 b^TDb,我有

dvec <- rep(0,nrow(Dmat))`

并且约束由

定义
Amat = matrix(data=0, nrow=nrow(Dmat), ncol=nrow(Dmat)+1)
Amat[1,] = 1
Amat[,1] = 1

Aind = matrix(data=0, nrow=nrow(Dmat)+1, ncol=nrow(Dmat)+1)
Aind[1,] = 1
Aind[1,1] = nrow(Dmat)
Aind[2,] = c(1, seq(1:nrow(Dmat)))
Aind[,1] = c(nrow(Dmat), seq(1:nrow(Dmat)))

总和应等于 1,所有其他值应为正,因此我将 bvec 定义为

bvec = rep(0,nrow(Dmat)+1)
bvec[1] = 1

我用solve.QP.compact

solve.QP.compact(Dmat = Dmat, dvec = dvec, Amat = Amat, Aind=Aind, bvec = bvec)

这是由以下错误导致的

constraints are inconsistent, no solution!

我做错了什么?

Dmat中的大数字有问题。

可能是解决方案向量 b 的元素与 0 无法区分(参见 .Machine$double.eps)仍然解决 b^T D b 太大并且内部有东西 quadprog 使约束不一致。

看起来应该有所帮助:

   Dmat <- Dmat / 10^6