skbio.stats.composition.tree_basis#

skbio.stats.composition.tree_basis(tree)[source]#

Calculate the sparse representation of an ilr basis from a tree.

This computes an orthonormal basis specified from a bifurcating tree.

Parameters:
treeskbio.TreeNode

Input bifurcating tree. Must be strictly bifurcating (i.e. every internal node needs to have exactly two children). This is used to specify the ilr basis.

Returns:
scipy.sparse.coo_matrix

The ilr basis required to perform the ilr_inv transform. This is also known as the sequential binary partition. Note that this matrix is represented in clr coordinates.

list of str

List of tree node names indicating the ordering in the basis.

Raises:
ValueError

If the tree doesn’t contain two branches.

Examples

>>> from skbio import TreeNode
>>> tree = u"((b,c)a, d)root;"
>>> t = TreeNode.read([tree])
>>> basis, nodes = tree_basis(t)
>>> basis.toarray()
array([[-0.40824829, -0.40824829,  0.81649658],
       [-0.70710678,  0.70710678,  0.        ]])