.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_similarity/plot_16_membership_layout.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_04_similarity_plot_16_membership_layout.py: Membership-aware layout: similarity with fewer intrusions ========================================================= The similarity layout gives meaningful positions but hulls drawn around hyperedges often contain foreign vertices. The membership-aware layout of hatvis alternates a stress-majorization step towards the similarity distances with a projection that moves non-members out of the hyperedge discs, and keeps the iterate with the fewest intrusions. It is compared with classical MDS and Sammon mapping on the whole wire harness space and on a 14-activity part of production line 1. .. GENERATED FROM PYTHON SOURCE LINES 15-41 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv from hatvis.plotting import draw_hypergraph W = hv.datasets.load_wire_harness() part = W.restrict_edges([e for e in W.edges if W.edge_data.loc[e, "line"] == 1 and W.edge_data.loc[e, "type"] in ("t16", "t19", "t24", "t2", "t11")]).remove_isolated() def compare(H): # [snippet:compare] layouts = {"classical MDS": hv.layout_similarity(H, jitter=0.01, random_state=0), "Sammon mapping": hv.layout_similarity(H, method="sammon"), "membership-aware": hv.layout_membership(H, random_state=0)} quality = pd.DataFrame({name: hv.layout_quality(H, pos) for name, pos in layouts.items()}).T # [/snippet:compare] return layouts, quality layouts_w, q_w = compare(W) layouts_p, q_p = compare(part) print("whole space (31 resources, 70 activities):\n", q_w.round(3).to_string()) print("line-1 part:\n", q_p.round(3).to_string()) .. rst-class:: sphx-glr-script-out .. code-block:: none whole space (31 resources, 70 activities): stress intrusions hyperedges with intrusions mean hull area classical MDS 0.211 290.0 60.0 0.043 Sammon mapping 0.136 56.0 37.0 0.072 membership-aware 0.182 69.0 27.0 0.064 line-1 part: stress intrusions hyperedges with intrusions mean hull area classical MDS 0.107 23.0 12.0 0.068 Sammon mapping 0.099 6.0 3.0 0.062 membership-aware 0.083 1.0 1.0 0.070 .. GENERATED FROM PYTHON SOURCE LINES 42-47 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(17, 6)) for ax, (name, pos) in zip(axes, layouts_p.items(), strict=False): draw_hypergraph(part, pos=pos, ax=ax, style="smooth", legend=False, pad=0.02, title=f"{name}: {int(q_p.loc[name, 'intrusions'])} intrusions") plt.tight_layout() .. image-sg:: /auto_examples/04_similarity/images/sphx_glr_plot_16_membership_layout_001.png :alt: classical MDS: 23 intrusions, Sammon mapping: 6 intrusions, membership-aware: 1 intrusions :srcset: /auto_examples/04_similarity/images/sphx_glr_plot_16_membership_layout_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.257 seconds) .. _sphx_glr_download_auto_examples_04_similarity_plot_16_membership_layout.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/04_similarity/plot_16_membership_layout.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_16_membership_layout.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_16_membership_layout.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_16_membership_layout.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_