Note
Go to the end to download the full example code or to run this example in your browser via Binder.
VAT and iVAT images#
VAT reorders a dissimilarity matrix in the order in which Prim’s algorithm grows the minimal spanning tree, so samples of one cluster become consecutive and appear as a dark block on the diagonal. iVAT replaces every dissimilarity by the largest edge on the tree path between the two samples (the minimax distance); the blocks become crisp for elongated clusters, where plain VAT shows only faint structure. Minimax distances are single-linkage distances, however, so groups joined by a chain still form one block.

import matplotlib.pyplot as plt
import numpy as np
from graphclust.datasets import make_chainlink, make_curves
from graphclust.plotting import plot_partition, plot_vat
from graphclust.vat import ivat, vat
fig, axes = plt.subplots(2, 3, figsize=(11, 7.4))
for row, (X, y, name) in enumerate([(*make_chainlink(), "ChainLink"), (*make_curves(), "Curves")]):
D = np.linalg.norm(X[:, None] - X[None], axis=-1)
# [snippet:vat]
R, order = vat(D)
R_i, _ = ivat(D)
# [/snippet:vat]
plot_partition(X, y, ax=axes[row, 0], markers=False, title=name)
axes[row, 0].set_xticks([])
axes[row, 0].set_yticks([])
plot_vat(R, ax=axes[row, 1], title="VAT")
plot_vat(R_i, ax=axes[row, 2], title="iVAT")
plt.tight_layout()
Total running time of the script: (0 minutes 0.087 seconds)