我已经准备好所有向量和矩阵,并且可以纠正并且仍然求解.QP抛出错误。有人可以帮忙吗?
错误是:
solve.QP(Dmat,dvec,Amat,bvec)中的错误:
约束不一致,没有解决办法!
Dmat=matrix(c(0.002010, 0.002656, -0.001158, -0.001350, 0.000242, 0.000256, -0.000890, -0.000874, 0.002656, 0.014554, -0.002614, -0.001220, -0.004474, -0.001978, 0.002884, -0.003070,-0.001158, -0.002614, 0.119704, 0.055176, 0.126994, 0.046072, 0.065934, 0.096078, -0.001350, -0.001220, 0.055176, 0.059218, 0.053144, 0.042930, 0.041394, 0.059708, 0.000242, -0.004474, 0.126994, 0.053144, 0.204976, 0.085488, 0.079886, 0.131988, 0.000256, -0.001978, 0.046072, 0.042930, 0.085488, 0.064112, 0.039762, 0.064470, -0.000890, 0.002884, 0.065934, 0.041394, 0.079886, 0.039762, 0.056710, 0.070128, -0.000874, -0.003070, 0.096078, 0.059708, 0.131988, 0.064470, 0.070128, 0.159916), nrow=8,ncol=8,byrow=TRUE)
dvec <- rep(0,8)
m = c(.08,.67,6.41,4.08,7.43,3.7,4.8,6.6)/100
tau = .25
omega = diag(x = c(.000801,.009546,.000884))
q = c(.041,.016,.008)
P = rbind(c(0,0,0,0,0,1,0,0),c(0,0,0,0,0,0,-1,1),c(0,0,-1,0,1,0,0,0))
covar = Dmat/2
mhat_1=solve(solve(tau * covar)+(((t(P) %*% solve(omega)) %*% P)))
mhat_2=(solve(tau * covar) %*% m) + ((t(P) %*% solve(omega)) %*% q)
mhat = mhat_1 %*% mhat_2
Amat <- matrix(c(mhat,-mhat,rep(1,8),rep(-1,8),diag(length(mhat))),8,12)
bvec=matrix(c(0.07640375, -0.07640375, 1.00000000, -1.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.00000000),nrow=1,ncol=12,byrow=TRUE)
sol = solve.QP(Dmat,dvec,Amat,bvec)
答案 0 :(得分:1)
似乎没有内部解决方案,问题出在0.07640375
中使用mhat[5]
(对应于bvec
)。为了允许转角解决方案,只需使用更高的精度并设置
bvec <- matrix(c(0.0764037467, -0.0764037467, 1, -1, rep(0, 8)), nrow = 1)
相反。然后
solve.QP(Dmat,dvec,Amat,bvec)$sol
# [1] 1.800544e-16 1.577392e-16 5.082845e-09 1.771718e-16 1.000000e+00 1.649150e-16
# [7] -3.161050e-20 0.000000e+00