Sparse Approximation by the Generalized Soft-Min Penalty
Project description
sparse-approx-gsm
Python (+ optional CUDA) implementation of Sparse Approximation by the Generalized Soft-Min (GSM) Penalty — a sparse-recovery solver based on the Trimmed Lasso.
Solves: min ||Ax - y||_2 subject to ||x||_0 <= k
Tal Amir, Ronen Basri, Boaz Nadler — The Trimmed Lasso: Sparse Recovery Guarantees and Practical Optimization by the Generalized Soft-Min Penalty. Weizmann Institute of Science.
Install
From PyPI:
pip install sparse-approx-gsm
From source (with CUDA extension):
pip install pybind11 scikit-build-core cython numpy
NVCC=/path/to/nvcc
PYBIND11_DIR=$(python -c "import pybind11; print(pybind11.get_cmake_dir())")
CMAKE_ARGS="-DCMAKE_CUDA_COMPILER=$NVCC -Dpybind11_DIR=$PYBIND11_DIR -DCMAKE_CXX_COMPILER=/usr/bin/g++" \
pip install --no-build-isolation . -v
From source (CPU only):
pip install --no-build-isolation .
Usage
from sparse_approx_gsm import sparse_approx_gsm, SparseApproxGSM, gsm
# High-level solver: min ||Ax - y||_2 s.t. ||x||_0 <= k
x = sparse_approx_gsm(A, y, k, profile='normal')
# GSM function and gradient
mu, theta = gsm(z, k, gamma)
GPU Acceleration
Install CuPy for the matching CUDA version (e.g. pip install cupy-cuda12x), then pass
a CuPy array to gsm() or use SparseApproxGSM(..., use_gpu=True).
When use_gpu=True, arrays are cached on the GPU and kept there throughout the solver loop, minimizing CPU-GPU data transfers.
What's New in v1.1.0
- GPU transfer optimization: Immutable arrays (A, G, y, Aty) cached on GPU; solution vector and weights stay on GPU through the MM loop
- Redundant computation elimination: GSM mu is cached from weight computation, avoiding duplicate GPU kernel launches
- Cython acceleration: Fused FISTA kernels and OpenMP-parallelized utilities for the CPU fallback path
- Module renamed: Import path is now
sparse_approx_gsm(wasgsm_python)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sparse_approx_gsm-1.1.0.tar.gz.
File metadata
- Download URL: sparse_approx_gsm-1.1.0.tar.gz
- Upload date:
- Size: 2.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
304d2ab54ab94f55369a3439223b1f6cdfeb4b2d35693f684ea1652ff1f973ab
|
|
| MD5 |
eb9fcfeef0817bef7e9433ae79393d25
|
|
| BLAKE2b-256 |
01063f523b9ad2f0f9861f898aae03ff9595a6ec0be36454e12b59cf4c60ffb7
|