2016-09-09 28 views
1

我想理解爲什麼我會在嘗試使用solnp解決此問題時收到警告消息?以下是我得到的消息 -Rsolnp中的警告:解決方案不可靠,因爲無法反轉Hessian

solnp--> Solution not reliable....Problem Inverting Hessian. 
Warning message: 
In p0 * vscale[(neq + 2):(nc + np + 1)] : 
    longer object length is not a multiple of shorter object length 

以下是代碼

countw <- 100 
Dmat = diag(1, 100, 100) 
# Equality constraints 
eq_A <- rep(1, countw) 
eq_b <- 1 

# Constraint wts greater than zero 
ineq_A <- diag(x = 1, nrow = countw, ncol = countw) 
ineq_b <- rep(0, countw) 

# Combine constraints 
heq <- eq_A 
hin <- ineq_A 

theta <- c(0.51, 0.49, rep(0, countw-2)) 

krdsolnp <- solnp(par = theta, 
        fun = function(x) -c(t(x) %*% Dmat %*% x), 
        ineqfun = function(x) c(hin %*% x), 
        ineqLB = rep(0, countw), 
        ineqUB = rep(1, countw), 
        eqfun = function(x) c(heq %*% x), 
        eqB = eq_b) 

回答

0

此代碼等於問:我如何能最大限度地總和(X^2),同時保持的係數x 0和1之間,並保持sum(x)等於1?

的庫嘗試此使用目標函數的Hessian矩陣,即總和(X^2)的偏導數的矩陣相對於任何對X係數來解決。 Hessian通常是單位矩陣的2倍,這是可逆的。

但是,有關約束的內容會引發這種情況。您可以通過將0在初始條件theta中更改爲0.01來避免該錯誤。

相關問題