Skip to main content

SPArse Modeling Software (SPAMS) Cython interface

Project description

spams-cython

This package exposes convenient interfaces of some functions of the SPArse Modeling Software (SPAMS) C++ library, allowing them to be used from Cython code by releasing the Python Global Interpreter Lock (GIL)

Installation from PyPI

pip install spams-cython

Installation from source

git clone https://github.com/getspams/spams-cython.git
cd spams-cython
pip install .

Use spams-cython into your project

pyproject.toml

[build-system]
requires = [
    "setuptools",
    "Cython",
    "spams-cython"
]

setup.py

from setuptools import setup, Extension
from Cython.Build import cythonize
import cyspams

extensions = [
    Extension(
        mymodule,
        sources['mymodule.pyx'],
        include_dirs=cyspams.get_include()
    )
]

setup(ext_modules=cythonize(extensions))

mymodule.pyx

from cyspams.interfaces cimport nnls, lasso

Note

To build your project with spams-cython you need to have a BLAS/LAPACK library on your system (e.g. OpenBLAS, Intel MKL)

Exposed functions

nnls

void nnls(const double *A, const double *y, const int m, const int n, double *x, double &rnorm)

Args in:
A → Matrix 'A = (m, n)' stored as 1D contiguous array (column-major order)
y → Vector 'y = (m)'
m → Dimension 'm'
n → Dimension 'n'

Args out:
x → Solution vector 'x = (n)'
rnorm → Squared Euclidean norm of the final residual vector


lasso

void lasso(double *A, double *y, const int m, const int p, const int n, double *x)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2, const int mode, const bint pos)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2, const int mode, const bint pos, const bint ols, const int max_length_path, const int L, const bint cholesky, const int n_threads, const bint verbose)

Args in:
A → Matrix 'A = (m, p)' stored as 1D contiguous array (column-major order)
y → Matrix 'y = (m, n)' stored as 1D contiguous array (column-major order)
m → Dimension 'm'
p → Dimension 'p'
n → Dimension 'n'
lambda1 → Regularization parameter (default = 0.0)
lambda2 → Parameter for solving the Elastic-Net (default = 0.0)
mode → 0 = L1COEFFS, 1 = L2ERROR, 2 = PENALTY, 3 = SPARSITY, 4 = L2ERROR2, 5 = PENALTY2, 6 = FISTAMODE (default = 2)
pos → Adds non-negativity constraints on the coefficients (default = true)
ols → Perform an orthogonal projection before returning the solution (default = false)
max_length_path → Maximum length of the path (default = -1)
L → Maximum number of steps of the homotopy algorithm. Can be used as a stopping criterion (default = -1)
cholesky → Choose between Cholesky implementation or one based on the matrix inversion Lemma (default = false)
n_threads → Number of threads to use (default = 1)
verbose → Verbose mode (default = false)

Args out:
x → Solution matrix 'x = (p, n)' stored as 1D contiguous array (column-major order)


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

spams-cython-1.0.0.tar.gz (148.7 kB view hashes)

Uploaded Source

Built Distribution

spams_cython-1.0.0-py3-none-any.whl (157.1 kB view hashes)

Uploaded Python 3

Supported by

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