LoGo: private API
PortfolioOptimisers.InverseMatrixSparsificationAlgorithm — Type
abstract type InverseMatrixSparsificationAlgorithm <: AbstractMatrixProcessingAlgorithmAbstract supertype for all inverse matrix sparsification algorithms.
A member of this family imposes a sparsity pattern on the inverse of a covariance matrix rather than on the matrix itself. The covariance that comes back is dense; what is sparse is its precision, and the zeros there are the conditional independences the information filtering network selected.
The family declares no seam of its own, and no method dispatches on this supertype. A concrete subtype is reached through the matrix_processing_algorithm! of AbstractMatrixProcessingAlgorithm, which is the interface it inherits and which src/04_MatrixProcessing/04_MatrixProcessing.jl owns. LoGo is the shipped member, and matrix_processing_algorithm! states the contract that method satisfies.
Related
References
- [54] W. Barfuss, G. P. Massara, T. Di Matteo and T. Aste. Parsimonious modeling with information filtering networks. Phys. Rev. E 94, 062306 (2016).
PortfolioOptimisers.DVarInfo_DDVarInfo — Type
const DVarInfo_DDVarInfo = Union{<:Distance{<:Any, <:VariationInfoDistance},
<:DistanceDistance{<:Any, <:Any, <:Any, <:Any,
<:VariationInfoDistance}}Alias for distance types using variation of information metrics.
Matches either a VariationInfoDistance-based Distance or a VariationInfoDistance-based DistanceDistance. Used for dispatch in DBHT-based phylogeny computation.
Related
PortfolioOptimisers.jlogo! — Function
jlogo!(jlogo::MatNum, sigma::MatNum, source::MatNum, sign::Integer)Efficiently accumulate contributions to the sparse inverse covariance matrix for LoGo/DBHT.
This internal function updates the jlogo matrix in-place by iterating over a list of cliques or separators (source), extracting the corresponding submatrix from the covariance matrix sigma, inverting it, and adding (or subtracting) the result to the appropriate block in jlogo, scaled by sign.
Every row of source names the same number of vertices, because tmp is allocated once at size(source, 2) and reused. PMFG_T2s satisfies that: its 3-cliques all carry three vertices and its 4-cliques all carry four.
Algorithm
- Allocate
tmp, one square block of the width of a row ofsource. - For each row
iofsource, read the index setvand gather the submatrixsigma[v, v]intotmp. - Invert
tmp. - Add
signtimes each entry of the inverse intojlogo, at the pair ofvthat entry belongs to.
Arguments
jlogo:N × Nmatrix to be updated in-place. It is added to, never cleared, so the caller sets what it starts from.sigma:N × Ncovariance matrix. Only the blocks the rows ofsourcename are read.source:Ns×kindex matrix. Each row holds thekvertices of one clique or separator, andkis4for the cliques and3for the separators of a PMFG.sign:+1for cliques,-1for separators.
Returns
nothing. Updatesjlogoin-place.
Related
PortfolioOptimisers.J_LoGo — Function
J_LoGo(sigma::MatNum, separators::MatNum, cliques::MatNum)Compute the sparse inverse covariance matrix using the LoGo (Local-Global) algorithm [54].
This function implements the LoGo sparse inverse covariance estimation by combining clique and separator contributions from a Planar Maximally Filtered Graph (PMFG) or similar clique tree structure. It efficiently accumulates the inverses of covariance submatrices corresponding to cliques and separators, producing a sparse precision (inverse covariance) matrix suitable for robust portfolio optimization and risk management.
Mathematical definition
\[J_{i,\,j} = \sum_{c \in \mathcal{C}} \mathbf{1}\left[i \in c \land j \in c\right] \left(\mathbf{\Sigma}_{c,\,c}\right)^{-1}_{i,\,j} - \sum_{s \in \mathcal{S}} \mathbf{1}\left[i \in s \land j \in s\right] \left(\mathbf{\Sigma}_{s,\,s}\right)^{-1}_{i,\,j}\,.\]
Where:
- $\mathbf{J}$: LoGo precision matrix, $N \times N$.
- $\mathbf{\Sigma}$: Covariance matrix, $N \times N$.
- $\mathbf{\Sigma}_{c,\,c}$: Its submatrix on the index set $c$.
- $\mathcal{C}$: Set of the cliques of the network.
- $\mathcal{S}$: Set of its separators.
- $N$: Number of assets.
$J_{i,\,j}$ is exactly zero for a pair that no clique holds together, so the sparsity pattern of $\mathbf{J}$ is the edge set of the network. That is the conditional independence the filtering states, and it survives in the precision alone.
Algorithm
- Set
jlogoto a zero matrix of the size ofsigma. - Add the inverse of every clique block with
jlogo!atsign = 1. - Subtract the inverse of every separator block with
jlogo!atsign = -1.
Arguments
sigma:N × Ncovariance matrix.separators:Ns×3index matrix. Each row holds the vertices of one separator, which are the 3-cliques of a PMFG.cliques:Nq×4index matrix. Each row holds the vertices of one clique, which are the 4-cliques of a PMFG.
Returns
jlogo::Matrix{<:Number}:N × NLoGo sparse precision matrix. The covariance it stands for is its inverse, and that inverse is dense.
Related
PortfolioOptimisers.LoGo_dist_assert — Function
LoGo_dist_assert(de::DVarInfo_DDVarInfo, sigma::MatNum, X::MatNum)Validate compatibility of the distance estimator and covariance matrix for LoGo sparse inverse covariance estimation by checking size(sigma, 1) == size(X, 2).
The check runs for a VariationInfoDistance estimator alone, which is the only family that reads X rather than the correlation matrix. Every other estimator takes the no-op fallback, so a mismatched X passes. The narrow signature is what makes that so: it is bounded by DVarInfo_DDVarInfo, and the configurations that reach it are a Distance or a DistanceDistance whose algorithm is a VariationInfoDistance.
Arguments
de: Distance estimator whose algorithm is aVariationInfoDistance.sigma:N × Ncovariance matrix.X:T × Ndata matrix.size(X, 2)is the asset axis, which is the axis the check reads.
Validation
size(sigma, 1) == size(X, 2).
Returns
nothing.
Related
LoGo_dist_assert(args...)No-op fallback for other distance estimators.
Every distance estimator outside DVarInfo_DDVarInfo derives its distance from the correlation matrix and never reads X, so there is no shape of X for it to disagree with. This method makes that the default and leaves the check to the one family that owns it.
Algorithm
- Return
nothing. No shape is read, andargsis discarded.
Arguments
args...: The distance estimator, the covariance matrix and the data matrix (all ignored).
Returns
nothing.
Related
PortfolioOptimisers.logo! — Function
logo!(::Nothing, args...; kwargs...)
No-op fallback: return nothing when no LoGo algorithm is configured.
This is the branch a matrix processing pipeline takes when its sparsification field is nothing, so a caller composes the step in and out without a branch of its own.
Algorithm
- Return
nothing. No matrix is read and no matrix is written, andargsandkwargsare discarded.
Arguments
::Nothing: No LoGo algorithm configured.args...: Optional arguments (ignored).kwargs...: Optional keyword arguments (ignored).
Returns
nothing. The caller'ssigmais left as it stands.
Related
logo!(je::LoGo, sigma::MatNum, X::MatNum;
dims::Int = 1, kwargs...)Compute the LoGo (Local-Global) covariance matrix and update sigma in-place.
This method implements the LoGo algorithm for sparse inverse covariance estimation using the Planar Maximally Filtered Graph (PMFG) and clique-based decomposition. It validates inputs, computes the similarity and distance matrices, constructs the PMFG, identifies cliques and separators, and updates the input covariance matrix sigma in-place by inverting the LoGo sparse inverse covariance estimate. The result is projected to the nearest positive definite matrix if a Posdef estimator is not nothing.
Algorithm
- Check that
sigmais square, and check its asset axis againstXthroughLoGo_dist_assert. - Read the diagonal of
sigmaintos. When any entry ofsis not one,sigmais a covariance matrix: replaceswith its square roots and derive the correlation matrixSwithStatsBase.cov2cor.sigmaitself stays a covariance, and it is what step 6 decomposes. - Take the distance matrix
DfromSandXwithje.de, and check thatDlies in the domainje.simneeds. - Map
Dto the non-negative similaritySwithje.sim, throughdistance_to_similarity. - Build the TMFG on
SwithPMFG_T2satnargout = 4, and take its 3-cliques as the separators and its 4-cliques as the cliques. - Build the LoGo precision matrix from
sigmawithJ_LoGo, invert it, and write the result intosigma. - Repair
sigmawithposdef!throughje.pdm, which does nothing whenje.pdmisnothing.
Arguments
je: LoGo algorithm instance.sigma: Covariance matrix (N × N), updated in-place with the LoGo sparse inverse covariance.X: Data matrix (T × N).dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to distance and similarity estimators.
Validation
size(sigma, 1) == size(sigma, 2).size(sigma, 1) == size(X, 2), only whenje.dereadsX.LoGo_dist_assertcarries the check, and it has a method for the variation-of-information estimators alone; every other estimator takes the no-op fallback. A defaultLoGo()therefore accepts a20 × 20sigmabeside a400 × 10Xand returns without raising, becauseCanonicalDistancederives the distance from the correlation matrix and never touchesX.
Returns
nothing. The inputsigmais updated in-place.
Related
PortfolioOptimisers.logo — Function
logo(je::LoGo, sigma::MatNum, X::MatNum; dims::Int = 1, kwargs...) -> MatNumApply the LoGo (Local-Global) transformation to the covariance matrix and return the result as a new matrix.
This is the non-mutating variant of logo!. It copies sigma before applying the transformation.
Algorithm
- Copy
sigma. - Run
logo!on the copy, which carries every step and every check of this transformation. - Return the copy.
Arguments
je::LoGo: LoGo algorithm configuration.sigma::MatNum:N × Ncovariance matrix to transform (not mutated).X::MatNum:T × Nreturns data matrix.dims: Dimension along which to perform the computation.kwargs...: Additional keyword arguments passed to distance and similarity estimators.
Validation
- Every check of
logo!applies, and it raises from step 2.
Returns
sigma::MatNum:N × Ncopy of the input with the LoGo transformation applied.
Related
References
- [54]
- W. Barfuss, G. P. Massara, T. Di Matteo and T. Aste. Parsimonious modeling with information filtering networks. Phys. Rev. E 94, 062306 (2016).