Skip to main content
Help us improve Python packaging – donate today!

Python module for spectral learning of weighted automata

Project Description

The **Sp2Learning** package stands for
`SPiCe Spectral Learning (Sp2Learning)
Sp2Learning is a toolbox in
Python for spectral learning algorithms developped in the context of
the Sequence PredIction ChallengE (SPiCe).
Sp2Learning is a toolbox in python for spectral learning algorithms developed in the context of the Sequence PredIction Challenge (SPiCe). These algorithms aim at learning Weighted Automata (WA) using what is named a Hankel matrix. The toolbox thus provides also a class for WA (with a bunch of useful methods), another one for Hankel matrix, and a class for loading data and/or automata, and a class Sample that allows the storage of the data in a useful dictionary form. As WA are a generalization of classical Probabilistic Automaton, everything works for these simpler models.

The core of the learning algorithms is to compute a singular values decomposition of the Hankel matrix and then to construct the weighted automata from the elements of the decomposition. This is done in the class Learning.

In its classic version, the rows of the Hankel matrix are prefixes while its columns are suffixes. Each cell contains then the probability of the sequence starting with the corresponding prefix and ending with the corresponding suffix. In the case of learning, the cells contain observed frequencies. SP2Learning provides other versions, where each cell contains the probability that the corresponding sequence is prefix, a suffix, or a factor.

Formally, the Hankel matrix is bi-infinite. Hence, in case of learning, one has to concentrate on a finite portion. The parameters lrows and lcolumn allows to specified which subsequences are taken into account as rows and columns of the finite matrix (parameter partial should be valued to TRUE in this case). If, instead of a list, an integer is provided, the finite matrix will have all rows and columns that correspond to subsequences up to these given lengths. The learning method requires also the information about the rank of the matrix. This rank corresponds to the number of states of a minimal WA computing the matrix (in case of learning, this is the estimated number of states of the target automaton). There is no easy way to evaluate the rank, a cross-validation approach is usually used to find the best possible value.

Finally, Sp2Learning provides 2 ways to store the Hankel matrix: a classical one as an array, and a sparse version using scipy.sparse.

The original Sp2Learning Toolbox is developed in Python at `LabEx Archimède <>`_ (as a `LIF <>`_ project), Aix-Marseille University.

This package, as well as the Sp2Learning toolbox, is Free software, released under the BSD License.

The latest version of **Sp2Learning** can be downloaded from the following `PyPI page <>`_.

The documentation is available as a `pythonhosted site <>`_.

The development is done in this `gitlab project <>`_, which provides the git repository managing the source code and where issues can be reported.

.. :changelog:


1.0.0 (2016-03-30)
First version

1.1.0 (2016-04-27)
-Memory management optimized
-Sample instances now created using Learning parameters
-Load class modified in consequence
-Functions added in Sample select_columns and select_rows
-Rank tested in Learning

1.1.1 (2016-06-22)
-Removing pickle creation
-Rephrasing output messages

1.1.2 (2016-06-25)
-Bug in prefix and suffix versions :
The empty factors are not taken into account when
creating the factor dictionary in the prefix and suffix versions.

.. -*- mode: rst -*-



.. hlist::

* François Denis

* Rémi Eyraud

* Denis Arrivault

* Dominique Benielli

Release history Release notifications

This version
History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Sp2Learning-1.1.2.tar.gz (20.5 kB) Copy SHA256 hash SHA256 Source None Jun 24, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page