Skip to main content
Ctrl+K

mvtsa

  • Installation
  • Example gallery
  • API reference
  • Method lineage
  • The book
    • Citing
    • Changelog
    • All textbooks
  • GitHub
  • Installation
  • Example gallery
  • API reference
  • Method lineage
  • The book
  • Citing
  • Changelog
  • All textbooks
  • GitHub

Section Navigation

  • First steps: series, segmentations, representations, PCA models
    • First steps: segment, look, evaluate
    • Representations: PAA, PLA, SAX, episodes
    • PCA models: T², Q and similarity factors
  • Cost-based segmentation: costs, search strategies, number of segments
    • Costs and search strategies
    • The merge hierarchy: segmentogram and persistence
    • How many segments?
  • Latent-variable segmentation: PCA, dynamic PCA, recursive PCA, fuzzy and Fisher segmentation
    • PCA segmentation with the T² and Q statistics
    • Dynamic PCA segmentation
    • On-line segmentation with recursive PCA
    • Fuzzy segmentation with the modified Gath–Geva algorithm
    • Informative segments for parameter estimation (MMA polymerization)
    • Operating ranges of an energy indicator
  • Probabilistic, profile-based and state-based segmentation
    • Bayesian on-line change point detection
    • Recurring operating states
    • Shape changes: ClaSP and FLUSS
    • Predictive homogeneity with any scikit-learn model
    • Consensus of segmentations
    • Segmentation of a data stream
  • Elastic similarity: DTW and its relatives
    • Dynamic time warping and global constraints
    • A family of elastic measures on Cylinder–Bell–Funnel
    • Soft-DTW: a differentiable alignment and its uncertainty
    • Diagnosing and tuning warping
  • Correlation-based and segment-level warping
    • Correlation-based dynamic time warping
    • When the information is in the correlation structure
    • Process-dynamics-aware warping: DPCA-CBDTW
    • Real data: Japanese vowels and Riemannian local distances
    • Piecewise linear warping: MPLA, SPLA and MDPLA
    • A multivariate mixed segment distance
    • Comparing qualitative trends: episode alignment
  • Clustering time series, segments and trajectories
    • Partitional clustering: k-means, k-Shape, k-medoids
    • Hierarchical clustering and distance maps
    • Clustering multivariate recordings: BasicMotions
    • Clustering segments: recurring patterns across series
    • Objects that move together: trajectory clustering
  • Evaluation, validation and benchmarking
    • Measuring segmentation quality
    • Is the segmentation stable?
    • Benchmarking segmenters with statistical tests
    • Tuning segmenter parameters
  • Visualization and interpretation
    • A one-page segmentation report
    • Six-sigma visibility graphs
    • Series as images and networks
    • Looking inside alignments and collections
  • Reproducible analyses and model operations
    • From analysis to a deployable model
    • Monitoring a deployed model for drift
    • Experiment tracking and model cards
  • Case studies
    • Grade transitions of a polymerization reactor
    • Operating regions of a pH neutralization process
    • Explaining operating regimes
  • Example gallery
  • Correlation-based and segment-level warping
  • Comparing qualitative trends: episode alignment

Note

Go to the end to download the full example code or to run this example in your browser via Binder.

Comparing qualitative trends: episode alignment#

Balaskó, Bankó and Abonyi (2007) describe a signal by its sequence of triangular episodes (concave/convex increase and decrease, steady and linear parts) and compare two signals by aligning their episode strings with the Needleman–Wunsch algorithm and a primitive substitution table. Weighting the episodes by their size makes small wiggles count less. The alignment works on a handful of symbols, so it is fast and insensitive to the time scale.

import matplotlib.pyplot as plt
import numpy as np

from mvtsa import representation as rp
from mvtsa import viz
from mvtsa import warping as wp

t = np.linspace(0, 1, 300)
rng = np.random.default_rng(4)
base = np.tanh(8 * (t - 0.3)) - 0.6 * np.exp(-(((t - 0.75) / 0.07) ** 2))
signals = {
    "reference": base,
    "slower and scaled": 2.0 * np.interp(t**1.3, t, base) + 1,
    "noisy": base + 0.04 * rng.normal(size=300),
    "different": -base,
}

Episode strings#

eps = {k: rp.triangular_episodes(v, sigma=8) for k, v in signals.items()}
for k, e in eps.items():
    print(f"{k:18s} {rp.episode_string(e)}")
viz.plot_episodes(signals["noisy"], eps["noisy"], smooth=8)
plot 07 episodes
reference          DEAGBCDAG
slower and scaled  GEDEAGBCDAG
noisy              EDABCDAED
different          BFCGDABCG

<Axes: xlabel='time'>

Alignment scores#

for k in ("slower and scaled", "noisy", "different"):
    score, pairs = wp.align_episodes(eps["reference"], eps[k])
    print(
        f"reference vs {k:18s}: score {score:5.2f} / 10, "
        f"episode DTW {wp.episode_dtw(eps['reference'], eps[k]):.3f}"
    )
reference vs slower and scaled : score  9.47 / 10, episode DTW 6.321
reference vs noisy             : score  7.94 / 10, episode DTW 8.603
reference vs different         : score  5.14 / 10, episode DTW 11.500

Parameter study: smoothing before the episode extraction#

for s in (2, 8, 20):
    e_ref = rp.triangular_episodes(signals["reference"], sigma=s)
    e_noisy = rp.triangular_episodes(signals["noisy"], sigma=s)
    print(
        f"sigma {s:2d}: {len(e_noisy):3d} episodes, "
        f"score {wp.align_episodes(e_ref, e_noisy)[0]:.2f}"
    )
plt.show()
sigma  2:  57 episodes, score 7.54
sigma  8:   9 episodes, score 7.94
sigma 20:   9 episodes, score 9.98

Total running time of the script: (0 minutes 0.175 seconds)

Launch binder

Download Jupyter notebook: plot_07_episodes.ipynb

Download Python source code: plot_07_episodes.py

Download zipped: plot_07_episodes.zip

Gallery generated by Sphinx-Gallery

previous

A multivariate mixed segment distance

next

Clustering time series, segments and trajectories

On this page
  • Episode strings
  • Alignment scores
  • Parameter study: smoothing before the episode extraction
Show Source

© Copyright 2026, János Abonyi.

Created using Sphinx 9.1.1.