Skip to content

Commit 169baab

Browse files
committed
add Penalties and Regularized Least Squares
format use :cholesky and dropcollinear like in GLM correctly use QR test method :cholesky change types clean after rebase
1 parent 9a72f1d commit 169baab

16 files changed

+4075
-14
lines changed

README.md

+75-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ This package implements:
4040
* MQuantile regression (e.g. Expectile regression)
4141
* Robust Ridge regression (using any of the previous estimator)
4242
* Quantile regression using interior point method
43+
* Regularized Least Square regression
44+
* Θ-IPOD regression, possibly with a penalty term
4345

4446
## Installation
4547

@@ -63,6 +65,15 @@ For quantile regression, use `quantreg`:
6365

6466
`m = quantreg(X, y; quantile=0.5)`
6567

68+
For Regularized Least Squares and a penalty term, use `rlm`:
69+
70+
`m = rlm(X, y, L1Penalty(); method=:cgd)`
71+
72+
For Θ-IPOD regression with outlier detection and a penalty term, use `ipod`:
73+
74+
`m = ipod(X, y, L2Loss(), SquaredL2Penalty(); method=:auto)`
75+
76+
6677
For robust version of `mean`, `std`, `var` and `sem` statistics, specify the estimator as first argument.
6778
Use the `dims` keyword for computing the statistics along specific dimensions.
6879
The following functions are also implemented: `mean_and_std`, `mean_and_var` and `mean_and_sem`.
@@ -119,6 +130,16 @@ m9 = rlm(form, data, MEstimator{TukeyLoss}(); initial_scale=:L1, ridgeλ=1.0)
119130
## Quantile regression solved by linear programming interior point method
120131
m10 = quantreg(form, data; quantile=0.2)
121132
refit!(m10; quantile=0.8)
133+
134+
## Penalized regression
135+
m11 = rlm(form, data, SquaredL2Penalty(); method=:auto)
136+
137+
## Θ-IPOD regression with outlier detection
138+
m12 = ipod(form, data, TukeyLoss(); method=:auto)
139+
140+
## Θ-IPOD regression with outlier detection and a penalty term
141+
m13 = ipod(form, data, L2Loss(), L1Penalty(); method=:ama)
142+
122143
;
123144

124145
# output
@@ -136,7 +157,7 @@ With ordinary least square (OLS), the objective function is, from maximum likeli
136157
where `yᵢ` are the values of the response variable, `𝒙ᵢ` are the covectors of individual covariates
137158
(rows of the model matrix `X`), `𝜷` is the vector of fitted coefficients and `rᵢ` are the individual residuals.
138159

139-
A `RobustLinearModel` solves instead for the following loss function: `L' = Σᵢ ρ(rᵢ)`
160+
A `RobustLinearModel` solves instead for the following loss function [1]: `L' = Σᵢ ρ(rᵢ)`
140161
(more precisely `L' = Σᵢ ρ(rᵢ/σ)` where `σ` is an (robust) estimate of the standard deviation of the residual).
141162
Several loss functions are implemented:
142163

@@ -182,6 +203,17 @@ Using an asymmetric variant of the `L1Estimator`, quantile regression is perform
182203
Identically, with an M-estimator using an asymetric version of the loss function,
183204
a generalization of quantiles is obtained. For instance, using an asymetric `L2Loss` results in _Expectile Regression_.
184205

206+
### Quantile regression
207+
208+
_Quantile regression_ results from minimizing the following objective function:
209+
`L = Σᵢ wᵢ|yᵢ - 𝒙ᵢ 𝜷| = Σᵢ wᵢ(rᵢ) |rᵢ|`,
210+
where `wᵢ = ifelse(rᵢ>0, τ, 1-τ)` and `τ` is the quantile of interest. `τ=0.5` corresponds to _Least Absolute Deviations_.
211+
212+
This problem is solved exactly using linear programming techniques,
213+
specifically, interior point methods using the internal API of [Tulip](https://github.com/ds4dm/Tulip.jl).
214+
The internal API is considered unstable, but it results in a much lighter dependency than
215+
including the [JuMP](https://github.com/JuliaOpt/JuMP.jl) package with Tulip backend.
216+
185217
### Robust Ridge regression
186218

187219
This is the robust version of the ridge regression, adding a penalty on the coefficients.
@@ -192,16 +224,44 @@ By default, all the coefficients (except the intercept) have the same penalty, w
192224
all the feature variables have the same scale. If it is not the case, use a robust estimate of scale
193225
to normalize every column of the model matrix `X` before fitting the regression.
194226

195-
### Quantile regression
227+
### Regularized Least Squares
196228

197-
_Quantile regression_ results from minimizing the following objective function:
198-
`L = Σᵢ wᵢ|yᵢ - 𝒙ᵢ 𝜷| = Σᵢ wᵢ(rᵢ) |rᵢ|`,
199-
where `wᵢ = ifelse(rᵢ>0, τ, 1-τ)` and `τ` is the quantile of interest. `τ=0.5` corresponds to _Least Absolute Deviations_.
229+
_Regularized Least Squares_ regression is the solution of the minimization of following objective function:
230+
`L = ½ Σᵢ |yᵢ - 𝒙ᵢ 𝜷|² + P(𝜷)`,
231+
where `P(𝜷)` is a (sparse) penalty on the coefficients.
232+
233+
The following penalty function are defined:
234+
- `NoPenalty`: `cost(𝐱) = 0`, no penalty.
235+
- `SquaredL2Penalty`: `cost(𝐱) = λ ½||𝐱||₂²`, also called Ridge.
236+
- `L1Penalty`: `cost(𝐱) = λ||𝐱||₁`, also called LASSO.
237+
- `ElasticNetPenalty`: `cost(𝐱) = λ . l1_ratio .||𝐱||₁ + λ .(1 - l1_ratio) . ½||𝐱||₂²`.
238+
- `EuclideanPenalty`: `cost(𝐱) = λ||𝐱||₂`, non-separable penalty used in Group LASSO.
239+
240+
Different penalties can be applied to different indices of the coefficients, using
241+
`RangedPenalties(ranges, penalties)`. E.g., `RangedPenalties([2:5], [L1Penalty(1.0)])` defines
242+
a L1 penalty on every coefficients except the first index, which can correspond to the intercept.
243+
244+
With a penalty, the following solvers are available (instead of the other ones):
245+
- `:cgd`, Coordinate Gradient Descent [2].
246+
- `:fista`, Fast Iterative Shrinkage-Thresholding Algorithm [3].
247+
- `:ama`, Alternating Minimization Algorithm [4].
248+
- `:admm`, Alternating Direction Method of Multipliers [5].
249+
250+
To use a robust loss function with a penalty, see Θ-IPOD regression.
251+
252+
### Θ-IPOD regression
253+
254+
_Θ-IPOD regression_ (Θ-thresholding based Iterative Procedure for Outlier Detection) results from
255+
minimizing the following objective function [6]:
256+
`L = ½ Σᵢ |yᵢ - 𝒙ᵢ 𝜷 - γᵢ|² + P(𝜷) + Q(γ)`,
257+
where `Q(γ)` is a penalty function on the outliers `γ` that is sparse so the problem is not underdetermined.
258+
We don't need to know the expression of this penalty function, just that it leads to thresholding using
259+
one of the loss function used by M-Estimators. Then Θ-IPOD is equivalent to solving an M-Estimator.
260+
This problem is solved using an alternating minimization technique, for the outlier detection.
261+
Without penalty, the coefficients are updated at every step using a solver for _Ordinary Least Square_.
262+
263+
`P(𝜷)` is an optionnal (sparse) penalty on the coefficients.
200264

201-
This problem is solved exactly using linear programming techniques,
202-
specifically, interior point methods using the internal API of [Tulip](https://github.com/ds4dm/Tulip.jl).
203-
The internal API is considered unstable, but it results in a much lighter dependency than
204-
including the [JuMP](https://github.com/JuliaOpt/JuMP.jl) package with Tulip backend.
205265

206266
## Credits
207267

@@ -215,4 +275,9 @@ for implementing the Iteratively Reweighted Least Square algorithm.
215275

216276
## References
217277

218-
- "Robust Statistics: Theory and Methods (with R)", 2nd Edition, 2019, R. Maronna, R. Martin, V. Yohai, M. Salibián-Barrera
278+
[1] "Robust Statistics: Theory and Methods (with R)", 2nd Edition, 2019, R. Maronna, R. Martin, V. Yohai, M. Salibián-Barrera
279+
[2] "Regularization Paths for Generalized Linear Models via Coordinate Descent", 2009, J. Friedman, T. Hastie, R. Tibshirani
280+
[3] "A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse Problems", 2009, A. Beck, M. Teboulle
281+
[4] "Applications of a splitting algorithm to decomposition in convex programming and variational inequalities", 1991, P. Tseng
282+
[5] "Fast Alternating Direction Optimization Methods", 2014, T. Goldstein, B. O'Donoghue, S. Setzer, R. Baraniuk
283+
[6] "Outlier Detection Using Nonconvex Penalized Regression", 2011, Y. She, A.B. Owen

docs/src/api.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AbstractQuantileEstimator
99
LossFunction
1010
RobustLinearModel
1111
RobustModels.RobustLinResp
12+
RobustModels.IPODResp
1213
GLM.LinPred
1314
RobustModels.DensePredCG
1415
RobustModels.SparsePredCG
@@ -17,7 +18,12 @@ GLM.SparsePredChol
1718
GLM.DensePredQR
1819
RobustModels.RidgePred
1920
RobustModels.AbstractRegularizedPred
21+
RobustModels.CGDPred
22+
RobustModels.FISTAPred
23+
RobustModels.AMAPred
24+
RobustModels.ADMMPred
2025
QuantileRegression
26+
IPODRegression
2127
```
2228

2329
## Constructors for models
@@ -30,6 +36,7 @@ fit(::Type{M}, ::Union{AbstractMatrix{T}}, ::AbstractVector{T}) where {T<:Abstra
3036
```@docs
3137
rlm
3238
quantreg
39+
ipod
3340
fit!
3441
refit!
3542
```
@@ -67,10 +74,13 @@ StatsAPI.residuals
6774
StatsModels.hasintercept
6875
hasformula
6976
formula
77+
haspenalty
78+
penalty
7079
scale
7180
tauscale
7281
RobustModels.location_variance
7382
Estimator
83+
outliers
7484
GLM.linpred!
7585
RobustModels.pirls!
7686
RobustModels.pirls_Sestimate!
@@ -111,7 +121,17 @@ HardThresholdLoss
111121
HampelLoss
112122
```
113123

114-
## Estimator and Loss functions methods
124+
## Penalty functions
125+
```@docs
126+
NoPenalty
127+
SquaredL2Penalty
128+
EuclideanPenalty
129+
L1Penalty
130+
ElasticNetPenalty
131+
RangedPenalties
132+
```
133+
134+
## Estimator, Loss and Penalty functions methods
115135
```@docs
116136
RobustModels.rho
117137
RobustModels.psi
@@ -139,4 +159,10 @@ RobustModels.set_MEstimator
139159
RobustModels.update_weight!
140160
RobustModels.tau_scale_estimate
141161
RobustModels.quantile_weight
162+
RobustModels.cost
163+
RobustModels.proximal!
164+
RobustModels.proximal
165+
RobustModels.isconcrete
166+
RobustModels.concrete!
167+
RobustModels.concrete
142168
```

src/RobustModels.jl

+23
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ export LossFunction,
173173
GeneralizedQuantileEstimator,
174174
ExpectileEstimator,
175175
L2Estimator,
176+
PenaltyFunction,
177+
NoPenalty,
178+
SquaredL2Penalty,
179+
L1Penalty,
180+
ElasticNetPenalty,
181+
EuclideanPenalty,
182+
BerhuPenalty,
183+
CappedL1Penalty,
184+
SCADPenalty,
185+
MCPPenalty,
186+
RangedPenalties,
187+
End,
176188
DensePredCG,
177189
SparsePredCG,
178190
RidgePred,
@@ -183,6 +195,11 @@ export LossFunction,
183195
Estimator,
184196
rlm,
185197
quantreg,
198+
IPODRegression,
199+
ipod,
200+
outliers,
201+
penalty,
202+
haspenalty,
186203
loss,
187204
tuning_constant,
188205
refit!,
@@ -224,6 +241,9 @@ abstract type AbstractMEstimator <: AbstractEstimator end
224241
"Generalized M-Quantile estimator"
225242
abstract type AbstractQuantileEstimator <: AbstractMEstimator end
226243

244+
"Penalty function"
245+
abstract type PenaltyFunction{T} end
246+
227247

228248
"""
229249
AbstractRobustModel
@@ -243,17 +263,20 @@ abstract type AbstractRegularizedPred{T} end
243263

244264
Base.broadcastable(m::AbstractEstimator) = Ref(m)
245265
Base.broadcastable(m::LossFunction) = Ref(m)
266+
Base.broadcastable(m::PenaltyFunction) = Ref(m)
246267

247268

248269
include("tools.jl")
249270
include("losses.jl")
250271
include("estimators.jl")
272+
include("penalties.jl")
251273
include("linpred.jl")
252274
include("regularizedpred.jl")
253275
include("linresp.jl")
254276
include("robustlinearmodel.jl")
255277
include("univariate.jl")
256278
include("quantileregression.jl")
279+
include("ipod.jl")
257280
include("deprecated.jl")
258281

259282
end # module

0 commit comments

Comments
 (0)