# L1 regularization with box constraint in JuMP?

**URL:** https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105
**Category:** Optimization (Mathematical)
**Created:** [October 27, 2020, 9:16am UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105 "2020-10-27T09:16:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)
#### Post date: [October 27, 2020, 9:16am UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105/1 "2020-10-27T09:16:27Z")

</div>

Does JuMP have **L1 regularization with box constraint** in following form as utility ?

**minimize || Ax - b ||**  
subject to 1st norm of x i.e. **|x| \< lambda** (some parameter)  
and **0 \<= x[i] \<= kappa** (some parameter)  
where, **A is some tall matrix and b is some tall vector**

(If not, and you know any other package that supports such kind of optimization, please let me know)  
I was suggested to use [NormOneCone](https://jump.dev/MathOptInterface.jl/stable/apireference/#MathOptInterface.NormOneCone) utility, but I am not aware with the syntax.

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [October 27, 2020, 1:58pm UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105/2 "2020-10-27T13:58:19Z")

</div>

You should use `@constraint(model, [λ, x] in MOI.NormOneCone(length(x) + 1))`

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [October 27, 2020, 2:14pm UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105/3 "2020-10-27T14:14:22Z")

</div>

Why not build a function to do it based on Proximal Gradient Descent / ADMM?

It takes ~10-15 lines and probably will be much faster than JuMP.

See for instance [Solving LASSO (Basis Pursuit Denoising Form) with LARS](https://dsp.stackexchange.com/questions/65986) and [Constrained LASSO Problem - L1 Regularized Least Squares with Linear Equality Constraints](https://dsp.stackexchange.com/questions/54853) (MATLAB Code is linked, but it will be easy to convert it to Julia).

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [October 27, 2020, 4:35pm UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105/4 "2020-10-27T16:35:04Z")

</div>

> It takes ~10-15 lines and probably will be much faster than JuMP

You could also use an ADMM solver specialized for this problem through JuMP 🙂  
For example [GitHub - blegat/MCPSD.jl: Julia translation of the mc\_psd.m MATLAB function for solving Max-Cut PSD relaxation](https://github.com/blegat/MCPSD.jl) implements an interior point solver specialized for maxcut (special case of SDP) that can be used through JuMP

---

<div class="post-metadata">

### Author: ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)
#### Post date: [October 28, 2020, 3:07pm UTC](https://discourse.julialang.org/t/l1-regularization-with-box-constraint-in-jump/49105/5 "2020-10-28T15:07:01Z")

</div>

Thank you everyone for your references, I am going through them.  
Meanwhile, I found following way of approaching such kind of problem using Convex.jl  
A is some matrix of `m x n` size, and b is some vector of `m x 1` size, such that `m >= n`

```julia
m = 100; n=5;
k = Convex.Variable(n)
problem = minimize(norm(A*x - b,2),[norm(k,1) <= λ,k >= 0, k <= κ])
Convex.solve!(problem, () -> SCS.Optimizer(max_iters = 100000, verbose = false))

```
