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

时间:2017-01-12 10:55:19

标签: r quadprog

我试图使用solve.QP.compact来解决线性约束下的二次问题。最小化的函数可以写成Beta Dmat Beta,其中Beta表示应该是正的凸系数(Beta> 0且β的总和= 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)

as 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!

我做错了什么?

1 个答案:

答案 0 :(得分:3)

Dmat中的巨大数字出现了问题。

解决方案向量b的元素可能与0无法区分(请参阅.Machine$double.eps),但b^T D b中的元素仍然过大且内部有{{1}使约束不一致。

看起来这应该会有所帮助:

quadprog