【问题标题】:Warning in Rsolnp : Solution not reliable because unable to Invert HessianRsolnp 中的警告:解决方案不可靠,因为无法反转 Hessian
【发布时间】:2016-09-09 12:42:38
【问题描述】:

我试图了解为什么在尝试使用 solnp 解决此问题时会收到警告消息?以下是我收到的消息 -

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)

【问题讨论】:

    标签: r mathematical-optimization hessian-matrix


    【解决方案1】:

    这段代码相当于在问:我怎样才能最大化 sum(x^2),同时保持 x 的系数在 0 和 1 之间,并保持 sum(x) 等于 1?

    库尝试使用目标函数的 Hessian 矩阵来解决这个问题,即 sum(x^2) 的偏导数矩阵相对于 x。 Hessian 通常是单位矩阵的 2 倍,这是可逆的。

    然而,一些关于约束的东西把它扔掉了。您可以通过将初始条件 theta 中的 0 更改为 0.01 来避免该错误。

    【讨论】:

      猜你喜欢
      • 2020-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      • 2022-10-26
      • 1970-01-01
      相关资源
      最近更新 更多