Sparse Optimisation Research Code: A Python package for sparse coding and dictionary learning

Sparse, Representations, Coding, Dictionary, Learning, Convolutional, Optimization, ADMM, PGM, convolutional-dictionary-learning, convolutional-sparse-coding, cuda, dictionary-learning, fista, optimization-algorithms, plug-and-play-priors, python, robust-pca, sparse-coding, sparse-representations, sparsity, total-variation, total-variation-minimization
pip install sporco==0.2.1


SParse Optimization Research COde (SPORCO)

Supported Python Versions Package License Documentation Status Test status Test Coverage PyPi Release PyPi Downloads Conda Forge Release Conda Forge Downloads Binder DOI

SPORCO is a Python package for solving optimisation problems with sparsity-inducing regularisation. These consist primarily of sparse coding and dictionary learning problems, including convolutional sparse coding and dictionary learning, but there is also support for other problems such as Total Variation regularisation and Robust PCA. The optimisation algorithms in the current version are based on the Alternating Direction Method of Multipliers (ADMM) or on the Proximal Gradient Method (PGM).

If you use this software for published work, please cite it.


Documentation is available online, or can be built from the root directory of the source distribution by the command

python build_sphinx

in which case the HTML documentation can be found in the build/sphinx/html directory (the top-level document is index.html). Although the SPORCO package itself is compatible with Python 3.x, building the documention requires Python 3.3 or later due to the use of Jonga to construct call graph images for the SPORCO optimisation class hierarchies.

An overview of the package design and functionality is also available in

Brendt Wohlberg, SPORCO: A Python package for standard and convolutional sparse representations, in Proceedings of the 15th Python in Science Conference, (Austin, TX, USA), doi:10.25080/shinma-7f4c6e7-001, pp. 1--8, Jul 2017


Scripts illustrating usage of the package can be found in the examples directory of the source distribution. These examples can be run from the root directory of the package by, for example

python examples/scripts/sc/

To run these scripts prior to installing the package it will be necessary to first set the PYTHONPATH environment variable to include the root directory of the package. For example, in a bash shell


from the root directory of the package.

Jupyter Notebook examples are also available. These examples can be viewed online via nbviewer, or run interactively at binder.


The primary requirements are Python itself, and modules future, numpy, scipy, imageio, pyfftw, and matplotlib. Module numexpr is not required, but some functions will be faster if it is installed. If module mpldatacursor is installed, functions plot.plot, plot.contour, and plot.imview will support the data cursor that it provides.

Instructions for installing these requirements are provided in the Requirements section of the package documentation.


To install the most recent release of SPORCO from PyPI do

pip install sporco

The development version on GitHub can be installed by doing

pip install git+

or by doing

git clone

followed by

cd sporco
python build
python install

The install commands will usually have to be performed with root privileges.

SPORCO can also be installed as a conda package from the conda-forge channel

conda install -c conda-forge sporco

A summary of the most significant changes between SPORCO releases can be found in the CHANGES.rst file. It is strongly recommended to consult this summary when updating from a previous version.


Some additional components of SPORCO are made available in separate repositories:

  • SPORCO-CUDA: GPU-accelerated versions of selected convolutional sparse coding algorithms
  • SPORCO Notebooks: Jupyter Notebook versions of the example scripts distributed with SPORCO
  • SPORCO Extra: Additional examples, data, and contributed code


SPORCO is distributed as open-source software under a BSD 3-Clause License (see the LICENSE file for details).