Skip to main content

Build Status codecov

This is a library to perform shift-invariant sparse dictionary learning, also known as convolutional sparse coding (CSC), on time-series data. It includes a number of different models:

  1. univariate CSC

  2. multivariate CSC

  3. multivariate CSC with a rank-1 constraint [1]

  4. univariate CSC with an alpha-stable distribution [2]

A mathematical descriptions of these models is available in the documentation.

Installation

To install this package, the easiest way is using pip. It will install this package and its dependencies. The setup.py depends on numpy and cython for the installation so it is advised to install them beforehand. To install this package, please run one of the two commands:

(Latest stable version)

pip install alphacsc

(Development version)

pip install git+https://github.com/alphacsc/alphacsc.git#egg=alphacsc

(Dicodile backend)

pip install numpy cython
pip install alphacsc[dicodile]

To use dicodile backend, do not forget to set MPI_HOSTFILE environment variable.

If you do not have admin privileges on the computer, use the --user flag with pip. To upgrade, use the --upgrade flag provided by pip.

To check if everything worked fine, you can run:

python -c 'import alphacsc'

and it should not give any error messages.

Quickstart

Here is an example to present briefly the API:

import numpy as np
import matplotlib.pyplot as plt
from alphacsc import BatchCDL

# Define the different dimensions of the problem
n_atoms = 10
n_times_atom = 50
n_channels = 5
n_trials = 10
n_times = 1000

# Generate a random set of signals
X = np.random.randn(n_trials, n_channels, n_times)

# Learn a dictionary with batch algorithm and rank1 constraints.
cdl = BatchCDL(n_atoms, n_times_atom, rank1=True)
cdl.fit(X)

# Display the learned atoms
fig, axes = plt.subplots(n_atoms, 2, num="Dictionary")
for k in range(n_atoms):
    axes[k, 0].plot(cdl.u_hat_[k])
    axes[k, 1].plot(cdl.v_hat_[k])

axes[0, 0].set_title("Spatial map")
axes[0, 1].set_title("Temporal map")
for ax in axes.ravel():
    ax.set_xticklabels([])
    ax.set_yticklabels([])

plt.show()

Dicodile backend

AlphaCSC can use a dicodile-based backend to perform sparse encoding in parallel.

To install dicodile, run pip install alphacsc[dicodile].

Known OpenMPI issues

When self-installing OpenMPI (for instance to run dicodile on a single machine, or for continuous integration), running the dicodile solver might end up causing a deadlock (no output for a long time). It is often due to communication issue between the workers. This issue can often be solved by disabling Docker-related virtual NICs, for instance by running export OMPI_MCA_btl_tcp_if_exclude="docker0".

Bug reports

Use the github issue tracker to report bugs.

Cite our work

If you use this code in your project, please consider citing our work:

Release files for alphacsc 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alphacsc 0.4.1
File Size Uploaded
alphacsc-0.4.1.tar.gz 4.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for alphacsc 0.4.1
File Interpreter ABI Platform
alphacsc-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 MB

Release files / alphacsc-0.4.1.tar.gz

Download URL alphacsc-0.4.1.tar.gz
Size 4.9 MB
Tags Source
SHA-256 checksum
How to use checksums
f1f04bfa1b71e2c054bc16a1b3c807bbde0b704c6bc33ddb5f499fbf66b18866
BLAKE2b-256 checksum
How to use checksums
cc7b8fb639e9aa6090955fdfe348a911641798f6e431cd240c31e16afae13128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / alphacsc-0.4.1-py3-none-any.whl

Download URL alphacsc-0.4.1-py3-none-any.whl
Size 101.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca27cac7a1a5d95aed25d23056b00b62e0d565b3165d042af696d30a1d0e4d37
BLAKE2b-256 checksum
How to use checksums
ae0e694ece3432f143f41b4bccd6868edf26e3c20a8d9aa8127c5ecfea3742d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3

1 release file

0.2.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page