.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_topology_maps/plot_02_ovi_gnlp_trnmap.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_07_topology_maps_plot_02_ovi_gnlp_trnmap.py: OVI-NG, GNLP-NG and TRNMap ========================== All three map the nodes of a neural-gas-type network: * OVI-NG adapts node positions online together with the codebook, matching map distances to *Euclidean* codebook distances; the S curve stays folded; * GNLP-NG uses *geodesic* distances on the node graph and unfolds it; * TRNMap builds a topology representing network, connects it, computes geodesic distances and maps them by metric MDS (DP-TRNMap) or non-metric MDS (NP-TRNMap) in one shot, without online iterations. The edges of the learned graphs are drawn in the maps; the nodes are colored by the position along the S of the samples they represent. .. GENERATED FROM PYTHON SOURCE LINES 17-44 .. image-sg:: /auto_examples/07_topology_maps/images/sphx_glr_plot_02_ovi_gnlp_trnmap_001.png :alt: OVI-NG, GNLP-NG, DP-TRNMap, NP-TRNMap :srcset: /auto_examples/07_topology_maps/images/sphx_glr_plot_02_ovi_gnlp_trnmap_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from graphclust import GeodesicNLPNG, OnlineVisualizationNG, TRNMap from graphclust.datasets import make_s_curve from graphclust.plotting import plot_graph X, t = make_s_curve(2000, random_state=0) n = 120 # [snippet:trnmap] ovi = OnlineVisualizationNG(n_nodes=n, random_state=0).fit(X) gnlp = GeodesicNLPNG(n_nodes=n, random_state=0).fit(X) dp = TRNMap(n_nodes=n, mapping="metric", random_state=0).fit(X) np_ = TRNMap(n_nodes=n, mapping="nonmetric", random_state=0).fit(X) # [/snippet:trnmap] fig, axes = plt.subplots(1, 4, figsize=(14, 3.6)) for ax, m, name in [(axes[0], ovi, "OVI-NG"), (axes[1], gnlp, "GNLP-NG"), (axes[2], dp, "DP-TRNMap"), (axes[3], np_, "NP-TRNMap")]: owner = np.argmin(((X[:, None, :] - m.nodes_[None]) ** 2).sum(-1), axis=1) t_node = np.array([t[owner == i].mean() if (owner == i).any() else np.nan for i in range(len(m.nodes_))]) plot_graph(m.embedding_, m.adjacency_, ax=ax, node_size=0, lw=0.5, title=name) ax.scatter(*m.embedding_.T, c=t_node, cmap="viridis", s=16, zorder=3) ax.set_xticks([]) ax.set_yticks([]) plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.791 seconds) .. _sphx_glr_download_auto_examples_07_topology_maps_plot_02_ovi_gnlp_trnmap.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/graphclust/main?urlpath=lab/tree/notebooks/auto_examples/07_topology_maps/plot_02_ovi_gnlp_trnmap.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_ovi_gnlp_trnmap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_ovi_gnlp_trnmap.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_ovi_gnlp_trnmap.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_