Skip to main content

Discovering variable-length motif sets in multivariate time series using time warping

Project description

LoCoMotif: Discovering time-warped motifs in time series

This repository contains the implementation of the time series motif discovery (TSMD) method called LoCoMotif. LoCoMotif is a novel TSMD method that stands out from existing methods as it able to discover motifs that have different lengths (variable-length motifs), exhibit slight temporal differences (time-warped motifs), and span multiple dimensions (multivariate motifs). LoCoMotif was proposed in this publication.

🚂 Installation

The easiest way to install is to use pip.

Install using pip

TODO

You can also install from source.

Build from source

First, clone the repository:

git clone https://github.com/ML-KULeuven/locomotif.git

Then, navigate into the directory and build the package from source:

pip install .

🚂 Usage

A time series is representated as 2d numpy array of shape (n, d) where n is the length of the time series and d the number of dimensions:

f = open(os.path.join("..", "examples", "datasets", "mitdb_patient214.csv"))
ts = np.array([line.split(',') for line in f.readlines()], dtype=np.double)

print(ts.shape)
>>> (3600, 2)

To apply LoCoMotif to the time series, simply import the locomotif module and call the apply_locomotif method with suitable parameter values. Note that, we highly advise you to first z-normalize the time series.

import locomotif.locomotif as locomotif 
ts = (ts - np.mean(ts, axis=None)) / np.std(ts, axis=None)
motif_sets = locomotif.apply_locomotif(ts, l_min=216, l_max=360, rho=0.6)

The parameters l_min and l_max respectively represent the minimum and maximum motif length of the representative of a motif set. The parameter rho determines the ''strictness'' of the LoCoMotif method; or in other words, how similar the subsequences in a motif set are expected to be. The best value of rho depends heavily on the application; however, in most of our experiments, a value between 0.6 and 0.8 always works relatively well.
Optionally, we allow you to choose how the allowed overlap between motifs through the overlap parameter (which lies between 0.0 and 0.5), the number of motif sets to be discovered through the nb parameter (by default, nb=None and LoCoMotif finds all motifs), and whether to use time warping or not through the warping parameter (either True or False)

The result of LoCoMotif is a list of (candidate, motif_set) tuples, where each candidate is the representative subsequence (the most "central" subsequence) of the corresponding motif_set. Each candidate is a tuple of two integers (b, e) representing the start- and endpoint of the corresponding time segment, while each motif_set is a list of such tuples.

print(motif_sets)
>>> [((2666, 2932), [(2666, 2932), (1892, 2137), (1038, 1333), (3168, 3490), (2334, 2666), (628, 1036), (1589, 1893), (1, 261)]), ((1333, 1565), [(1333, 1565), (2137, 2333), (2932, 3162)])]

We also include a visualization module, visualize, to plot the time series together with the found motifs:

import locomotif.visualize as visualize
import matplotlib.pyplot as plt

fig, ax = visualize.plot_motif_sets(ts, motif_sets)
plt.show()

More examples can be found in this folder.

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

dtai_locomotif-0.1.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

dtai_locomotif-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file dtai_locomotif-0.1.0.tar.gz.

File metadata

  • Download URL: dtai_locomotif-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for dtai_locomotif-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c91ea06f379e5fd0653d1f33aabba0186117995f74d0ef0dbfae2ff874c25d0
MD5 3b0d519918409eb4d4165583879c133e
BLAKE2b-256 d3c79f1ca1de96ed55d254eb1396e64240c566f87e8c41aa9555773eb4e035db

See more details on using hashes here.

File details

Details for the file dtai_locomotif-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dtai_locomotif-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for dtai_locomotif-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc9985793a329a06f0e295898156d10156d74d35ac3da76df123d3157bfd9b70
MD5 e684290daae056dd26c25eea00eab950
BLAKE2b-256 0098029ebf862c1e1a9e7007cfd2e8ff897a83201352920336d65a6c2d568edf

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