{ } Raw JSON

bundles / scipy latest / scipy / cluster / hierarchy / is_isomorphic

function

scipy.cluster.hierarchy:is_isomorphic

source: /scipy/cluster/hierarchy.py :3813

Signature

def   is_isomorphic ( T1 T2 )

Summary

Determine if two different cluster assignments are equivalent.

Parameters

T1 : array_like

An assignment of singleton cluster ids to flat cluster ids.

T2 : array_like

An assignment of singleton cluster ids to flat cluster ids.

Returns

b : bool

Whether the flat cluster assignments T1 and T2 are equivalent.

Notes

Array API Standard Support

is_isomorphic has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

====================  ====================  ====================
Library               CPU                   GPU
====================  ====================  ====================
NumPy                 ✅                     n/a                 
CuPy                  n/a                   ✅                   
PyTorch               ✅                     ✅                   
JAX                   ✅                     ✅                   
Dask                  ✅                     n/a                 
====================  ====================  ====================

See dev-arrayapi for more information.

Examples

from scipy.cluster.hierarchy import fcluster, is_isomorphic
from scipy.cluster.hierarchy import single, complete
from scipy.spatial.distance import pdist
Two flat cluster assignments can be isomorphic if they represent the same cluster assignment, with different labels. For example, we can use the `scipy.cluster.hierarchy.single` method and flatten the output to four clusters:
X = [[0, 0], [0, 1], [1, 0],
     [0, 4], [0, 3], [1, 4],
     [4, 0], [3, 0], [4, 1],
     [4, 4], [3, 4], [4, 3]]
Z = single(pdist(X))
T = fcluster(Z, 1, criterion='distance')
T
We can then do the same using the `scipy.cluster.hierarchy.complete`: method:
Z = complete(pdist(X))
T_ = fcluster(Z, 1.5, criterion='distance')
T_
As we can see, in both cases we obtain four clusters and all the data points are distributed in the same way - the only thing that changes are the flat cluster labels (3 => 1, 4 =>2, 2 =>3 and 4 =>1), so both cluster assignments are isomorphic:
is_isomorphic(T, T_)

See also

fcluster

for the creation of flat cluster assignments.

linkage

for a description of what a linkage matrix is.

Aliases

  • scipy.cluster.hierarchy.is_isomorphic

Referenced by

This package