Skip to content

Commit 7e9c00a

Browse files
committed
updates
1 parent d51cd79 commit 7e9c00a

1 file changed

Lines changed: 62 additions & 47 deletions

File tree

Readme.md

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ We currently support the following loss functions
1212
- Quantile regression
1313
- Multiple response versions of the linear, huber and poisson losses
1414

15-
and the following penalties
15+
the following basic penalties
1616

1717
- Lasso
1818
- [Group Lasso](https://rss.onlinelibrary.wiley.com/doi/pdfdirect/10.1111/j.1467-9868.2005.00532.x?casa_token=wN_F5iYwNK4AAAAA:4PVnAz4icP5hR9FIRviV0zqnp_QAibv55uYkptKQKezvDoqtMzrSpFyHh15lL4IO1yFJ3Sfl4OwOuA) with user specified groups
1919
- [Multi-task Lasso](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.MultiTaskLasso.html#sklearn.linear_model.MultiTaskLasso) (i.e. L1 to L2 norm)
2020
- Nuclear norm
2121
- Ridge
22+
- Weighed versions of the above
2223
- [Tikhonov regularization](https://en.wikipedia.org/wiki/Tikhonov_regularization#Tikhonov_regularization)
23-
- [Elastic net](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ElasticNet.html) versions of the above Lasso penalties
24-
- Weighted versions of all of the above
25-
- Concave penalties such as [SCAD](https://fan.princeton.edu/papers/01/penlike.pdf)
2624

27-
The concave penalties are fit by applying the *local linear approximation* (LLA) algorithm to a "good enough" initializer such as the Lasso fit. See [(Fan et al, 2014)](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4295817/) for details. We provide concave versions of the group Lasso, multi-task Lasso and nuclear norm that are not discussed in the original paper.
25+
and the following more sophisticated penalties
26+
27+
- [Elastic net](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ElasticNet.html) versions of the above
28+
- Adaptive Lasso versions of the above (including multi-task, group and nuclear norm)
29+
- Folded concave penalties (FCP) such as [SCAD](https://fan.princeton.edu/papers/01/penlike.pdf) fit by applying the *local linear approximation* (LLA) algorithm to a "good enough" initializer such as the Lasso fit ([Zou and Li, 2008](http://www.personal.psu.edu/ril4/research/AOS0316.pdf); [Fan et al, 2014](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4295817/)). We also provide concave versions of the group Lasso, multi-task Lasso and nuclear norm that are not discussed in the original paper.
30+
2831

2932
The built in cross-validation functionality supports
3033

@@ -33,9 +36,9 @@ The built in cross-validation functionality supports
3336
- custom evaluation metrics
3437
- custom selection rules such as the '1se' rule from the glmnet package
3538

36-
We provide a built in FISTA algorithm [(Beck and Teboulle, 2009)](https://epubs.siam.org/doi/pdf/10.1137/080716542?casa_token=cjyK5OxcbSoAAAAA:lQOp0YAVKIOv2-vgGUd_YrnZC9VhbgWvZgj4UPbgfw8I7NV44K82vbIu0oz2-xAACBz9k0Lclw) that covers most glm loss + non-smooth penalty combinations (the ya_glm.opt module is inspired by [pyunlocbox](https://github.com/epfl-lts2/pyunlocbox), [copt](https://github.com/openopt/copt), and [lightning](https://github.com/scikit-learn-contrib/lightning)). **It is straightforward for you to plug in your favorite penalized GLM optimization algorithm.**
39+
We provide a built in FISTA algorithm [(Beck and Teboulle, 2009)](https://epubs.siam.org/doi/pdf/10.1137/080716542?casa_token=cjyK5OxcbSoAAAAA:lQOp0YAVKIOv2-vgGUd_YrnZC9VhbgWvZgj4UPbgfw8I7NV44K82vbIu0oz2-xAACBz9k0Lclw) that covers most glm loss + non-smooth penalty combinations (`ya_glm.opt` is inspired by [pyunlocbox](https://github.com/epfl-lts2/pyunlocbox) and [lightning](https://github.com/scikit-learn-contrib/lightning)). **It is straightforward for you to plug in your favorite penalized GLM optimization algorithm.**
3740

38-
We aim to add additional loss functions (e.g. quantile, gamma, cox regression) and penalties (e.g. generalized Lasso, TV1)
41+
We aim to add additional loss functions (e.g. gamma, cox regression) and penalties (e.g. generalized Lasso, TV1)
3942

4043

4144
**Beware**: this is a preliminary release of the package; the documentation and testing may leave you wanting and the code may be subject to breaking changes in the near future.
@@ -56,61 +59,71 @@ To use the backend from [andersoncd](https://github.com/mathurinm/andersoncd) yo
5659

5760

5861
```python
59-
from ya_glm.backends.fista.LinearRegression import Lasso, LassoCV, RidgeCV, LassoENetCV, \
60-
GroupLassoENet, GroupLassoENetCV, \
61-
FcpLLA, FcpLLACV
62+
from ya_glm.estimator_getter import get_pen_glm
63+
from ya_glm.toy_data import sample_sparse_multinomial, sample_sparse_lin_reg
6264

63-
from ya_glm.toy_data import sample_sparse_lin_reg
65+
# multinomial regression model with a row sparse coefficient matrix
66+
X, y = sample_sparse_multinomial(n_samples=100, n_features=10, n_classes=3)[0:2]
6467

65-
# sample some linear regression data
66-
X, y = sample_sparse_lin_reg(n_samples=100, n_features=20)[0:2]
68+
# programatically generate any loss + penalty combination
69+
Est, EstCV = get_pen_glm(loss_func='multinomial',
70+
penalty='lasso' # 'enet', 'adpt_lasso', 'adpt_enet', 'fcp_lla'
71+
)
6772

68-
# fit the Lasso penalized linear regression model we all known and love
69-
est = Lasso(pen_val=1).fit(X, y)
7073

71-
# tune the Lasso penalty using cross-validation
72-
# just as in sklearn.linear_model.LassoCV we use a
73-
# path algorithm to make this fast and set the tuning
74-
# parameter sequence with a sensible default
75-
est_cv = LassoCV(cv_select_rule='1se').fit(X, y)
74+
# fit using the sklean API you know and love
75+
Est(multi_task=True).fit(X, y)
76+
# Est().fit(X, y) # entrywise Lasso
77+
# Est(nuc=True).fit(X, y) # nuclear norm
7678

77-
# or you could have picked a different penalty!
78-
# est_cv = RidgeCV().fit(X, y)
79-
# est_cv = LassoENetCV().fit(X, y)
79+
# tune the lasso penalty with cross-validation
80+
# we automatically compute the tuning sequence
81+
# for any loss + penalty combination (the concave ones included!)
82+
EstCV(cv_select_rule='1se', # here we select the penalty parameter with the 1se rule
83+
cv_n_jobs=-1 # parallelization over CV folds with joblib
84+
).fit(X, y)
8085

81-
# we support user specified groups!
82-
groups = [range(10), range(10, 20)]
83-
est = GroupLassoENet(groups=groups)
84-
# and a cross-validation object that supports path solutions
85-
est_cv = GroupLassoENetCV(estimator=est).fit(X, y)
8686

87+
# Lets try a concave penalty such as the adaptive Lasso
88+
# or a concave penalty fit with the LLA algorithm
89+
Est_concave, EstCV_concave = get_pen_glm(loss_func='multinomial',
90+
penalty='fcp_lla' # 'adpt_lasso'
91+
)
8792

88-
# folded concave penalty with SCAD penalty
89-
# and initialized from the LassoCV solution
90-
# see (Fan et al. 2014) for details
91-
est = FcpLLA(init=LassoCV(), pen_func='scad')
93+
# concave penalties require an initilizer which is set via the init argument
94+
# by default we initialize with a LassoCV
95+
est = Est_concave(init='default', multi_task=True).fit(X, y)
9296

93-
# we can also tune this with cross-validation
94-
est_cv = FcpLLACV(estimator=est).fit(X, y)
95-
```
97+
# but you can provide any init estimator you want
98+
init = EstCV(estimator=Est(multi_task=True), cv=10)
99+
est = Est_concave(init=init)
100+
est_cv = EstCV_concave(estimator=est)
96101

97-
We can programmatically generate estimators for any loss + penalty combination (this avoids writing a ton of code by hand).
98102

99-
```python
100-
from ya_glm.estimator_getter import get_pen_glm, get_fcp_glm
101-
from ya_glm.toy_data import sample_sparse_log_reg
103+
# Here we an Elastic Net version of the Adaptive Lasso
104+
# with user specified groups for a liner regression example
105+
Est, EstCV = get_pen_glm(loss_func='lin_reg', penalty='adpt_enet')
106+
X, y = sample_sparse_lin_reg(n_samples=100, n_features=10, n_nonzero=5)[0:2]
107+
108+
groups = [range(5), range(5, 10)]
109+
est = Est(groups=groups)
110+
EstCV(estimator=est).fit(X, y)
102111

103-
# sample some logistic regression data
104-
X, y = sample_sparse_log_reg(n_samples=100, n_features=20)[0:2]
105112

106-
# Get a penalized logistic regression estimator and corresponding cross-validation object
107-
Est, EstCV = get_pen_glm(loss_func='log_reg', penalty='lasso')
113+
# we provide a penalized qunatile regression solve based on
114+
# Linear Programming for Lasso penalties or Quadratic Programming for Ridge type penalties
115+
from ya_glm.backends.quantile_lp.glm_solver import solve_glm
108116

109-
# Or a concave penalized logistic regression estimator
110-
# Est, EstCV = get_fcp_glm(loss_func='log_reg', penalty='lasso')
117+
# Quantile regression with your favorite optimzation algorithm
118+
# you can easily provide your own optimization algorithm to be the backend solver
119+
Est, EstCV = get_pen_glm(loss_func='quantile',
120+
penalty='adpt_lasso',
121+
backend = {'solve_glm': solve_glm # solves a single penalize GLM problem
122+
# 'solve_glm_path': None # path algorithm
123+
}
124+
)
111125

112-
est = Est().fit(X, y) # single fit
113-
est_cv = EstCV().fit(X, y) # cross-validation
126+
Est(quantile=0.5).fit(X, y)
114127
```
115128

116129

@@ -137,5 +150,7 @@ bug fixes, spelling errors, new features, etc.
137150

138151
Beck, A. and Teboulle, M., 2009. [A fast iterative shrinkage-thresholding algorithm for linear inverse problems](https://epubs.siam.org/doi/pdf/10.1137/080716542?casa_token=cjyK5OxcbSoAAAAA:lQOp0YAVKIOv2-vgGUd_YrnZC9VhbgWvZgj4UPbgfw8I7NV44K82vbIu0oz2-xAACBz9k0Lclw). SIAM journal on imaging sciences, 2(1), pp.183-202.
139152

153+
Zou, H. and Li, R., 2008. [One-step sparse estimates in nonconcave penalized likelihood models](http://www.personal.psu.edu/ril4/research/AOS0316.pdf). Annals of statistics, 36(4), p.1509.
154+
140155

141156
Fan, J., Xue, L. and Zou, H., 2014. [Strong oracle optimality of folded concave penalized estimation](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4295817/). Annals of statistics, 42(3), p.819.

0 commit comments

Comments
 (0)