.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_representations/plot_02_projection_loss.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_02_projection_loss.py: What the clique expansion forgets ================================= Two different hypergraphs can have the same clique expansion: a single three-vertex hyperedge and a triangle of three pairwise hyperedges both project to the same triangle graph. The star expansion (bipartite graph) and the incidence matrix keep the difference; conformality tells whether a hypergraph can be recovered from its clique expansion. .. GENERATED FROM PYTHON SOURCE LINES 13-28 .. code-block:: Python import matplotlib.pyplot as plt import networkx as nx import hatvis as hv from hatvis.plotting import draw_bipartite, draw_clique, draw_hypergraph # [snippet:compare] H1 = hv.Hypergraph({"group": ["a", "b", "c"]}, name="one 3-way interaction") H2 = hv.Hypergraph({"ab": ["a", "b"], "bc": ["b", "c"], "ac": ["a", "c"]}, name="three pairwise interactions") G1, G2 = hv.clique_expansion(H1), hv.clique_expansion(H2) print("same clique expansion:", set(map(frozenset, G1.edges())) == set(map(frozenset, G2.edges()))) print("same star expansion: ", nx.is_isomorphic(hv.star_expansion(H1), hv.star_expansion(H2))) print("conformal:", hv.problems.is_conformal(H1), hv.problems.is_conformal(H2)) # [/snippet:compare] .. rst-class:: sphx-glr-script-out .. code-block:: none same clique expansion: True same star expansion: False conformal: True False .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python pos = {"a": (0, 0), "b": (1, 0), "c": (0.5, 0.85)} fig, axes = plt.subplots(2, 3, figsize=(11, 6.5)) for row, H in enumerate((H1, H2)): draw_hypergraph(H, pos=pos, ax=axes[row, 0], legend=False, title=H.name, pad=0.06) draw_clique(H, pos=pos, ax=axes[row, 1], title="clique expansion") draw_bipartite(H, ax=axes[row, 2], title="star expansion", random_state=1) plt.tight_layout() .. image-sg:: /auto_examples/01_representations/images/sphx_glr_plot_02_projection_loss_001.png :alt: one 3-way interaction, clique expansion, star expansion, three pairwise interactions, clique expansion, star expansion :srcset: /auto_examples/01_representations/images/sphx_glr_plot_02_projection_loss_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.271 seconds) .. _sphx_glr_download_auto_examples_01_representations_plot_02_projection_loss.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_02_projection_loss.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_projection_loss.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_projection_loss.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_projection_loss.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_