Representations: PAA, PLA, SAX, episodes#

Four ways to summarize a noisy signal: piecewise aggregate and piecewise linear approximations, the symbolic SAX word and the qualitative episodes of trend analysis (Cheung and Stephanopoulos, 1990; Balaskó et al., 2007).

import matplotlib.pyplot as plt
import numpy as np

from mvtsa import representation as rp
from mvtsa import viz

rng = np.random.default_rng(1)
t = np.linspace(0, 4 * np.pi, 400)
x = np.sin(t) + 0.4 * np.sin(3.1 * t) + 0.05 * rng.normal(size=t.size)

Piecewise linear approximation#

p = rp.pla(x, n_segments=12)
print("slope angles (degrees):", np.degrees(p.angles[:, 0]).round(0))
viz.plot_pla(x, p)
plot 02 representations
slope angles (degrees): [ 3.  0. -4.  0. -1.  3. -0.  1. -3.  1. -1.  4.]

<Axes: xlabel='time'>

SAX#

print("SAX word:", "".join(rp.sax(x, n_segments=16, alphabet_size=5)))
viz.plot_sax(x, 16, 5)
plot 02 representations
SAX word: deedaaabededabab

<Axes: xlabel='time'>

Qualitative episodes#

eps = rp.triangular_episodes(x, sigma=6)
print("episodes:", rp.episode_string(eps))
viz.plot_episodes(x, eps, smooth=6)
plot 02 representations
episodes: DABCDABCDABCDABCDABCDABCDA

<Axes: xlabel='time'>

Parameter study: the smoothing of the episodes#

for s in (2, 6, 15, 30):
    print(
        f"sigma={s:2d}:", rp.episode_string(rp.triangular_episodes(x, sigma=s))
    )
plt.show()
sigma= 2: DACBCDABCBCADADBCDABCDABCADABCDA
sigma= 6: DABCDABCDABCDABCDABCDABCDA
sigma=15: DAGFGDABCBCDADABCBCDA
sigma=30: EABCDABFCDA

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

Gallery generated by Sphinx-Gallery