Skip to main content

Parametric Simplex Method for Sparse Learning

Project description

pyprimal

pyprimal: Parametric Simplex Method for Sparse Learning

A native Python package implementing the parametric simplex method for a variety of sparse learning problems including Dantzig selector, sparse SVM, compressed sensing, and quantile regression. The core algorithm is implemented in C++ with Eigen support; Python wraps it via ctypes with no R dependency.

Directory structure

python-package/
├── pyprimal/           Package source
│   ├── core.py         Solvers and PrimalResult dataclass
│   ├── libpath.py      Shared library loader
│   └── lib/            Compiled libpsm (.so / .dylib)
├── docs/               MkDocs documentation pages
├── examples/           Runnable example scripts
├── tests/              Unit tests (pytest)
├── mkdocs.yml          Documentation configuration
└── pyproject.toml      Build configuration

Requirements

  • Python >= 3.9
  • NumPy >= 1.23
  • Compiled libpsm shared library (Linux .so or macOS .dylib)
  • Optional: matplotlib >= 3.5 for plotting

Installation

From source (recommended):

git clone https://github.com/Gatech-Flash/primal.git
cd primal

# Build the C++ library
make clean && make dylib

# Install the Python package
cd python-package
pip install -e ".[viz,test]"

Optional extras:

pip install -e ".[viz]"    # matplotlib for plotting
pip install -e ".[test]"   # pytest for testing
pip install -e ".[docs]"   # mkdocs for documentation

Verify installation:

python -c "import pyprimal; pyprimal.test()"

Usage

import numpy as np
from pyprimal import dantzig_solver, sparse_svm_solver

# Dantzig selector
rng = np.random.default_rng(42)
X = rng.standard_normal((100, 20))
beta_true = np.array([1]*5 + [0]*15, dtype=float)
y = X @ beta_true + 0.1 * rng.standard_normal(100)

result = dantzig_solver(X, y)
print(result)           # summary
result.coef()           # coefficients at last iteration
result.coef(3)          # coefficients at iteration 3
result.plot()           # all three plots
result.plot(1)          # regularization path only

# Sparse SVM
y_svm = np.where(X[:, 0] + X[:, 1] > 0, 1.0, -1.0)
result_svm = sparse_svm_solver(X, y_svm)
print(result_svm)

Available solvers

Function Problem
dantzig_solver(X, y) Dantzig selector
sparse_svm_solver(X, y) Sparse support vector machine
compressed_sensing_solver(X, y) Compressed sensing
quantile_regression_solver(X, y, tau=0.5) Quantile regression

All solvers return a PrimalResult dataclass with:

  • .beta -- coefficient matrix (d x iterN)
  • .lambda_ -- regularization parameter path
  • .value -- objective function values
  • .df -- degrees of freedom along the path
  • .summary() / print(result) -- formatted summary
  • .coef(n) -- extract coefficients at iteration n (1-based index)
  • .plot(n) -- visualize the solution path

Documentation

Build the documentation locally:

pip install -e ".[docs]"
mkdocs build
mkdocs serve          # opens at http://127.0.0.1:8000

Developer workflow

# Run tests
pip install -e ".[test]"
pytest tests/ -v

# Build docs
pip install -e ".[docs]"
mkdocs build --strict

Citation

@article{li2018primal,
  title={The Parametric Simplex Method for Sparse Learning},
  author={Li, Zichong and Shen, Qianli and Zhao, Tuo},
  year={2018}
}

License

GPL-3.0

Authors

Zichong Li, Qianli Shen, Tuo Zhao

Maintainer: Tuo Zhao tourzhao@gatech.edu

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyprimal-2.0.0.tar.gz (538.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyprimal-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (550.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

pyprimal-2.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (556.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

pyprimal-2.0.0-py3-none-macosx_11_0_arm64.whl (426.9 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file pyprimal-2.0.0.tar.gz.

File metadata

  • Download URL: pyprimal-2.0.0.tar.gz
  • Upload date:
  • Size: 538.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyprimal-2.0.0.tar.gz
Algorithm Hash digest
SHA256 478202c151f28596dd7f1793b742532625067be986142f2129031cea0ef48cd3
MD5 52a91c594b06d57f0194b8ed84d8a84f
BLAKE2b-256 05db0681994ea7711b95d9f1a8047a002c3792f95ee7689ff1aaea4c76539c7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyprimal-2.0.0.tar.gz:

Publisher: build-publish.yml on ShenQianli/primal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyprimal-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyprimal-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aaac185ad6a0b4eff51c5db2f5457b0eb89958c78f58060ed4fd38bd6f875a2d
MD5 cf6f914d818c8605e34455aed8fc1ea9
BLAKE2b-256 6605ee3621da8282fe01133af4d4b7e81437314f00052a0073f90ea1178260a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyprimal-2.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-publish.yml on ShenQianli/primal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyprimal-2.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pyprimal-2.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 34cf9d70a345ceef7dddafd4b9511e21ea802e6d7e5412390db5ff6079e2ac14
MD5 c9a2df6d42961eecb281ee8dbdb35d85
BLAKE2b-256 a3c91a769c4a52e53654e635e9d5e8473ceca948e0d0ce541e7a87562c353a4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyprimal-2.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: build-publish.yml on ShenQianli/primal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyprimal-2.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyprimal-2.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 14a423ff666d7149ddfba47b5fd39820e66bfe2c2a9e58dd401d315eda03c115
MD5 e1c8dfddec84416e8a36312a54d1869f
BLAKE2b-256 1a8305434999a9ec8737d0f3f3e0e73fa2909f760a8c9422c3b4f1df7841f967

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyprimal-2.0.0-py3-none-macosx_11_0_arm64.whl:

Publisher: build-publish.yml on ShenQianli/primal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page