Skip to main content

Series Distance Matrix

This library implements the Series Distance Matrix framework, a flexible component-based framework that bundles various Matrix Profile related techniques. These techniques can be used for (time) series mining and analysis. Some example applications include:

  • motif discovery: finding the best (imperfect) matching subsequence pair in a larger series
  • discord discovery: finding the most dissimilar subsequence in a larger series
  • finding repeating subsequences in one or more series (common and consensus motifs)
  • visualizing series
  • finding changing patterns
  • ...

The Series Distance Matrix framework was designed to integrate the various Matrix Profile variants that were established over the years. It does this by splitting the generation and consumption of the all-pair subsequence distances, putting the focus on the distance matrix itself. This allows for easier and more flexible experiments by freely combining components and eliminates the need to re-implement algorithms to combine techniques in an efficient way.

Following core techniques are implemented:

  • Z-normalized Euclidean distance (including noise elimination)
  • Euclidean distance
  • (Left/Right) Matrix Profile
  • Multidimensional Matrix Profile
  • Contextual Matrix Profile
  • Radius Profile
  • Streaming and batch calculation

Following Matrix Profile related techniques are implemented:

  • Valmod: find the top-1 motif in a series for each subsequence length in a given range
  • Ostinato: find the top-1 (k of n) consensus motif in a collection of series
  • Anytime Ostinato: find the radius profile for a collection of series

Basic Usage

Calculate a standard Matrix Profile using z-normalized Euclidean distance over a single series.

import numpy as np
from distancematrix.generator.znorm_euclidean import ZNormEuclidean
from distancematrix.consumer.matrix_profile_lr import MatrixProfileLR
from distancematrix.calculator import AnytimeCalculator

data = np.random.randn(10000)
m = 100 # Subsequence length

calc = AnytimeCalculator(m, data)
gen_0 = calc.add_generator(0, ZNormEuclidean())
cons_mp = calc.add_consumer([0], MatrixProfileLR())
calc.calculate_columns()

matrix_profile = cons_mp.matrix_profile()

Calculate a Matrix Profile and (common-10) Radius Profile over a single series using Euclidean distance. A combined calculation is more efficients, as it can reuse the calculated distances.

import numpy as np
from distancematrix.generator.euclidean import Euclidean
from distancematrix.consumer.radius_profile import RadiusProfile
from distancematrix.consumer.matrix_profile_lr import MatrixProfileLR
from distancematrix.calculator import AnytimeCalculator

data = np.random.randn(10000)
m = 100 # Subsequence length

calc = AnytimeCalculator(m, data)
gen_0 = calc.add_generator(0, Euclidean()) # Generator 0 works on channel 0
cons_mp = calc.add_consumer([0], MatrixProfileLR()) # Consumer consumes generator 0
cons_rp = calc.add_consumer([0], RadiusProfile(10, m//2)) # Consumer consumes generator 0
calc.calculate_columns()

matrix_profile = cons_mp.matrix_profile()
radius_profile = cons_rp.values

Calculate a partial multidimensional Matrix Profile over two data channels. Partial calculations return approximated results but are significantly faster, they are particularly interesting in interactive workflows, as they can be resumed.

import numpy as np
from distancematrix.generator.znorm_euclidean import ZNormEuclidean
from distancematrix.consumer.multidimensional_matrix_profile_lr import MultidimensionalMatrixProfileLR
from distancematrix.consumer.matrix_profile_lr import MatrixProfileLR
from distancematrix.calculator import AnytimeCalculator

data = np.random.randn(2, 10000)
m = 100 # Subsequence length

calc = AnytimeCalculator(m, data)
gen_0 = calc.add_generator(0, ZNormEuclidean()) # Generator 0 works on channel 0
gen_1 = calc.add_generator(1, ZNormEuclidean()) # Generator 1 works on channel 1
cons_mmp = calc.add_consumer([0, 1], MultidimensionalMatrixProfileLR()) # Consumer consumes generator 0 & 1

# Calculate only 1/4 of all distances: faster, but returns approximated results
calc.calculate_diagonals(partial=0.25)
multidimensional_matrix_profile = cons_mmp.md_matrix_profile()

# Calculate the next quarter, so in total 1/2 of all distances are processed.
calc.calculate_diagonals(partial=0.5)
multidimensional_matrix_profile = cons_mmp.md_matrix_profile()

Documentation

Documentation for the latest version is available online.

Building the documentation locally is done using Sphinx. Navigate to the docs folder, activate the conda environment defined in the environment file, and run:

make html

Installing

Using pip:

pip install seriesdistancematrix

Alternatively, clone this repositor and run:

python setup.py clean build install

For local development (this allows you to edit code without having to reinstall the library):

python setup.py develop

Academic Usage

When using this library for academic purposes, please cite:

@article{series_distance_matrix,
  title = "A generalized matrix profile framework with support for contextual series analysis",
  journal = "Engineering Applications of Artificial Intelligence",
  volume = "90",
  pages = "103487",
  year = "2020",
  issn = "0952-1976",
  doi = "https://doi.org/10.1016/j.engappai.2020.103487",
  url = "http://www.sciencedirect.com/science/article/pii/S0952197620300087",
  author = "De Paepe, Dieter and Vanden Hautte, Sander and Steenwinckel, Bram and De Turck, Filip and Ongenae, Femke and Janssens, Olivier and Van Hoecke, Sofie"
}

Metadata

Release files for seriesdistancematrix 0.3.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 seriesdistancematrix 0.3.1
File Size Uploaded
seriesdistancematrix-0.3.1.tar.gz 37.3 kB Details

Built distribution (wheel)

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

Total release size: 85.2 kB

Release files / seriesdistancematrix-0.3.1.tar.gz

Download URL seriesdistancematrix-0.3.1.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3fa1ba2712c79aa9630a717ab5bebb426180db991c7d2c0712ebaa7148a918c0
BLAKE2b-256 checksum
How to use checksums
1fce35338afadfad8b1870de002e944e151c1022f8e8a8d0a33273d2f1a1158c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / seriesdistancematrix-0.3.1-py3-none-any.whl

Download URL seriesdistancematrix-0.3.1-py3-none-any.whl
Size 47.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5b1c7f5d1296ff0b9b4024a441bb10939010e50cc49d35b2fa8061fce1b3b38
BLAKE2b-256 checksum
How to use checksums
ab8bb75833dcca02fd72a8e4a12be05fcf49c91d09ed0866d806e5e218472bf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

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