Phylogeny Matrix: private API

PortfolioOptimisers._phylogeny_matrix — Function
_phylogeny_matrix(sep::HopCount, nte::AbstractNetworkEstimator,
                  g::Graphs.AbstractGraph)
_phylogeny_matrix(sep::PathLength, nte::AbstractNetworkEstimator,
                  g::Graphs.AbstractGraph)

Select the related pairs of a structure, through the branch of the separation sep.

phylogeny_matrix calls this function for its body. The separation decides the neighbourhood that phylogeny_matrix selects, and the estimator does not. This function therefore dispatches on the separation, and the public method does not. A dispatch on the estimator ties the choice to NetworkEstimator, and puts every other AbstractNetworkEstimator on one branch. The other kernels of the family, separation_matrix and separation_budget, also take the separation first, for the same reason.

The structure is already built

g comes from separation_graph. The public method builds it one time, and also gives it to resolve_separation. Neither branch computes a distance of its own. The function passes nte to separation_budget, and reads it for no other purpose.

The two balls

  • HopCount: the hop ball, sum(A^i for i in 0:n) clamped to 0 or 1, over Graphs.adjacency_matrix(g). The matrix is binary, because separation_graph gives a hop count a binary structure, and a power of a weighted matrix sums products of distances. The function reads sep.n directly as a count of matrix powers, and not through separation_budget.
  • PathLength: the radius ball, the matrix of separation_matrix with a threshold at separation_budget. It needs no second traversal.

Algorithm

Under a HopCount:

  1. Read the binary matrix A from g with Graphs.adjacency_matrix.
  2. Add up P as the sum of A^i over i in 0:sep.n.val. Each entry counts the walks of length at most sep.n.val between its pair.
  3. Clamp P to 0 or 1, which changes the count of walks into the selection. Subtract the identity to set the diagonal to zero.

Under a PathLength:

  1. Measure the separations over g into d with separation_matrix.
  2. Find the budget dmax with separation_budget.
  3. Select every pair that is_related admits at dmax. Subtract the identity to set the diagonal to zero. is_related tests the unreachable sentinel as well as the budget.

Arguments

  • sep: Resolved separation algorithm. The public method takes it from nte.sep.
  • nte: Network estimator.
  • g: Structure to read, from separation_graph.

Returns

  • P::Matrix{Int}: Phylogeny matrix. An entry is 1 for a related pair and 0 otherwise, and the diagonal is 0.

Related

source