.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_structure/plot_20_hypercores.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_05_structure_plot_20_hypercores.py: Hyper-cores =========== The :math:`(k,m)`-hyper-core keeps the vertices that belong to at least :math:`k` hyperedges with at least :math:`m` members inside the core (Mancastroppa et al. 2023). The core numbers for growing :math:`m` and the resulting hyper-coreness reveal a densely interacting nucleus in a synthetic hypergraph with a planted core. .. GENERATED FROM PYTHON SOURCE LINES 13-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd import hatvis as hv rng = np.random.default_rng(0) core = [f"c{i}" for i in range(8)] periph = [f"p{i}" for i in range(40)] edges = [list(rng.choice(core, size=rng.integers(3, 6), replace=False)) for _ in range(25)] edges += [list(rng.choice(core + periph, size=rng.integers(2, 4), replace=False)) for _ in range(60)] H = hv.Hypergraph(edges) # [snippet:cores] cores = pd.DataFrame({f"m={m}": hv.hypercore_numbers(H, m) for m in range(2, 6)}) R = hv.hypercoreness(H) # [/snippet:cores] print(cores.loc[core + periph[:4]]) print("top 8 by hyper-coreness:", list(R.sort_values(ascending=False).index[:8])) .. rst-class:: sphx-glr-script-out .. code-block:: none m=2 m=3 m=4 m=5 c0 14 11 9 4 c1 9 8 7 4 c2 14 11 9 4 c3 14 11 9 4 c4 14 11 9 4 c5 14 11 9 4 c6 14 11 9 4 c7 10 10 7 4 p0 4 2 0 0 p1 1 1 0 0 p2 3 0 0 0 p3 3 1 0 0 top 8 by hyper-coreness: [np.str_('c4'), np.str_('c6'), np.str_('c2'), np.str_('c0'), np.str_('c5'), np.str_('c3'), np.str_('c7'), np.str_('c1')] .. GENERATED FROM PYTHON SOURCE LINES 33-41 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(11, 4.2)) for m in cores.columns: axes[0].plot(range(len(cores)), cores[m].sort_values(ascending=False).to_numpy(), label=m) axes[0].set_xlabel("vertices (sorted)") axes[0].set_ylabel("core number") axes[0].legend(frameon=False) hv.plotting.plot_ranking(R, top=12, ax=axes[1], title="hyper-coreness") plt.tight_layout() .. image-sg:: /auto_examples/05_structure/images/sphx_glr_plot_20_hypercores_001.png :alt: hyper-coreness :srcset: /auto_examples/05_structure/images/sphx_glr_plot_20_hypercores_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.216 seconds) .. _sphx_glr_download_auto_examples_05_structure_plot_20_hypercores.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/05_structure/plot_20_hypercores.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_20_hypercores.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_20_hypercores.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_20_hypercores.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_