.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_basics/plot_02_representations.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_01_basics_plot_02_representations.py: 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). .. GENERATED FROM PYTHON SOURCE LINES 9-20 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 21-23 Piecewise linear approximation ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: Python p = rp.pla(x, n_segments=12) print("slope angles (degrees):", np.degrees(p.angles[:, 0]).round(0)) viz.plot_pla(x, p) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_001.png :alt: plot 02 representations :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none slope angles (degrees): [ 3. 0. -4. 0. -1. 3. -0. 1. -3. 1. -1. 4.] .. GENERATED FROM PYTHON SOURCE LINES 28-30 SAX --- .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python print("SAX word:", "".join(rp.sax(x, n_segments=16, alphabet_size=5))) viz.plot_sax(x, 16, 5) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_002.png :alt: plot 02 representations :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none SAX word: deedaaabededabab .. GENERATED FROM PYTHON SOURCE LINES 34-36 Qualitative episodes -------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-40 .. code-block:: Python eps = rp.triangular_episodes(x, sigma=6) print("episodes:", rp.episode_string(eps)) viz.plot_episodes(x, eps, smooth=6) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_003.png :alt: plot 02 representations :srcset: /auto_examples/01_basics/images/sphx_glr_plot_02_representations_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none episodes: DABCDABCDABCDABCDABCDABCDA .. GENERATED FROM PYTHON SOURCE LINES 41-43 Parameter study: the smoothing of the episodes ---------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 43-48 .. code-block:: Python for s in (2, 6, 15, 30): print( f"sigma={s:2d}:", rp.episode_string(rp.triangular_episodes(x, sigma=s)) ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none sigma= 2: DACBCDABCBCADADBCDABCDABCADABCDA sigma= 6: DABCDABCDABCDABCDABCDABCDA sigma=15: DAGFGDABCBCDADABCBCDA sigma=30: EABCDABFCDA .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.164 seconds) .. _sphx_glr_download_auto_examples_01_basics_plot_02_representations.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/mvtsa/main?urlpath=lab/tree/notebooks/auto_examples/01_basics/plot_02_representations.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_representations.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_representations.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_representations.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_