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)
pip install spams-cythongit clone https://github.com/getspams/spams-cython.git
cd spams-cython
pip install .[build-system]
requires = [
"setuptools",
"Cython",
"spams-cython"
]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))from cyspams.interfaces cimport nnls, lassoNote
To build your project with
spams-cythonyou need to have a BLAS/LAPACK library on your system (e.g. OpenBLAS, Intel MKL)
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
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)