library(sssp)
v <- c(10, -1, 2, 3, 9, 0, -4, -8, 7, 6)
groups <- c(3, 4, 3)
res <- sssp_project(v, groups, r = 3, s = 6)
print(res)
## SSSP algorithm — J. Shen & S. Damadi, Sparse projection onto semi-symmetric sets with applications to sparse optimization, J. Global Optimization (2026), doi:10.1007/s10898-026-01592-y
## objective ||x - v||_2^2: 14
## optimal tuple r*: 1, 2, 3
## selected groups: 1, 2, 3
## tuples enumerated: 13
## wall time: 0 sHere v is \(v \in
\mathbb{R}^{10}\), groups encodes \(\mathcal{L}_1=\{1,2,3\}\), \(\mathcal{L}_2=\{4,5,6,7\}\), and \(\mathcal{L}_3=\{8,9,10\}\), r
is the group sparsity level \(r\), and
s is the sparsity level \(s\). With \(r=p=3\), the group sparsity restriction is
removed and the feasible exact-\(s\)
tuple count is 13.
res_r2 <- sssp_project(v, groups, r = 2, s = 6)
print(res_r2)
## SSSP algorithm — J. Shen & S. Damadi, Sparse projection onto semi-symmetric sets with applications to sparse optimization, J. Global Optimization (2026), doi:10.1007/s10898-026-01592-y
## objective ||x - v||_2^2: 105
## optimal tuple r*: 0, 3, 3
## selected groups: 2, 3
## tuples enumerated: 5
## wall time: 0 sThe same projection call accepts a list of 1-based index vectors. The next example uses non-uniform groups of sizes 2, 6, and 4, with \(|\mathcal{L}_1| < s\).
v2 <- c(4, -3, 5, 2, -6, 1, 7, -8, 0.5, 9, -2, 3)
groups2 <- list(c(1, 4), c(2, 3, 5, 8, 9, 10), c(6, 7, 11, 12))
res2 <- sssp_project(v2, groups2, r = 2, s = 5)
print(res2)
## SSSP algorithm — J. Shen & S. Damadi, Sparse projection onto semi-symmetric sets with applications to sparse optimization, J. Global Optimization (2026), doi:10.1007/s10898-026-01592-y
## objective ||x - v||_2^2: 43.25
## optimal tuple r*: 0, 4, 1
## selected groups: 2, 3
## tuples enumerated: 9
## wall time: 0.001 s