【问题标题】:Fast nonnegative quantile and Huber regression in RR中的快速非负分位数和Huber回归
【发布时间】:2018-06-02 23:02:56
【问题描述】:

我正在寻找一种在 R 中进行非负分位数和 Huber 回归的快速方法(即所有系数都 > 0 的约束)。我尝试使用 CVXR 包进行分位数和 Huber 回归,使用 quantreg 包进行分位数回归,但 CVXR 非常慢,当我使用非负约束时,quantreg 似乎有问题。有谁知道 R 中有一个好的快速的解决方案,例如使用Rcplex 包或R gurobi API,从而使用更快的CPLEX 或gurobi 优化器?

请注意,我需要运行低于 80 000 次的问题大小,因此我只需要在每次迭代中更新 y 向量,但仍使用相同的预测矩阵 X。从这个意义上说,我觉得在CVXR 中我现在必须在每次迭代中执行obj <- sum(quant_loss(y - X %*% beta, tau=0.01)); prob <- Problem(Minimize(obj), constraints = list(beta >= 0)) 效率低下,而问题实际上保持不变,而我只想更新y。有什么想法可以更好/更快地完成这一切吗?

小例子:

## Generate problem data
n <- 7 # n predictor vars
m <- 518 # n cases 
set.seed(1289)
beta_true <- 5 * matrix(stats::rnorm(n), nrow = n)+20
X <- matrix(stats::rnorm(m * n), nrow = m, ncol = n)
y_true <- X %*% beta_true
eps <- matrix(stats::rnorm(m), nrow = m)
y <- y_true + eps

使用 CVXR 的非负分位数回归:

## Solve nonnegative quantile regression problem using CVX
require(CVXR)
beta <- Variable(n)
quant_loss <- function(u, tau) { 0.5*abs(u) + (tau - 0.5)*u }
obj <- sum(quant_loss(y - X %*% beta, tau=0.01))
prob <- Problem(Minimize(obj), constraints = list(beta >= 0))
system.time(beta_cvx <- pmax(solve(prob, solver="SCS")$getValue(beta), 0)) # estimated coefficients, note that they ocasionally can go - though and I had to clip at 0
# 0.47s
cor(beta_true,beta_cvx) # correlation=0.99985, OK but very slow

非负 Huber 回归的语法相同,但会使用

M <- 1      ## Huber threshold
obj <- sum(CVXR::huber(y - X %*% beta, M))

使用quantreg 包的非负分位数回归:

### Solve nonnegative quantile regression problem using quantreg package with method="fnc"
require(quantreg)
R <- rbind(diag(n),-diag(n))
r <- c(rep(0,n),-rep(1E10,n)) # specify bounds of coefficients, I want them to be nonnegative, and 1E10 should ideally be Inf
system.time(beta_rq <- coef(rq(y~0+X, R=R, r=r, tau=0.5, method="fnc"))) # estimated coefficients
# 0.12s
cor(beta_true,beta_rq) # correlation=-0.477, no good, and even worse with tau=0.01...

【问题讨论】:

    标签: r cplex cvx quantile-regression cvxr


    【解决方案1】:

    为了加速CVXR,你可以在开始的时候获取一次问题数据,然后在一个循环内修改它并直接传递给求解器的R接口。这个代码是

    prob_data <- get_problem_data(prob, solver = "SCS")
    

    然后,解析出参数并将它们从 scs 库传递给 scs。 (参见solver.R 中的Solver.solve)。您必须深入研究规范化的细节,但我希望如果您只是在每次迭代时更改 y,这应该是一个简单的修改。

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 1970-01-01
      • 2023-03-25
      • 2015-03-17
      • 2013-10-08
      • 1970-01-01
      • 2021-07-11
      • 2013-01-31
      • 2013-11-20
      相关资源
      最近更新 更多