level_set_tree.construct_tree_from_graph

level_set_tree.construct_tree_from_graph(adjacency_list, density, prune_threshold=None, num_levels=None, verbose=False)

Construct a level set tree from a similarity graph and a density estimate.

Parameters:

adjacency_list : list [list]

Adjacency list of the k-nearest neighbors graph on the data. Each entry contains the indices of the k closest neighbors to the data point at the same row index.

density : list [float]

Estimate of the density function, evaluated at the data points represented by the keys in adjacency_list.

prune_threshold : int, optional

Leaf nodes with fewer than this number of members are recursively merged into larger nodes. If ‘None’ (the default), then no pruning is performed.

num_levels : list int, optional

Number of density levels in the constructed tree. If None (default), num_levels is internally set to be the number of rows in X.

verbose : bool, optional

If True, a progress indicator is printed at every 100th level of tree construction.

Returns:

T : levelSetTree

See the LevelSetTree class for attributes and method definitions.

Examples

>>> X = numpy.random.rand(100, 2)
>>> knn_graph, radii = debacl.utils.knn_graph(X, k=8)
>>> density = debacl.utils.knn_density(radii, n=100, p=2, k=8)
>>> tree = debacl.construct_tree_from_graph(knn_graph, density,
...                                         prune_threshold=5)
>>> print(tree)
+----+-------------+-----------+------------+----------+------+--------+----------+
| id | start_level | end_level | start_mass | end_mass | size | parent | children |
+----+-------------+-----------+------------+----------+------+--------+----------+
| 0  |    0.000    |   0.768   |   0.000    |  0.390   | 100  |  None  |  [1, 2]  |
| 1  |    0.768    |   1.494   |   0.390    |  0.790   |  30  |   0    |  [7, 8]  |
| 2  |    0.768    |   4.812   |   0.390    |  1.000   |  31  |   0    |    []    |
| 7  |    1.494    |   2.375   |   0.790    |  0.950   |  6   |   1    |    []    |
| 8  |    1.494    |   2.308   |   0.790    |  0.940   |  5   |   1    |    []    |
+----+-------------+-----------+------------+----------+------+--------+----------+