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)Internal dispatch helper carrying phylogeny_matrix's per-separation body.
The neighbourhood phylogeny_matrix selects is a question about the separation, not about the estimator, so the split lives here rather than on the public method's argument. Dispatching on the estimator instead would pin the choice to NetworkEstimator and leave every other AbstractNetworkEstimator on one branch — and this family's other kernels, separation_matrix and separation_budget, already take the separation first for the same reason.
The structure arrives built
g is separation_graph's, built once by the public method and shared with resolve_separation, so neither branch derives a distance of its own. nte stays for separation_budget's estimator channel and is otherwise inert here.
The two balls
HopCount: the hop ball,sum(A^i for i in 0:n)clamped to0or1, overGraphs.adjacency_matrix(g)— binary, becauseseparation_graphhands a hop count a binarised structure and a power of a weighted matrix would sum products of distances.sep.nis read directly as a matrix-power count rather than throughseparation_budget, which is what makes it a power count and not a budget.PathLength: the radius ball,separation_matrixthresholded atseparation_budget. No second traversal.
Algorithm
Under a HopCount:
- Read
Graphs.adjacency_matrixoffg, giving the binary matrixA. - Accumulate
Pas the sum ofA^ioveri in 0:sep.n. Each entry counts the walks of length at mostsep.nbetween its pair. - Clamp
Pto0or1, which turns the walk count into the selection, and subtract the identity to clear the diagonal.
Under a PathLength:
- Measure the separations over
gwithseparation_matrix, givingd. - Resolve the budget with
separation_budget, givingdmax. - Select every pair
is_relatedadmits atdmax, and subtract the identity to clear the diagonal.is_relatedcarries the unreachable sentinel as well as the budget.
Arguments
sep: Separation algorithm, taken fromnte.sepby the public method and resolved.nte: Network estimator.g: Structure to read, fromseparation_graph.
Returns
P::Matrix{Int}: Phylogeny matrix.1for a related pair,0otherwise,0on the diagonal.
Related