DBHT Clustering: private API
PortfolioOptimisers.DBHTs — Function
DBHTs(D::MatNum, S::MatNum; branchorder::Symbol = :optimal,
root::DBHTRootMethod = UniqueRoot(),
sim::Option{<:AbstractSimilarityMatrixAlgorithm} = nothing)Perform Direct Bubble Hierarchical Tree clustering, a deterministic clustering algorithm [53]. This version uses a graph-theoretic filtering technique called Triangulated Maximally Filtered Graph (TMFG).
This function implements the full DBHT clustering pipeline: it constructs a Planar Maximally Filtered Graph (PMFG) from the similarity matrix, extracts the clique and bubble hierarchies, assigns clusters, and builds a hierarchical clustering (dendrogram) compatible with Clustering.Hclust.
Algorithm
- Check that
DandSare non-empty and of equal size. - Build the PMFG from
SwithPMFG_T2s, giving the weighted adjacencyRpm, and check its edge count withassert_pmfg_weights. - Copy the sparsity pattern of
RpmintoApmand fill it with the dissimilarities ofD, so the structure comes from the similarities and the lengths from the distances. - Take the shortest path lengths
DpmonApmwithdistance_wei. - Build the clique and bubble hierarchies from
RpmwithCliqHierarchyTree2s, givingHb,Mb,CliqListandSb. - Lift the clique membership
Mbto the vertex membershipMv: columnnmarks every vertex of every 3-clique that bubblenholds. - Assign the clusters with
BubbleCluster8s, givingAdjvand the discrete membershipT8. - Build the linkage matrix
ZwithHierarchyConstruct4s, and convert it withturn_into_Hclust_merges. - Load the two merge columns and the heights into a
Clustering.HclustMerges, and order its branches through the branchbranchorderselects. - Wrap the merges in a
Clustering.Hclusttagged:DBHT.
Arguments
D:N × Ndissimilarity matrix (e.g., a distance matrix). It must be symmetric, and the symmetry is a caller contract that this function does not check.S:N × Nnon-negative similarity matrix. It must be symmetric, on the same unchecked contract.branchorder: Ordering method for the dendrogram branches.:optimaland:barjosephboth callClustering.orderbranches_barjoseph!, and:rcallsClustering.orderbranches_r!. Any other value is not refused: it leaves the branches in the orderHierarchyConstruct4sbuilt them.root: Root selection method for the clique hierarchy.sim: Similarity matrix algorithm that producedS. It is forwarded toassert_pmfg_weightsand read for nothing else, so that a refusal names the configuration rather than the matrix. A caller that holds only the matrices leaves itnothing.
Validation
!isempty(S), raisingIsEmptyError.!isempty(D), raisingIsEmptyError.size(S) == size(D), raisingDimensionMismatch.- The PMFG built from
Skeeps its3N - 6edges, byassert_pmfg_weights. An exactly zero similarity is an absent edge.
Symmetry is not among them. A caller that derives both matrices from a correlation matrix gets it by construction, and a caller that assembles either by hand carries the contract itself.
Returns
T8::Vector{Int}:N × 1cluster membership vector.T8[n] = kputs vertexnin thek-th discrete cluster.Rpm::SparseMatrixCSC{<:Number, Int}:N × Nadjacency matrix of the Planar Maximally Filtered Graph (PMFG).Adjv::SparseMatrixCSC{Int, Int}: Bubble cluster membership matrix fromBubbleCluster8s.Dpm::Matrix{<:Number}:N × Nshortest path length matrix of the PMFG.Mv::SparseMatrixCSC{Int, Int}:N × Nbbubble membership matrix.Mv[n, bi] = 1means vertexnis a vertex of bubblebi.Z::Matrix{<:Number}:(N-1)×3linkage matrix in Matlab format.Z_hclust::Clustering.Hclust: Dendrogram inClustering.Hclustformat.
Related
References
- [53]
- W.-M. Song, T. Di Matteo and T. Aste. Hierarchical information clustering by means of topologically embedded graphs. PloS one 7, e31929 (2012).