Skip to main content

sequence modelling using HMMs

Project description

tests docs build

sequence-modelling

Numerically optimized time-series and sequence modelling in Python.

Key features

  • Hidden Markov Models and Quasi-Deterministic Hidden Markov Models
  • Numerically stable: floating point arithmetic performed in log space to avoid underflow
  • Easy to use (based on the scikit-learn API)
  • Pure Python and Numpy based
  • Open source and commercially usable (BSD license)
  • Support for discrete and continuous (Gaussian) emissions

Installation

The easiest way to install sequence-modelling is using pip:

   pip install sequence-modelling

Example usage

   import numpy as np
   from sequence_modelling.emmissions import Gaussian
   from sequence_modelling.hmm import StandardHMM
   import sequence_modelling.hmmviz as plt

   # define a 2-state HMM estimator with one-dimensional Gaussian emissions

   # the transition matrix
   A = np.array([[0.6, 0.4],
                 [0.3, 0.7],
                 [0.5, 0.5]])

   # the emission object
   O = Gaussian(mu=np.array([[-100.0, 100.0]]),
             covar=np.array([[[10.0]], [[10.0]]]))

   # build the HMM model object
   hmm = StandardHMM(A, O)

   # sample 100 observations from the generative model
   obs, path = hmm.sample(dim=1, N=100)

    # fit the model to the data
   likelihood, ll, duration, rankn, res = hmm.fit([obs])

   # decode (predict) the most likely state sequence using the Viterbi algorithm
   decoded_path = hmm.viterbi(obs)

   # visualize the decoded state sequence
   from matplotlib.pyplot import figure, show
   fa = figure()
   plt.view_viterbi(fa.add_subplot(1, 1, 1), [obs], [decoded_path], hmm.O.mu, seq=0)
   fa.tight_layout()
   show()

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

sequence_modelling-0.1.6.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sequence_modelling-0.1.6-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file sequence_modelling-0.1.6.tar.gz.

File metadata

  • Download URL: sequence_modelling-0.1.6.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.16 Linux/6.2.0-1015-azure

File hashes

Hashes for sequence_modelling-0.1.6.tar.gz
Algorithm Hash digest
SHA256 63cc7761351f137bc6b9108aaa3181ddb3f1bc24b0edb174d7a1a693ce20d54c
MD5 e87fd4f149b7752eabb43196d6c9b6b1
BLAKE2b-256 66dd51e5ae3a1a171f9072d20bffb6ff5d52f614b39c5fb2bd60e641a01c81b4

See more details on using hashes here.

File details

Details for the file sequence_modelling-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: sequence_modelling-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.16 Linux/6.2.0-1015-azure

File hashes

Hashes for sequence_modelling-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2b6daabc6788a455232a11b29630c21f4eb382cdbc183ced0210190b487e5d24
MD5 1ae82b49945887389fe26acf470240a6
BLAKE2b-256 d54337b17cd56dda5a6f159e5b5f331c2c5cbadbd9d2dcaaa13215ebf34c2b8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page