.. 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_04_number_of_nodes.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_04_number_of_nodes.py: Number of nodes in TRNMap and the mapping quality ================================================= The most influential parameter of TRNMap is the number of nodes. With too few nodes the node spacing exceeds the gap between the windings of the roll, the competitive Hebbian links bridge the gap, and the map folds; with enough nodes the links stay on the sheet and the roll is unrolled. Trustworthiness and continuity of the node maps, computed with geodesic distances as the reference, quantify the result. .. GENERATED FROM PYTHON SOURCE LINES 12-39 .. image-sg:: /auto_examples/07_topology_maps/images/sphx_glr_plot_04_number_of_nodes_001.png :alt: DP-TRNMap, n = 50 (104 edges), DP-TRNMap, n = 150 (303 edges), DP-TRNMap, n = 400 (629 edges), quality of the node maps :srcset: /auto_examples/07_topology_maps/images/sphx_glr_plot_04_number_of_nodes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none n=50: trustworthiness(5) 0.930, continuity(5) 0.941 n=150: trustworthiness(5) 0.998, continuity(5) 0.998 n=400: trustworthiness(5) 0.998, continuity(5) 0.999 | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from graphclust import TRNMap, metrics from graphclust.datasets import make_swiss_roll from graphclust.plotting import plot_graph, plot_quality_curves X, t = make_swiss_roll(2000, random_state=0) ks = np.arange(1, 21) fig, axes = plt.subplots(1, 4, figsize=(15, 3.6)) T, C = {}, {} for ax, n in zip(axes[:3], [50, 150, 400]): # [snippet:nodes] tm = TRNMap(n_nodes=n, random_state=0).fit(X) Tn, Cn = metrics.trustworthiness_continuity(tm.dist_matrix_, tm.embedding_, ks, precomputed=True) # [/snippet:nodes] T[f"trust., n = {n}"], C[f"cont., n = {n}"] = Tn, Cn owner = tm.trn_.labels_ t_node = np.array([t[owner == i].mean() if (owner == i).any() else np.nan for i in range(n)]) plot_graph(tm.embedding_, tm.adjacency_, ax=ax, node_size=0, lw=0.5, title=f"DP-TRNMap, n = {n} ({tm.trn_.n_edges_} edges)") ax.scatter(*tm.embedding_.T, c=t_node, cmap="viridis", s=10, zorder=3) ax.set_xticks([]) ax.set_yticks([]) print(f"n={n}: trustworthiness(5) {Tn[4]:.3f}, continuity(5) {Cn[4]:.3f}") plot_quality_curves({**T, **C}, k=ks, ax=axes[3], title="quality of the node maps") plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.664 seconds) .. _sphx_glr_download_auto_examples_07_topology_maps_plot_04_number_of_nodes.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_04_number_of_nodes.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_number_of_nodes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_number_of_nodes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_number_of_nodes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_