.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/09_visualization/plot_03_recurrence_images.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_09_visualization_plot_03_recurrence_images.py: Series as images and networks ============================= Recurrence plots (Eckmann et al., 1987) show when a trajectory returns to earlier states; their texture reveals periodicity, drift and regime changes. Gramian angular and Markov transition fields (Wang and Oates, 2015) encode a series as an image for image-based learning, and the ordinal partition network (Small, 2013) describes the transitions between ordinal patterns. .. GENERATED FROM PYTHON SOURCE LINES 12-25 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mvtsa import representation as rp from mvtsa import viz t = np.arange(600) rng = np.random.default_rng(0) x = np.r_[ np.sin(2 * np.pi * t[:300] / 30), np.cumsum(rng.normal(0, 0.15, 300)) ] + 0.05 * rng.normal(size=600) .. GENERATED FROM PYTHON SOURCE LINES 26-28 Recurrence plot of a periodic and a random-walk regime ------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 28-42 .. code-block:: Python R = rp.recurrence_plot(x, dim=3, tau=5, percentage=10) G = rp.recurrence_network(x, dim=3, tau=5) print( "recurrence rate:", R.mean().round(3), "| network:", { k: round(v, 3) for k, v in rp.graph_features(G).items() if k in ("mean_degree", "clustering") }, ) viz.plot_recurrence(R, title="recurrence plot (10 % recurrence rate)") .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_03_recurrence_images_001.png :alt: recurrence plot (10 % recurrence rate) :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_03_recurrence_images_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none recurrence rate: 0.1 | network: {'mean_degree': 58.902, 'clustering': 0.676} .. GENERATED FROM PYTHON SOURCE LINES 43-45 Gramian angular and Markov transition fields -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 45-53 .. code-block:: Python gaf = rp.gramian_angular_field(x[:300], n_bins=100) mtf = rp.markov_transition_field(x[:300], n_states=8, n_bins=100) fig, axes = plt.subplots(1, 2, figsize=(8, 3.8)) axes[0].imshow(gaf, origin="lower", cmap="RdBu_r") axes[0].set_title("Gramian angular summation field") axes[1].imshow(mtf, origin="lower", cmap="viridis") axes[1].set_title("Markov transition field") .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_03_recurrence_images_002.png :alt: Gramian angular summation field, Markov transition field :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_03_recurrence_images_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Markov transition field') .. GENERATED FROM PYTHON SOURCE LINES 54-56 Ordinal partition networks -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 56-63 .. code-block:: Python for name, seg in [("periodic", x[:300]), ("random walk", x[300:])]: N = rp.ordinal_partition_network(seg, order=4, delay=3) print( f"{name:12s}: {N.number_of_nodes()} ordinal patterns, {N.number_of_edges()} transitions, " f"permutation entropy {rp.permutation_entropy(seg, order=4, delay=3):.3f}" ) plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none periodic : 14 ordinal patterns, 30 transitions, permutation entropy 0.633 random walk : 24 ordinal patterns, 147 transitions, permutation entropy 0.910 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.377 seconds) .. _sphx_glr_download_auto_examples_09_visualization_plot_03_recurrence_images.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/09_visualization/plot_03_recurrence_images.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_recurrence_images.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_recurrence_images.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_recurrence_images.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_