.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/08_higher_order/plot_29_simpliciality.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_08_higher_order_plot_29_simpliciality.py: Simpliciality and nestedness: hypergraph or simplicial complex? =============================================================== Simpliciality (Landry, Young and Eikmeier 2024) measures how close a hypergraph is to a simplicial complex, in which every subset of a hyperedge is itself a hyperedge. A simplicial complex, a random hypergraph and a hypergraph of frequent itemsets (downward closed by construction) are compared; node motifs of order three show the same contrast at the local level. .. GENERATED FROM PYTHON SOURCE LINES 14-34 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv T = hv.datasets.make_news_transactions(150, random_state=0) cases = { "simplicial complex": hv.representations.simplicial_closure(hv.models.uniform_random(12, 8, 4, random_state=0)), "random hypergraph": hv.models.random_hypergraph(30, [2, 3, 4] * 30, random_state=0), "frequent itemsets": hv.itemset_hypergraph(hv.frequent_itemsets(T, 0.05), min_size=2), "news articles": T, } # [snippet:simpliciality] table = pd.DataFrame({name: pd.concat([hv.simpliciality(H, max_size=12), hv.metrics.nestedness(H)]) for name, H in cases.items()}).T # [/snippet:simpliciality] print(table[["simplicial fraction", "edit simpliciality", "face edit simpliciality", "included fraction"]].round(3).to_string()) motifs = pd.DataFrame({name: hv.motifs.node_motifs(H) for name, H in cases.items()}).T print(motifs.to_string()) .. rst-class:: sphx-glr-script-out .. code-block:: none simplicial fraction edit simpliciality face edit simpliciality included fraction simplicial complex 1.000 1.000 1.000 0.906 random hypergraph 0.000 0.219 0.018 0.111 frequent itemsets 1.000 1.000 1.000 0.875 news articles 0.054 0.052 0.162 0.829 open wedge triangle 3-hyperedge 3-hyperedge + 1 pair 3-hyperedge + 2 pairs simplex (3-hyperedge + 3 pairs) simplicial complex 66 10 0 0 0 31 random hypergraph 56 0 30 0 0 0 frequent itemsets 0 1 0 0 0 23 news articles 0 2 3 29 6 13 .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: Python fig, ax = plt.subplots(figsize=(7.5, 3.8)) table[["simplicial fraction", "edit simpliciality", "face edit simpliciality"]].plot.bar( ax=ax, rot=0, color=hv.plotting.PALETTE[:3]) ax.set_ylim(0, 1.05) ax.legend(frameon=False, fontsize=8) plt.tight_layout() .. image-sg:: /auto_examples/08_higher_order/images/sphx_glr_plot_29_simpliciality_001.png :alt: plot 29 simpliciality :srcset: /auto_examples/08_higher_order/images/sphx_glr_plot_29_simpliciality_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.204 seconds) .. _sphx_glr_download_auto_examples_08_higher_order_plot_29_simpliciality.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/08_higher_order/plot_29_simpliciality.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_29_simpliciality.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_29_simpliciality.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_29_simpliciality.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_