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 \(\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 \(v_1\) and \(v_5\) is \(1/3\cdot1/2=0.167\), as in the paper.

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))
       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.   ]]
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()
Jaccard similarity, transitive similarity, HAT-VIS drawing

Total running time of the script: (0 minutes 0.261 seconds)

Gallery generated by Sphinx-Gallery