.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_similarity/plot_14_hatvis_pipeline.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_14_hatvis_pipeline.py: The HAT-VIS pipeline step by step ================================= HAT-VIS computes (1) the weighted Jaccard similarity of the vertices, (2) its max-product transitive closure, (3) the dissimilarity :math:`\boldsymbol{\Delta}=\mathbf{1}-\mathbf{S}` and (4) a classical MDS configuration; hyperedges are drawn as minimum spanning trees of their members. On the five-vertex example the transitive similarity of :math:`v_1` and :math:`v_5` is :math:`1/3\cdot1/2=0.167`, as in the paper. .. GENERATED FROM PYTHON SOURCE LINES 14-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import pandas as pd import hatvis as hv from hatvis.plotting import draw_hatvis H = hv.datasets.hatvis_example() # [snippet:steps] S = hv.vertex_similarity(H) # weighted Jaccard ST = hv.transitive_closure(S, "max-product") # strongest chains Delta = 1 - ST Y = hv.layout.classical_mds(Delta) # 2-D configuration # [/snippet:steps] print(pd.DataFrame(S, H.nodes, H.nodes).round(3)) print(pd.DataFrame(ST, H.nodes, H.nodes).round(3)) print(np.round(Y, 3)) .. rst-class:: sphx-glr-script-out .. code-block:: none v1 v2 v3 v4 v5 v1 1.000 1.000 0.333 0.333 0.0 v2 1.000 1.000 0.333 0.333 0.0 v3 0.333 0.333 1.000 0.333 0.5 v4 0.333 0.333 0.333 1.000 0.5 v5 0.000 0.000 0.500 0.500 1.0 v1 v2 v3 v4 v5 v1 1.000 1.000 0.333 0.333 0.167 v2 1.000 1.000 0.333 0.333 0.167 v3 0.333 0.333 1.000 0.333 0.500 v4 0.333 0.333 0.333 1.000 0.500 v5 0.167 0.167 0.500 0.500 1.000 [[-0.389 0. ] [-0.389 0. ] [ 0.17 -0.333] [ 0.17 0.333] [ 0.437 0. ]] .. GENERATED FROM PYTHON SOURCE LINES 33-45 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(13, 4)) for ax, M, t in ((axes[0], S, "Jaccard similarity"), (axes[1], ST, "transitive similarity")): im = ax.imshow(M, cmap=hv.plotting.matrix.BRAND_CMAP, vmin=0, vmax=1) ax.set_xticks(range(5), H.nodes) ax.set_yticks(range(5), H.nodes) for i in range(5): for j in range(5): ax.text(j, i, f"{M[i, j]:.2f}", ha="center", va="center", fontsize=8, color="white" if M[i, j] > 0.6 else "black") ax.set_title(t) draw_hatvis(H, ax=axes[2], title="HAT-VIS drawing", node_names=None) plt.tight_layout() .. image-sg:: /auto_examples/04_similarity/images/sphx_glr_plot_14_hatvis_pipeline_001.png :alt: Jaccard similarity, transitive similarity, HAT-VIS drawing :srcset: /auto_examples/04_similarity/images/sphx_glr_plot_14_hatvis_pipeline_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.261 seconds) .. _sphx_glr_download_auto_examples_04_similarity_plot_14_hatvis_pipeline.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_14_hatvis_pipeline.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_14_hatvis_pipeline.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_14_hatvis_pipeline.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_14_hatvis_pipeline.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_