You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it would be possible by any chance to support extra arguments lower.limits and upper.limits with vectors of lower & upper box constraints on the coefficients. I would like to fit a nonnegative Poisson GLM, but in the absence of nonnegativity constraints this always blows up. In my experience, just imposing these constraints in each IRLS iteration by clipping coefficients to the allowed range works quite well. Otherwise, the osqp quadratic programming solver is also quite efficient and would allow formal box constraints & works both for dense or sparse covariate matrices :
constrainedLS_osqp <- function(y, X,
lower=rep(0, ncol(X)), upper=rep(Inf, ncol(X)),
x.start = NULL, y.start = NULL) {
require(osqp)
require(Matrix)
XtX = crossprod(X,X)
Xty = crossprod(X,y)
settings = osqpSettings(verbose = FALSE, eps_abs = 1e-8, eps_rel = 1e-8, linsys_solver = 0L,
warm_start = FALSE)
pff = .sparseDiagonal(ncol(X))
model <- osqp(XtX, -Xty, pff, l=lower, u=upper, pars=settings)
if (!is.null(x.start)) model$WarmStart(x=x.start, y=y.start)
coefs = model$Solve()$x # fitted coefficients
coefs = pmax(lower, pmin(coefs, upper) ) # fitted coefficients sometimes go very slightly outside constraint zone due to numerical inaccuracies in solver - this is fixed here via clipping
return(coefs)
}
The text was updated successfully, but these errors were encountered:
I was wondering if it would be possible by any chance to support extra arguments
lower.limits
andupper.limits
with vectors of lower & upper box constraints on the coefficients. I would like to fit a nonnegative Poisson GLM, but in the absence of nonnegativity constraints this always blows up. In my experience, just imposing these constraints in each IRLS iteration by clipping coefficients to the allowed range works quite well. Otherwise, theosqp
quadratic programming solver is also quite efficient and would allow formal box constraints & works both for dense or sparse covariate matrices :The text was updated successfully, but these errors were encountered: