.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_topology/plot_03_growing_networks.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_03_growing_networks.py: Growing networks: GNG, GWR, DTRN and WINN ========================================= Neural gas and the TRN need the number of nodes in advance. Growing networks start small and insert nodes where the representation is poor: * growing neural gas (GNG) inserts a node every λ steps near the node with the largest accumulated error; * grow when required (GWR) inserts a node as soon as the winner of a sample is far away and already well trained; * the dynamic TRN (DTRN) creates a node whenever a sample fails a vigilance test; * the weighted incremental network (WINN) grows like GNG and also counts how often nodes and edges are used, which estimates the local density. .. GENERATED FROM PYTHON SOURCE LINES 17-53 .. image-sg:: /auto_examples/02_topology/images/sphx_glr_plot_03_growing_networks_001.png :alt: GNG: 200 nodes, 381 edges, GWR: 140 nodes, 305 edges, DTRN: 325 nodes, 452 edges, WINN: 189 nodes, 250 edges :srcset: /auto_examples/02_topology/images/sphx_glr_plot_03_growing_networks_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none GNG: 200 nodes, quantization error 0.0027 GWR: 140 nodes, quantization error 0.0066 DTRN: 325 nodes, quantization error 0.0019 WINN: 189 nodes, quantization error 0.0027 | .. code-block:: Python import matplotlib.pyplot as plt from graphclust import ( DynamicTopologyRepresentingNetwork, GrowingNeuralGas, GrowWhenRequired, WeightedIncrementalNetwork, ) from graphclust.datasets import make_swiss_roll, minmax_scale from graphclust.plotting import plot_graph X = minmax_scale(make_swiss_roll(2000, random_state=0)[0]) # [snippet:growing] models = { "GNG": GrowingNeuralGas(max_nodes=200, max_age=30, random_state=0), "GWR": GrowWhenRequired(activity_threshold=0.86, n_epochs=3, random_state=0), "DTRN": DynamicTopologyRepresentingNetwork(max_iter=4000, rho=(None, 0.06), max_age=8, random_state=0), "WINN": WeightedIncrementalNetwork(n_nodes=200, max_age=5, random_state=0), } for m in models.values(): m.fit(X) # [/snippet:growing] fig = plt.figure(figsize=(9, 7.5)) for i, (name, m) in enumerate(models.items()): ax = fig.add_subplot(2, 2, i + 1, projection="3d") plot_graph(m.nodes_, m.adjacency_, ax=ax, node_size=5, lw=0.5) ax.set_title(f"{name}: {m.n_nodes_} nodes, {m.n_edges_} edges", fontsize=9) ax.view_init(10, -70) ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) print(f"{name}: {m.n_nodes_} nodes, quantization error {m.quantization_error(X):.4f}") plt.tight_layout() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.484 seconds) .. _sphx_glr_download_auto_examples_02_topology_plot_03_growing_networks.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_03_growing_networks.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_growing_networks.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_growing_networks.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_growing_networks.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_