Skip to content

Commit

Permalink
Handle the fact that QuantileRegressionSolver still uses ECOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnapolitano committed Sep 12, 2024
1 parent 30dc66a commit 5e86db4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import find_packages, setup

INSTALL_REQUIRES = ["cvxpy~=1.5", "numpy~=2.1", "scipy~=1.14"]
INSTALL_REQUIRES = ["cvxpy~=1.5", "ecos~=2.0", "numpy~=2.1", "scipy~=1.14"]

THIS_FILE_DIR = os.path.dirname(__file__)

Expand Down
27 changes: 17 additions & 10 deletions src/elexsolver/QuantileRegressionSolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings

import cvxpy as cp
import numpy as np
Expand Down Expand Up @@ -61,17 +62,23 @@ def _fit_with_regularization(
"""
Fits quantile regression with regularization
TODO: convert this problem to use the dual like in the non regularization case
TODO: experiment with switching to CLARABEL instead of ECOS
"""
arguments = {"ECOS": {"max_iters": 10000}}
coefficients = cp.Variable((x.shape[1],))
y_hat = x @ coefficients
residual = y - y_hat
loss_function = cp.sum(cp.multiply(weights, 0.5 * cp.abs(residual) + (tau - 0.5) * residual))
loss_function += lambda_ * self._get_regularizer(coefficients, regularize_intercept, n_feat_ignore_reg)
objective = cp.Minimize(loss_function)
problem = cp.Problem(objective)
problem.solve(solver="ECOS", **arguments.get("ECOS", {}))
return coefficients.value

with warnings.catch_warnings():
# silence the warning we receive from cvxpy about having not yet switched away from ECOS
warnings.simplefilter("ignore", FutureWarning)

arguments = {cp.ECOS: {"max_iters": 10000}}
coefficients = cp.Variable((x.shape[1],))
y_hat = x @ coefficients
residual = y - y_hat
loss_function = cp.sum(cp.multiply(weights, 0.5 * cp.abs(residual) + (tau - 0.5) * residual))
loss_function += lambda_ * self._get_regularizer(coefficients, regularize_intercept, n_feat_ignore_reg)
objective = cp.Minimize(loss_function)
problem = cp.Problem(objective)
problem.solve(solver=cp.ECOS, **arguments.get(cp.ECOS, {}))
return coefficients.value

def fit(
self,
Expand Down

0 comments on commit 5e86db4

Please sign in to comment.