.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/09_visualization/plot_04_warping_maps.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_04_warping_maps.py: Looking inside alignments and collections ========================================= Warping paths, the accumulated cost and the uncertainty of an alignment explain *why* two series are similar; maps of a distance matrix show the structure of a whole collection; prototypes summarize the clusters. The example uses GunPoint (two classes of hand movements, UEA & UCR archive). .. GENERATED FROM PYTHON SOURCE LINES 10-23 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mvtsa import pairwise_distances, viz from mvtsa import warping as wp from mvtsa.datasets import load_gunpoint G, y = load_gunpoint() rng = np.random.default_rng(0) idx = rng.choice(len(G), 60, replace=False) G, y = [G[i] for i in idx], y[idx] .. GENERATED FROM PYTHON SOURCE LINES 24-26 An alignment and its uncertainty -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-33 .. code-block:: Python a, b = G[0], G[int(np.flatnonzero(y == y[0])[1])] res = wp.dtw_path(a, b, window=0.1) _, E = wp.soft_dtw_alignment(a, b, gamma=0.05) fig, axes = plt.subplots(1, 2, figsize=(9, 3.4)) viz.plot_alignment(a, b, res.path, every=4, ax=axes[0]) viz.plot_alignment_uncertainty(E, path=res.path, ax=axes[1]) .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_001.png :alt: plot 04 warping maps :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 34-36 The collection: distance matrix, Sammon map and prototypes ---------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 36-45 .. code-block:: Python D = pairwise_distances(G, metric="dtw", window=0.1) viz.plot_distance_matrix(D, y) viz.plot_embedding(D, y, method="sammon") centers = [ wp.dba([G[i] for i in np.flatnonzero(y == k)], n_iter=8, window=0.1) for k in np.unique(y) ] viz.plot_cluster_prototypes(G, y, centers=centers, ncols=2) plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_002.png :alt: plot 04 warping maps :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_003.png :alt: Sammon mapping (stress 0.341) :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_004.png :alt: cluster 1 (n=39), cluster 2 (n=21) :srcset: /auto_examples/09_visualization/images/sphx_glr_plot_04_warping_maps_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/sklearn/manifold/_mds.py:735: FutureWarning: The default value of `init` will change from 'random' to 'classical_mds' in 1.10. To suppress this warning, provide some value of `init`. warnings.warn( /opt/hostedtoolcache/Python/3.12.16/x64/lib/python3.12/site-packages/sklearn/manifold/_mds.py:752: FutureWarning: The `dissimilarity` parameter is deprecated and will be removed in 1.10. Use `metric` instead. warnings.warn( .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.624 seconds) .. _sphx_glr_download_auto_examples_09_visualization_plot_04_warping_maps.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_04_warping_maps.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_warping_maps.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_warping_maps.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_warping_maps.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_