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

sourcepolaritygraph
AbstractNetworkEstimatorDistancePolaritycalc_distance_weighted_graph, with distances on either branch
NetworkEstimator on the similarity branchSimilarityPolaritycalc_weighted_adjacency_graph, with the similarities that selected the edges
any sourcenothingplain Graphs.SimpleGraph of phylogeny_matrix
a clustering estimator or Clustersanyplain Graphs.SimpleGraph of phylogeny_matrix
AbstractNetworkEstimator on a tree branchSimilarityPolarityplain 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

  1. Return the plain Graphs.SimpleGraph of phylogeny_matrix when the source is a clustering estimator or a Clusters. A partition carries no edge weights, so the function ignores the polarity.

  2. Build the graph, through the branch that the polarity and the source select together.

Arguments

  • polarity: Effective polarity of the algorithm ct, from centrality_polarity.
  • pl: Network estimator, clustering estimator, or clustering result.
  • X: Data matrix observations × assets if the dims keyword does not exist or dims = 1, assets × observations when dims = 2.
  • dims: Dimension along which the computation runs.
  • kwargs...: Additional keyword arguments.

Returns

  • g::Graphs.AbstractGraph: A SimpleWeightedGraphs.SimpleWeightedGraph on a weighted route, a Graphs.SimpleGraph otherwise.

Related

source