Skip to content
A Python Library for Probabilistic Sparse Coding with Non-Standard Priors and Superpositions
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Build Status Documentation Status


This package contains all the source code to reproduce the numerical experiments described in the paper. It contains a parallelized implementation of the Binary Sparse Coding (BSC) [1], Gaussian Sparse Coding (GSC) [2], Maximum Causes Analysis (MCA) [3], Maximum Magnitude Causes Analysis (MMCA) [4], Ternary Sparse Coding (TSC) [5], and Discrete Sparse Coding [7] models. All these probabilistic generative models are trained using a truncated Expectation Maximization (EM) algorithm [6].

Software dependencies

Python related dependencies can be installed using:

  $ pip install -r requirements.txt

MPI4PY also requires a system level installation of MPI. You can do that on MacOS using Homebrew:

  $ brew install mpich

for Ubuntu systems:

  $ sudo apt install mpich

for any other system you might wish to review the relevent section of the MPI4PY installation guidelines


prosper/ - Python library/framework for MPI parallelized EM-based algorithms. The models' implementations can be found in prosper/em/camodels/.

examples/ - Small examples for initializing and running the models


To install the library run:

  $ git clone
  $ cd prosper
  $ python install

Optionally you can replace the final line with:

  $ python develop

This option installs the library using links and it allows the user to edit the library without reinstalling it (useful for Prosper developers).


To run some toy examples:

  $ cd examples/barstest
  $ python param-bars-<...>.py

where <...> should be appropriately replaced to correspond to one of the parameter files available in the directory. The script should then initialize and run the algorithm which corresponds to the chosen parameter file.


The results produced by the code are stored in a 'results.h5' file under "./output/.../". The file stores the model parameters (e.g., W, pi etc.) for each EM iteration performed. To read the results file, you can use openFile function of the standard tables package in python. Moreover, the results files can also be easily read by other packages such as Matlab etc.

Running on a parallel architecture

The code uses MPI based parallelization. If you have parallel resources (i.e., a multi-core system or a compute cluster), the provided code can make a use of parallel compute resources by evenly distributing the training data among multiple cores.

To run the same script as above, e.g.,

a) On a multi-core machine with 32 cores:

$ mpirun -np 32 param-bars-<...>.py

b) On a cluster:

$ mpirun --hostfile machines python param-bars-<...>.py

where 'machines' contains a list of suitable machines.

See your MPI documentation for the details on how to start MPI parallelized programs.


[1] M. Henniges, G. Puertas, J. Bornschein, J. Eggert, and J. Lücke (2010). Binary Sparse Coding. Proc. LVA/ICA 2010, LNCS 6365, 450-457.

[2] A.-S. Sheikh, J. A. Shelton, J. Lücke (2014). A Truncated EM Approach for Spike-and-Slab Sparse Coding. Journal of Machine Learning Research, 15:2653-2687.

[3] G. Puertas, J. Bornschein, and J. Lücke (2010). The Maximal Causes of Natural Scenes are Edge Filters. Advances in Neural Information Processing Systems 23, 1939-1947.

[4] J. Bornschein, M. Henniges, J. Lücke (2013). Are V1 simple cells optimized for visual occlusions? A comparative study. PLOS Computational Biology 9(6): e1003062.

[5] G. Exarchakis, M. Henniges, J. Eggert, and J. Lücke (2012). Ternary Sparse Coding. International Conference on Latent Variable Analysis and Signal Separation (LVA/ICA), 204-212.

[6] J. Lücke and J. Eggert (2010). Expectation Truncation and the Benefits of Preselection in Training Generative Models. Journal of Machine Learning Research 11:2855-2900.

[7] G. Exarchakis, and J. Lücke (2017). Discrete Sparse Coding. Neural Computation, 29(11), 2979-3013.

You can’t perform that action at this time.