mvtsa.segmentation.GraphBottomUp#

class mvtsa.segmentation.GraphBottomUp(n_regions=2)[source]#

Bases: object

Bottom-up merging of connected regions of a graph.

Every node carries a feature vector; regions are merged along graph edges, always taking the adjacent pair whose union increases the within-region sum of squares least (Ward’s criterion restricted to adjacent regions). On a path graph it reduces to bottom-up segmentation with the L2 cost; on a sensor network, a spatial grid or a mesh it gives contiguous regions.

Parameters:
n_regionsint

Number of regions to keep.

Examples

>>> import networkx as nx
>>> G = nx.path_graph(6)
>>> F = np.array([0, 0, 0, 5, 5, 5.0])
>>> GraphBottomUp(2).fit(G, F).labels_.tolist()
[0, 0, 0, 1, 1, 1]