# Projection onto intersection of L\_0 ball and L\_infty ball via ShiftedProximalOperators

**URL:** https://discourse.julialang.org/t/projection-onto-intersection-of-l-0-ball-and-l-infty-ball-via-shiftedproximaloperators/127949
**Category:** Optimization (Mathematical)
**Tags:** question, package
**Created:** [April 10, 2025, 8:44pm UTC](https://discourse.julialang.org/t/projection-onto-intersection-of-l-0-ball-and-l-infty-ball-via-shiftedproximaloperators/127949 "2025-04-10T20:44:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)
#### Post date: [April 10, 2025, 8:44pm UTC](https://discourse.julialang.org/t/projection-onto-intersection-of-l-0-ball-and-l-infty-ball-via-shiftedproximaloperators/127949/1 "2025-04-10T20:44:36Z")

</div>

I am trying to follow the [paper](https://arxiv.org/pdf/2204.05429) describing a method to project a point x^0 onto the set C:=\{x : x\in kB\_0 \cap x\in \Delta B\_\infty\} where kB\_0=\{x : ||x||\_0\leq k\} and \Delta B\_\infty=\{x:||x||\_\infty\leq\Delta\}. It is said that such a method is implemented in the [`ShiftedProximalOperators`](https://github.com/JuliaSmoothOptimizers/ShiftedProximalOperators.jl) package, but I have not been able to find it. When I tried to implement the projection in the package as below, I wasn’t sure how to add the indicator of kB\_0; below only seems to add regularization. I know that there is a regularization parameter that corresponds to the projection, but am I missing an easy way to use the package to do projection?

```julia
using ShiftedProximalOperators, Random
Random.seed!(12345)

# Parameters
n = 10 # dimension
k = 3 # sparsity
δ = 1.0 # infinity norm bound
x0 = randn(n) * 3 # input vector

# define ℓ₀ pseudo-norm
h = ShiftedProximalOperators.NormL0(1.0)

# create ShiftedNormL0Box
xk = zeros(n) # no shift
sj = zeros(n) # no shift
l = -δ*ones(n) # lower bound
u = +δ*ones(n) # upper bound
selected = sortperm(abs.(x0), rev=true)[1:k]
ψ = ShiftedProximalOperators.ShiftedNormL0Box(h, xk, sj, l, u, false, selected)

# project onto feasible set
xproj = similar(x0)
σ = 1.0

julia> prox!(xproj, ψ, x0, σ)
10-element Vector{Float64}:
 -1.0
 -1.0
  1.0
  1.0
 -1.0
 -1.0
  1.0
 -1.0
  1.0
  1.0

```

When if I repeat the above with `h = ShiftedProximalOperators.NormL0(1.0e6)`, I get

```julia
julia> prox!(y, ψ, q, σ)
10-element Vector{Float64}:
 -0.0
 -1.0
  1.0
  1.0
 -1.0
 -0.0
  1.0
 -0.0
  1.0
  1.0

```

where the zeros correspond to the indices in `selected`.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [April 10, 2025, 9:28pm UTC](https://discourse.julialang.org/t/projection-onto-intersection-of-l-0-ball-and-l-infty-ball-via-shiftedproximaloperators/127949/2 "2025-04-10T21:28:25Z")

</div>

Seems like this is a question for @dpo

---

<div class="post-metadata">

### Author: ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)
#### Post date: [April 11, 2025, 2:00am UTC](https://discourse.julialang.org/t/projection-onto-intersection-of-l-0-ball-and-l-infty-ball-via-shiftedproximaloperators/127949/3 "2025-04-11T02:00:17Z")

</div>

Ah, I may have just missed it [here](https://github.com/JuliaSmoothOptimizers/ShiftedProximalOperators.jl/blob/master/src/shiftedIndBallL0BInf.jl)!
