Separation: private API
PortfolioOptimisers.separation_graph — Function
separation_graph(sep::HopCount, G::Graphs.AbstractGraph)
separation_graph(sep::HopCount, nte::AbstractNetworkEstimator, X::MatNum;
dims::Int = 1, kwargs...)
separation_graph(sep::PathLength, nte::AbstractNetworkEstimator, X::MatNum;
dims::Int = 1, kwargs...)Build the structure a separation measures over.
This function is one of the three kernels that a member of AbstractSeparationAlgorithm implements. separation_matrix and separation_budget are the other two. It is a kernel of its own, so that a consumer builds the structure one time for each call. separation_matrix and resolve_separation both take the graph. Without this kernel, a consumer that needs the separations and a resolved budget rule builds the same structure two times.
What each member measures over
HopCount: the structure ofcalc_adjacency, as aGraphs.SimpleGraph. The graph is binary, because a hop count does not read the weights and its consumers do._phylogeny_matrixreadsGraphs.adjacency_matrixof this graph for a sum of powers. With weights,A^isums products of distances and does not count walks.PathLength: the structure ofcalc_distance_weighted_graph. It has the same edge set, with distances as weights on either branch. A shortest path over the similarities of a PMFG takes the route through the weakest links.
Two entry points, and why only the hop count takes a graph
The methods that take nte build the structure from X. The method that takes G is for a caller that already holds the structure. Both clusterise methods build it from the quantity that selects the edges, through the entry point of calc_weighted_adjacency_graph that takes alg. Without this method, they compute the distance again to resolve a budget rule. Under VariationInfoDistance, that computation is 98% of the run time of clusterise.
PathLength has no method that takes a graph, and it cannot have one. A graph carries no polarity tag. G has distances as weights on the tree branch and similarities on the PMFG branch, and the argument does not show which. A shortest path over the similarities of a PMFG returns an answer and raises no error, see calc_distance_weighted_graph. The hop count is not affected, because it removes the weights.
Algorithm
Build the structure from
X, through the branch thatsepselects.HopCount: the binary matrix ofcalc_adjacency.PathLength: the structure ofcalc_distance_weighted_graph, with distances as weights. It is the answer.
Convert the structure of a
HopCountto aGraphs.SimpleGraph, which removes the weights. The method that takesGreceives it and starts here.
Arguments
sep: Separation algorithm. The function dispatches on its type and does not read its budget. A member whose budget is a rule measures over the same structure as a member whose budget is a number.resolve_separationcan therefore take this graph.G: Network structure that the caller holds, in either polarity.nte: Network estimator.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: The structuresepmeasures over.
Related
PortfolioOptimisers.separation_quantile — Function
separation_quantile(
sep::AbstractSeparationAlgorithm,
d::AbstractMatrix{<:Union{Number, AbstractJuMPScalar}},
q::Number
) -> Number
Compute the quantile of the reachable off-diagonal entries of a separation matrix.
The population is the set of pairs that a budget can relate. The diagonal is zero, and an unreachable pair holds the sentinel of separation_matrix, so neither is a separation. phylogeny_matrix selects from the same population. q is then the fraction of the pairs that the budget relates.
The test for the sentinel belongs to the family
The function removes an unreachable pair from the population with is_reachable, and not with a test of its own. isfinite does not work. It is true for every Integer, so it admits the sentinel typemax(Int) of HopCount.
Algorithm
- Collect into
vthe off-diagonal entries ofdthatis_reachableadmits.vis the population of the quantile. - Throw an
ArgumentErrorwhenvis empty. - Return the
q-quantile ofvfromStatistics.quantile.
Arguments
sep: Separation algorithm that measured the matrix. The function passes it tois_reachable.d: Separation matrix fromseparation_matrix.q: Quantile in[0, 1].resolve_separationpasses thevalof aFractionOfbudget.
Validation
- Throws an
ArgumentErrorif no off-diagonal entry ofdis reachable, because an empty population has no quantile.
Returns
dmax::Number: Theq-quantile of the reachable off-diagonal separations.
Related