.. 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_30_null_models.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_30_null_models.py: Null models: what is structure and what is chance? ================================================== The configuration model keeps every vertex degree and hyperedge size; the random model keeps only the sizes. Comparing clustering, assortativity, modularity of the best partition and the number of 2-components of the wire harness space with 30 samples of each null model shows which properties are explained by the degree and size sequences alone. .. GENERATED FROM PYTHON SOURCE LINES 13-45 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv H = hv.datasets.load_wire_harness() def stats(G): # [snippet:stats] lab = hv.hypergraph_louvain(G, random_state=0) return {"two-node clustering": hv.metrics.two_node_clustering(G).mean(), "degree assortativity": hv.metrics.degree_assortativity(G), "modularity": hv.modularity(G, lab), "2-components": len(hv.s_connected_components(G, 2))} # [/snippet:stats] obs = stats(H) null = {"configuration": [], "random": []} for k in range(30): null["configuration"].append(stats(hv.models.configuration_model(H, random_state=k))) null["random"].append(stats(hv.models.random_hypergraph(H.n_nodes, H.edge_sizes(), random_state=k, nodes=H.nodes))) rows = {"observed": obs} for name, lst in null.items(): df = pd.DataFrame(lst) rows[f"{name} mean"] = df.mean() rows[f"{name} std"] = df.std() table = pd.DataFrame(rows) print(table.round(3).to_string()) .. rst-class:: sphx-glr-script-out .. code-block:: none observed configuration mean configuration std random mean random std two-node clustering 0.183 0.097 0.004 0.095 0.003 degree assortativity -0.134 -0.079 0.038 -0.047 0.040 modularity 0.419 0.205 0.016 0.242 0.020 2-components 4.000 7.500 2.113 10.000 2.349 .. GENERATED FROM PYTHON SOURCE LINES 46-54 .. code-block:: Python fig, axes = plt.subplots(1, 4, figsize=(14, 3.3)) for ax, key in zip(axes, obs, strict=False): for k, (name, lst) in enumerate(null.items()): ax.hist([d[key] for d in lst], bins=10, alpha=0.6, color=hv.plotting.PALETTE[k + 1], label=name) ax.axvline(obs[key], color=hv.plotting.INK, lw=2, label="observed") ax.set_title(key, fontsize=9) axes[0].legend(frameon=False, fontsize=7) plt.tight_layout() .. image-sg:: /auto_examples/08_higher_order/images/sphx_glr_plot_30_null_models_001.png :alt: two-node clustering, degree assortativity, modularity, 2-components :srcset: /auto_examples/08_higher_order/images/sphx_glr_plot_30_null_models_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.664 seconds) .. _sphx_glr_download_auto_examples_08_higher_order_plot_30_null_models.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_30_null_models.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_30_null_models.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_30_null_models.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_30_null_models.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_