Tutorials › Statistical Learning (Graduate) › Constructing Cluster Trees from Density Estimates

Level Sets and Cluster Trees · Tutorial 680 of 989

Constructing Cluster Trees from Density Estimates

Build a cluster tree from an estimated density and understand how threshold grids approximate its merge heights without assuming a supremum is attained.

Advanced 13 min read

What You'll Learn

  • Define an estimated cluster tree using connected components of density superlevel sets.
  • Explain how nesting links components across density thresholds.
  • Specify practical choices for the estimator, domain, thresholds, and connectivity.
  • Construct cluster trees at finitely many thresholds and link their components.
  • Bound the error in grid-based merge heights, including when the supremum is not attained.
  • Distinguish a threshold-grid approximation from a spatial graph approximation.

From a Density Estimate to a Hierarchy

A density estimate describes where observations are concentrated, but a clustering summary must also describe how high-density regions split and join as the required density level changes. The central construction is to take connected components of the estimated density's superlevel sets at many thresholds. At high thresholds, only the most concentrated regions remain; lowering the threshold can enlarge existing components or join previously separate ones.

The resulting hierarchy depends not only on the observed sample but also on the density estimator, the domain on which it is analyzed, and the thresholds and connectivity convention used in computation. These choices should be made explicit: a tree built from estimated densities is a defined object, not an automatic by-product of fitting a density.

Definition: Let \(D\) be a connected topological space and let \(\hat f:D\to[0,\infty)\) be an estimated density or other specified density estimate. For a threshold \(\lambda\), its superlevel set is \(L_\lambda(\hat f)=\{x\in D:\hat f(x)\geq\lambda\}\). A component means a connected component in the topology on \(D\). The estimated cluster tree is the collection of pairs \((\lambda,C)\) for which \(C\) is a connected component of \(L_\lambda(\hat f)\), ordered by inclusion across thresholds.

For a finite threshold range, take \(a\leq\inf_{x\in D}\hat f(x)\) and \(b\geq\sup_{x\in D}\hat f(x)\), and consider \(\lambda\in[a,b]\). Then \(L_a(\hat f)=D\), so the baseline set is connected. In applications, \(D\) is often a prespecified compact region; restricting the domain makes the range and boundary convention part of the analysis rather than leaving them implicit. If \(D\) is not connected, the construction gives a forest at the baseline instead of a single root.

Why the Components Form a Tree

The hierarchy follows from a basic nesting property. If \(\lambda_2>\lambda_1\), then every point with estimated density at least \(\lambda_2\) also has estimated density at least \(\lambda_1\). Thus \(L_{\lambda_2}(\hat f)\subseteq L_{\lambda_1}(\hat f)\). A component at the higher threshold must lie inside exactly one component at the lower threshold.

Theorem (Nesting of superlevel components): Let \(\lambda_2>\lambda_1\), and let \(C_2\) be a connected component of \(L_{\lambda_2}(\hat f)\). Then \(C_2\) is contained in a unique connected component \(C_1\) of \(L_{\lambda_1}(\hat f)\).

Proof. Since \(\lambda_2>\lambda_1\), \(L_{\lambda_2}(\hat f)\subseteq L_{\lambda_1}(\hat f)\), so \(C_2\subseteq L_{\lambda_1}(\hat f)\). A connected subset of a space lies in one of that space's connected components: the union of the subset with any component it intersects is connected, so maximality of components places the subset inside that component. The component containing \(C_2\) is unique because distinct connected components are disjoint. \(\square\)

This result tells us how to link levels: each component at a higher threshold has one parent at every lower threshold where it exists. Conversely, a component at a lower threshold may contain several higher-threshold components, representing a split as the density requirement rises. The tree does not require the number of components to be finite at every threshold; finite data alone do not guarantee that for every possible estimator.

For two points \(x,y\in D\), their merge height summarizes when their paths through this hierarchy first become connected as the threshold is lowered.

Definition: Suppose \(L_a(\hat f)=D\) and \(D\) is connected. The merge height of \(x,y\in D\) is \(m_{\hat f}(x,y)=\sup\{\lambda\in[a,b]:x\text{ and }y\text{ belong to the same component of }L_\lambda(\hat f)\}\).

The set inside the supremum is nonempty because it contains \(a\). It is downward persistent: if \(x,y\) belong to the same component at \(\lambda\), then they belong to the same component at every threshold between \(a\) and \(\lambda\), since the connected component is contained in a component of the lower superlevel set. The supremum need not itself be in the set. This distinction matters when a tree is represented on a finite threshold grid.

Worked Example: Two Peaks and Their Merge Level

Consider the piecewise-linear function on \(D=[0,4]\) that joins the knot values \(0,0.4,0.1,0.3,0\) at \(x=0,1,2,3,4\), respectively. Its integral is \(0.2+0.25+0.2+0.15=0.8\). Dividing all values by \(0.8\) gives a density estimate with knot values \(0,0.5,0.125,0.375,0\).

At threshold \(\lambda=0.25\), the left peak's superlevel interval begins at \(x=2\lambda=0.5\). On the segment from \(x=1\) to \(x=2\), the estimate falls from \(0.5\) to \(0.125\), so the right endpoint is \(x=2-(0.25-0.125)/0.375=5/3\). The right peak's interval begins on the rising segment at \(x=2+(0.25-0.125)/0.25=2.5\) and ends on the falling segment at \(x=4-0.25/0.375=10/3\). The two components are therefore \([0.5,5/3]\) and \([2.5,10/3]\).

The valleys' height is \(0.125\). At that threshold the superlevel set extends through \(x=2\), so it connects the two peak regions. At any threshold strictly above \(0.125\), the two peaks are separated. Their merge height is \(0.125\), and in this example the supremum is attained because the two regions are connected at the valley threshold itself.

Building a Finite-Threshold Tree

A practical finite representation selects thresholds \(G=\{t_0,\ldots,t_J\}\), where \(a=t_0<t_1<\cdots<t_J=b\). At each selected level, compute the components of \(L_{t_j}(\hat f)\). Link every component at \(t_{j+1}\) to the unique component at \(t_j\) containing it. Repeating this gives a tree at the chosen levels. A split between recorded levels is not observed by this representation; its displayed height is therefore limited by the threshold spacing.

1
Specify the estimated density and domain.
Record the estimator, its tuning choices, the region \(D\), and any boundary correction. These affect the estimated values and hence the superlevel sets.
2
Choose thresholds.
Select a finite increasing grid over the range of interest. Include a baseline threshold that makes the domain connected, or explicitly retain a forest if the baseline has multiple components.
3
Find components at each level.
For each threshold, determine the connected components of the estimated superlevel set using a stated continuous or computational connectivity convention.
4
Link levels and record conventions.
Attach each higher-level component to its unique lower-level parent. State how equality at a threshold is handled and how any spatial discretization defines adjacency.

For example, a kernel density estimate with observations \(X_1,\ldots,X_n\), kernel \(K\), and bandwidth \(h>0\) is \(\hat f_h(x)=\frac{1}{nh^d}\sum_{i=1}^n K((x-X_i)/h)\) in \(d\) dimensions. The cluster tree is built from this estimate, not directly from the observations. Changing \(h\) can change the number and location of peaks and the thresholds at which regions join. Likewise, a boundary correction or a different analysis domain can change the tree.

In numerical work, a density estimate may be evaluated on a grid. A rule such as “join neighboring grid cells when both meet the threshold” defines a graph-based approximation to connectedness. The neighbor rule (for example, edge-sharing cells only, or edge- and corner-sharing cells) can change the computed components. This spatial approximation is distinct from choosing only finitely many density thresholds: refining one does not automatically correct the other.

Worked Example: A Two-Observation Kernel Estimate

Let \(D=[-2,2]\), take observations \(X_1=-1\) and \(X_2=1\), and use bandwidth \(h=1\) with the triangular kernel \(K(u)=(1-|u|)_+\), where \(z_+=\max(z,0)\). Since this kernel integrates to one, the estimate is \(\hat f(x)=\frac12\{(1-|x+1|)_++(1-|x-1|)_+\}\).

On \([-2,0]\), only the kernel centered at \(-1\) is positive except at the shared endpoint \(x=0\), where both contributions are zero. Thus the left positive region has peak \(1/2\) at \(-1\) and decreases linearly to zero at \(-2\) and \(0\). By symmetry, the right positive region has peak \(1/2\) at \(1\), with zero values at \(0\) and \(2\).

At \(\lambda=0.25\), each positive component has radius \(1-2\lambda=0.5\); the superlevel set is \([-1.5,-0.5]\cup[0.5,1.5]\). At every \(\lambda>0\), these regions are disjoint. At \(\lambda=0\), the superlevel set is all of \(D\), so the two peak locations belong to the same component. Their merge height on this domain is \(0\). This example also shows why the domain and the baseline threshold must be stated: the zero-threshold set here is \(D\), not an unspecified ambient space.

Threshold Grids and Merge-Height Error

For a grid \(G=\{t_0,\ldots,t_J\}\) with \(t_0=a\), define \(m_G(x,y)\) as the largest grid threshold at which \(x\) and \(y\) are in the same component. The baseline assumption ensures that at least one such grid threshold exists. The following bound concerns only the vertical resolution of the merge height; it does not bound spatial error in the estimated components.

Theorem (Grid approximation of merge heights): Suppose \(L_a(\hat f)=D\) is connected, \(G\) includes \(a\), and \(m_{\hat f}(x,y)\) and \(m_G(x,y)\) are defined as above. Let \(\Delta=\max_{0\leq j<J}(t_{j+1}-t_j)\). Then \(0\leq m_{\hat f}(x,y)-m_G(x,y)\leq\Delta\).

Proof. Every qualifying grid level qualifies in the full interval, so \(m_G(x,y)\leq m_{\hat f}(x,y)\). Write \(m=m_{\hat f}(x,y)\). If \(m=a\), the baseline qualifies and \(m_G=a=m\). If \(m\) is a grid point and qualifies, then \(m_G=m\), giving zero error. In all other cases, let \(t\) be the largest grid point strictly below \(m\). Such a point exists because \(a\) qualifies when \(m>a\). By the definition of a supremum, for every \(t<m\) there is a qualifying level \(s>t\); otherwise \(t\) would be an upper bound smaller than \(m\). Downward persistence then implies that \(t\) qualifies. Hence \(m_G\geq t\). The distance from \(m\) to this largest grid point strictly below it is no greater than the largest adjacent grid gap \(\Delta\), including when \(m\) itself is a grid point that does not qualify. Therefore \(0\leq m-m_G\leq\Delta\). \(\square\)

Worked Example: A Merge Supremum That Is Not Attained

Consider a connected space made of countably many distinct arcs joining the same two endpoints. Give arc \(n\) length \(2^{-n}\), and use arc length as the reference measure. Set the density equal to \(C(1-1/n)\) in the interior of arc \(n\), and equal to \(C\) at both endpoints. Choose \(C\) to normalize the integral: \(C^{-1}=\sum_{n=1}^\infty 2^{-n}(1-1/n)\), a finite positive sum. The endpoint values do not affect the integral.

For any \(\lambda<C\), choose \(n\) large enough that \(C(1-1/n)\geq\lambda\). Then the entire \(n\)th arc, including its endpoints, belongs to the superlevel set, so the endpoints lie in the same component. At \(\lambda=C\), the superlevel set consists only of the two endpoints, which are disconnected. Thus their merge height is \(m=C\), but \(C\) itself does not qualify.

Take \(G=\{0,C/4,C/2,3C/4,C\}\). The endpoints are connected at \(3C/4\), since every arc with \(n\geq4\) qualifies, but not at \(C\). Therefore \(m_G=3C/4\) and \(m-m_G=C/4\), exactly the maximum grid gap. This verifies the grid bound without treating the supremum as an attained level.

Common Pitfall and Practical Interpretation

A common mistake is to say that a merge height \(m\) must itself qualify, and then infer that a grid containing \(m\) must record that merge exactly. A supremum need not be attained: a pair can be connected at every level below \(m\) and disconnected at \(m\). The correction is to use \(m\) only if it qualifies; otherwise use the largest grid point strictly below it. Downward persistence guarantees that this lower grid point qualifies, and its distance from \(m\) is at most the maximum grid gap.

A second practical distinction is that a finite-threshold tree is not a claim that the density estimate has only finitely many meaningful levels. It is a summary at selected levels. A separate spatial grid or graph introduces another approximation, governed by the evaluation resolution and adjacency rule. Reporting these choices makes the resulting clustering structure interpretable and reproducible.

Key takeaway: Construct the estimated cluster tree by taking connected components of the estimated density's superlevel sets and linking each higher-level component to its unique lower-level parent. State the estimator, domain, threshold grid, and connectivity convention; for a grid with maximum gap \(\Delta\), merge-height error is at most \(\Delta\), whether or not the supremum is attained.

Check Your Understanding

Answer each question using the definitions and constructions above.

  1. Why must a component at a higher threshold lie inside exactly one component at a lower threshold?
  2. What role does the baseline condition \(L_a(\hat f)=D\) connected play in defining merge heights on \([a,b]\)?
  3. A pair has merge height equal to a grid point, but the pair is not connected at that threshold. Which grid point should be used to establish the approximation bound, and why does it qualify?
  4. For the two-observation triangular-kernel example, what are the components at threshold \(0.25\), and why do the peak locations have merge height zero?
  5. Name one spatial discretization choice that can change computed components even when the density threshold grid is unchanged.
Clinical Biostats