.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_topology/plot_02_trn.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_02_topology_plot_02_trn.py: Topology representing networks ============================== A topology representing network adds competitive Hebbian learning to neural gas: whenever a sample is drawn, its two nearest nodes are linked. Links that are not refreshed for a while die. The graph that survives connects nodes whose Voronoi cells meet *inside* the data, so it captures the topology of the manifold, here a 2-D sheet bent into an S and a rolled-up swiss roll. More nodes give a finer approximation. .. GENERATED FROM PYTHON SOURCE LINES 12-35 .. image-sg:: /auto_examples/02_topology/images/sphx_glr_plot_02_trn_001.png :alt: TRN of the S curve, n = 100 (208 edges), TRN of the S curve, n = 200 (392 edges), TRN of the swiss roll, n = 200 (390 edges) :srcset: /auto_examples/02_topology/images/sphx_glr_plot_02_trn_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt from graphclust import TopologyRepresentingNetwork from graphclust.datasets import make_s_curve, make_swiss_roll from graphclust.plotting import plot_graph S, _ = make_s_curve(2000, random_state=0) R, _ = make_swiss_roll(2000, random_state=0) fig = plt.figure(figsize=(12, 4)) for i, (X, n, name) in enumerate([(S, 100, "S curve"), (S, 200, "S curve"), (R, 200, "swiss roll")]): # [snippet:trn] trn = TopologyRepresentingNetwork(n_nodes=n, random_state=0).fit(X) # [/snippet:trn] ax = fig.add_subplot(1, 3, i + 1, projection="3d") plot_graph(trn.nodes_, trn.adjacency_, ax=ax, node_size=6, lw=0.6) ax.set_title(f"TRN of the {name}, n = {n} ({trn.n_edges_} edges)", fontsize=10) ax.view_init(10, -70) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.022 seconds) .. _sphx_glr_download_auto_examples_02_topology_plot_02_trn.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/02_topology/plot_02_trn.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_trn.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_trn.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_trn.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_