.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_representations/plot_03_expansions_and_spectra.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_01_representations_plot_03_expansions_and_spectra.py: Expansions, line graphs and Laplacian spectra ============================================= The same hypergraph seen through four graphs — clique expansion, star expansion, 1-line graph and 2-line graph — and through the spectra of three Laplacians. The example is the cyber-physical production system of the HyperGodot paper: 15 entities and 7 tasks. .. GENERATED FROM PYTHON SOURCE LINES 12-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import hatvis as hv from hatvis.plotting import draw_bipartite, draw_clique, draw_line_graph H = hv.datasets.load_manufacturing_cps() # [snippet:spectra] spectra = {kind: np.sort(np.linalg.eigvalsh(hv.laplacian(H, kind))) for kind in ("normalized", "bolla", "clique")} for kind, ev in spectra.items(): print(f"{kind:>10}: zero eigenvalues = {np.sum(ev < 1e-9)}, largest = {ev[-1]:.3f}") print("algebraic connectivity:", round(hv.spectral.algebraic_connectivity(H), 4)) # [/snippet:spectra] .. rst-class:: sphx-glr-script-out .. code-block:: none normalized: zero eigenvalues = 1, largest = 1.000 bolla: zero eigenvalues = 1, largest = 73.478 clique: zero eigenvalues = 1, largest = 314.041 algebraic connectivity: 0.1009 .. GENERATED FROM PYTHON SOURCE LINES 27-34 .. code-block:: Python fig, axes = plt.subplots(2, 2, figsize=(11, 9)) draw_clique(H, ax=axes[0, 0], title="clique expansion", layout="force") draw_bipartite(H, ax=axes[0, 1], title="star expansion") draw_line_graph(H, s=1, ax=axes[1, 0]) draw_line_graph(H, s=2, ax=axes[1, 1]) plt.tight_layout() .. image-sg:: /auto_examples/01_representations/images/sphx_glr_plot_03_expansions_and_spectra_001.png :alt: clique expansion, star expansion, 1-line graph, 2-line graph :srcset: /auto_examples/01_representations/images/sphx_glr_plot_03_expansions_and_spectra_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: Python fig, ax = plt.subplots(figsize=(6.5, 3.5)) for k, (kind, ev) in enumerate(spectra.items()): ax.plot(ev / ev.max(), "o-", ms=4, label=kind, color=hv.plotting.PALETTE[k]) ax.set_xlabel("index") ax.set_ylabel("eigenvalue / largest") ax.legend(frameon=False) plt.tight_layout() .. image-sg:: /auto_examples/01_representations/images/sphx_glr_plot_03_expansions_and_spectra_002.png :alt: plot 03 expansions and spectra :srcset: /auto_examples/01_representations/images/sphx_glr_plot_03_expansions_and_spectra_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.524 seconds) .. _sphx_glr_download_auto_examples_01_representations_plot_03_expansions_and_spectra.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/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/01_representations/plot_03_expansions_and_spectra.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_expansions_and_spectra.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_expansions_and_spectra.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_expansions_and_spectra.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_