Skip to main content

Convolutional dictionary learning for noisy signals.

Project description

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:

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

alphacsc-0.4.0rc12.tar.gz (4.9 MB view details)

Uploaded Source

Built Distribution

alphacsc-0.4.0rc12-py3-none-any.whl (103.1 kB view details)

Uploaded Python 3

File details

Details for the file alphacsc-0.4.0rc12.tar.gz.

File metadata

  • Download URL: alphacsc-0.4.0rc12.tar.gz
  • Upload date:
  • Size: 4.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for alphacsc-0.4.0rc12.tar.gz
Algorithm Hash digest
SHA256 adc2d26ba5290c38a5eb4f2c5fa48acac286ed38e08a46de10e86aa856e2a97e
MD5 95d38203e1ee8e63eaefe9a99c591f53
BLAKE2b-256 21b9c2dabc00c535da5fa9600e860b4135b6d21a2715be61ffdd9e1f5e204024

See more details on using hashes here.

File details

Details for the file alphacsc-0.4.0rc12-py3-none-any.whl.

File metadata

  • Download URL: alphacsc-0.4.0rc12-py3-none-any.whl
  • Upload date:
  • Size: 103.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for alphacsc-0.4.0rc12-py3-none-any.whl
Algorithm Hash digest
SHA256 3b9bede3f0ef7e45d44d330227506d28b444637bfcc95f5257ef5ae57a894e14
MD5 f319530259258aa46ffdad3af1954d40
BLAKE2b-256 95f29369968639a94a49600190472e9da8f5134d96f942d13391d7db0ddadf4e

See more details on using hashes here.

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