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 to0or1, overGraphs.adjacency_matrix(g). The matrix is binary, becauseseparation_graphgives a hop count a binary structure, and a power of a weighted matrix sums products of distances. The function readssep.ndirectly as a count of matrix powers, and not throughseparation_budget.PathLength: the radius ball, the matrix ofseparation_matrixwith a threshold atseparation_budget. It needs no second traversal.
Algorithm
Under a HopCount:
- Read the binary matrix
AfromgwithGraphs.adjacency_matrix. - Add up
Pas the sum ofA^ioveri in 0:sep.n.val. Each entry counts the walks of length at mostsep.n.valbetween its pair. - Clamp
Pto0or1, which changes the count of walks into the selection. Subtract the identity to set the diagonal to zero.
Under a PathLength:
- Measure the separations over
gintodwithseparation_matrix. - Find the budget
dmaxwithseparation_budget. - Select every pair that
is_relatedadmits atdmax. Subtract the identity to set the diagonal to zero.is_relatedtests the unreachable sentinel as well as the budget.
Arguments
sep: Resolved separation algorithm. The public method takes it fromnte.sep.nte: Network estimator.g: Structure to read, fromseparation_graph.
Returns
P::Matrix{Int}: Phylogeny matrix. An entry is1for a related pair and0otherwise, and the diagonal is0.
Related