Centrality Queries: private API
PortfolioOptimisers.centrality_graph — Function
centrality_graph(polarity::Option{<:AbstractCentralityPolarity}, pl::NwE_ClE_Cl,
X::MatNum; dims::Int = 1, kwargs...)Build the graph that calc_centrality scores, with the weights of the polarity that centrality_polarity returns for an algorithm ct.
This function is the one place that holds both the source and the polarity of the algorithm, so it is the one place that can match them. centrality_polarity states the quantity that ct needs, and the source states the quantities that it has.
The routing
| source | polarity | graph |
|---|---|---|
AbstractNetworkEstimator | DistancePolarity | calc_distance_weighted_graph, with distances on either branch |
NetworkEstimator on the similarity branch | SimilarityPolarity | calc_weighted_adjacency_graph, with the similarities that selected the edges |
| any source | nothing | plain Graphs.SimpleGraph of phylogeny_matrix |
a clustering estimator or Clusters | any | plain Graphs.SimpleGraph of phylogeny_matrix |
AbstractNetworkEstimator on a tree branch | SimilarityPolarity | plain Graphs.SimpleGraph of phylogeny_matrix |
The similarity route is narrower than the distance route on purpose. calc_distance_weighted_graph carries distances on both branches, but a similarity selects the edges of the similarity branch only. On a tree, calc_mst selects the edges by a minimised distance. A similarity made from that distance puts on the structure a quantity that did not select it.
A partition carries no weights, and does not borrow any
A clustering source can reach a distance estimator through its own de, and it does not use it. The triangulated maximally filtered graph selects each edge by a pairwise quantity, so a distance orders that selection. A partition selects by a dendrogram and a cut, and two assets in the same cluster can be far apart in the distance. The distance does not order the membership of a cluster, so the partition has no quantity to borrow.
Only the unweighted route reads the separation
The unweighted route goes through phylogeny_matrix, so it reads the AbstractSeparationAlgorithm of the estimator. A HopCount of n = 2 gives the centrality on the closure at two hops. The weighted routes do not go through phylogeny_matrix, and read the structure. A closure is a sum of matrix powers, and a power of a weighted matrix sums products of distances, which is not a separation. The weighted routes do not read the sep field. At the default HopCount(; n = 1) the two routes agree, because the closure of a graph at one hop is the graph.
The caller resolves the polarity
The caller passes centrality_polarity(ct) in the first slot, as centrality_vector does, so every method takes the polarity and the function resolves it one time. The polarity that decides comes first, and the source only gives the graph. A clustering source ignores the polarity.
Algorithm
Return the plain
Graphs.SimpleGraphofphylogeny_matrixwhen the source is a clustering estimator or aClusters. A partition carries no edge weights, so the function ignores the polarity.Build the graph, through the branch that the polarity and the source select together.
nothing: the plainGraphs.SimpleGraphofphylogeny_matrix. It is the one route that reads thesepof the estimator.DistancePolarity: the structure ofcalc_distance_weighted_graph, with distances on either branch.SimilarityPolarityon a similarity branch: the structure ofcalc_weighted_adjacency_graph, with the similarities that selected its edges.SimilarityPolarityon a tree branch: the plain graph, because a minimised distance selects a tree, and a tree holds no similarity to read.
Arguments
polarity: Effective polarity of the algorithmct, fromcentrality_polarity.pl: Network estimator, clustering estimator, or clustering result.X: Data matrixobservations × assetsif thedimskeyword does not exist ordims = 1,assets × observationswhendims = 2.dims: Dimension along which the computation runs.kwargs...: Additional keyword arguments.
Returns
g::Graphs.AbstractGraph: ASimpleWeightedGraphs.SimpleWeightedGraphon a weighted route, aGraphs.SimpleGraphotherwise.
Related