Scipy Interoperability functions
Converts an Higra binary hierarchy to a SciPy linkage matrix. |
|
Converts a SciPy linkage matrix to an Higra binary hierarchy. |
- binary_hierarchy_to_scipy_linkage_matrix(tree, altitudes=None, area=None)[source]
Converts an Higra binary hierarchy to a SciPy linkage matrix.
From SciPy documentation:
An \(n-1\) by 4 matrix \(Z\) is returned. At the \(i\)-th iteration, clusters with indices \(Z[i, 0]\) and \(Z[i, 1]\) are combined to form cluster \(n+i\). A cluster with an index less than \(n\) corresponds to one of the \(n\) original observations. The distance between clusters \(Z[i, 0]\) and \(Z[i, 1]\) is given by \(Z[i, 2]\). The fourth value \(Z[i, 3]\) represents the number of original observations in the newly formed cluster.
If
altitudesis not specified, the value provided byattribute_regular_altitudes()ontreeis used.If
areais not specified, the value provided byattribute_area()ontreeis used.- Parameters:
tree – Input tree
altitudes – Tree nodes altitudes (should be increasing w.r.t tree)
area – Tree nodes area (should be increasing w.r.t tree)
- Returns:
A linkage matrix
- scipy_linkage_matrix_to_binary_hierarchy(linkage_matrix)[source]
Converts a SciPy linkage matrix to an Higra binary hierarchy.
The result is composed of
a tree
an array containing the altitudes of the tree nodes
an array containing the area of the tree nodes
- Parameters:
linkage_matrix – a 2d array as produced by the linkage method of SciPy
- Returns:
a tuple (tree, altitudes, area)