MCD search
PortfolioOptimisers.AbstractMCDAlgorithm — Type
abstract type AbstractMCDAlgorithm <: AbstractAlgorithmAbstract supertype for the search algorithms of the minimum covariance determinant.
The minimum covariance determinant of MCDCovariance is the subset of h observations whose covariance matrix has the smallest determinant. An exact search tries every subset, so it is not practical. A subtype gives a search that starts from a set of subsets and improves each one by concentration steps, see mcd_csteps. mcd_search returns the best subset that it finds.
Interfaces
To implement a new search, subtype AbstractMCDAlgorithm, keep each parameter in a field, and implement one method:
PortfolioOptimisers.mcd_starts(alg, Z::MatNum, h::Integer, fixed::Bool, intensity) -> Vector{Vector{Int}}: Returns the start subsets ofhobservations of the standardised dataZ. Whenfixedistrue, the centre is fixed at zero.intensityis the shrinkage intensity or its rule, ornothingfor a scatter with no shrinkage.
The fit does concentration steps from each start and keeps the best subset. A search with many starts can keep a part of them first, with one more method:
PortfolioOptimisers.mcd_refine(alg, Z::MatNum, starts, h::Integer, fixed::Bool, reg) -> Vector{Vector{Int}}: Returns the subsets from which the fit does concentration steps until they do not change. The default returnsstarts.regis theSubsetShrinkage, ornothing.
Related
PortfolioOptimisers.DetMCD — Type
struct DetMCD <: AbstractMCDAlgorithmSearches the minimum covariance determinant from six deterministic starts.
The search of [119] computes six robust estimates of the correlation of the standardised data. Each one gives a start of h observations. The search then does concentration steps from each start until the subset does not change, and keeps the subset with the smallest determinant. Two calls on the same data give the same subset, so cov(ce, X) == fit(ce, X).sigma holds, and a cross-validation run gives the same estimate each time.
The search follows the code of the R package robustbase, version 0.99-7, with nsamp = "deterministic", with one difference. That code scales the data by the tau scale when $n \geq 1000$, and [119] names the tau scale for a large sample as a faster choice. This search uses $Q_n$, see qn_scale, at every $n$, because the selection of kth_pairwise_difference is fast at any $n$.
Examples
julia> DetMCD()DetMCD()Related
References
- [119] M. Hubert, P. J. Rousseeuw and T. Verdonck. A deterministic algorithm for robust location and scatter. Journal of Computational and Graphical Statistics 21, 618–637 (2012). Sections 3.1 and 3.2.
PortfolioOptimisers.FastMCD — Type
struct FastMCD{__T_n_starts, __T_n_csteps, __T_n_best, __T_rng, __T_seed} <: AbstractMCDAlgorithmSearches the minimum covariance determinant from random starts.
The search of [120] draws n_starts random subsets of $p + 1$ observations. Each subset gives a start of h observations, the observations nearest to its mean in the metric of its covariance. The search does n_csteps concentration steps from each start. It keeps the n_best subsets with the smallest determinants, does concentration steps from each until the subset does not change, and returns the best.
The search draws random numbers, so the type has the fields rng and seed. resolve_rng combines them when the search runs. With seed = nothing, two calls can give two estimates. DetMCD is the default of MCDCovariance for that reason.
The search does not split a large sample into the nested subsamples of Section 3.3 of [120]. A start reads every observation.
Fields
n_starts: Number of random start subsets.
n_csteps: Number of concentration steps from each start before the search keeps the best starts.
n_best: Number of the best starts that the search iterates until their subsets do not change.
rng: Random number generator.
seed: Optional seed. If set, the draws come from a copy ofrngseeded with it, sorngdoes not advance and every call draws the same values. Ifnothing, the draws come fromrngitself.
Constructors
FastMCD(; n_starts::Integer = 500, n_csteps::Integer = 2, n_best::Integer = 10, rng::Random.AbstractRNG = Random.default_rng(), seed::Option{<:Integer} = nothing) -> FastMCDKeywords correspond to the struct's fields.
Validation
n_starts,n_cstepsandn_bestare positive.n_best <= n_starts.
Examples
julia> FastMCD(; seed = 42)FastMCD n_starts ┼ Int64: 500 n_csteps ┼ Int64: 2 n_best ┼ Int64: 10 rng ┼ Random.TaskLocalRNG: Random.TaskLocalRNG() seed ┴ Int64: 42Related
References
- [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Sections 3.1, 3.2 and 4.
PortfolioOptimisers.mcd_starts — Function
mcd_starts(alg::DetMCD, Z::MatNum, h::Integer, fixed::Bool, intensity::Nothing) -> Vector{Vector{Int}}
mcd_starts(alg::DetMCD, Z::MatNum, h::Integer, fixed::Bool,
intensity::Union{Number, AbstractSubsetShrinkageIntensity}) -> Vector{Vector{Int}}
mcd_starts(alg::FastMCD, Z::MatNum, h::Integer, fixed::Bool, intensity) -> Vector{Vector{Int}}Returns the start subsets of the search alg.
The DetMCD method returns six starts, one for each set of directions of detmcd_directions, through detmcd_initset. With a shrinkage it standardises the data again with mcd_standardise, because the coordinates that turn the target into the identity matrix can change the scale of a column, and the six estimates read standardised data. The FastMCD method resolves the generator from alg.rng and alg.seed with resolve_rng, and draws alg.n_starts starts with fastmcd_random_start.
Arguments
alg: The search algorithm.Z: The standardised data.h: The size of the subset.fixed: Whether the centre is fixed at zero.intensity: The shrinkage intensity or its rule, ornothing.
Returns
starts::Vector{Vector{Int}}: The start subsets.
Related
References
- [119] M. Hubert, P. J. Rousseeuw and T. Verdonck. A deterministic algorithm for robust location and scatter. Journal of Computational and Graphical Statistics 21, 618–637 (2012). Section 3.
- [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Section 3.1.
PortfolioOptimisers.mcd_refine — Function
mcd_refine(alg::AbstractMCDAlgorithm, Z::MatNum, starts, h::Integer, fixed::Bool,
reg::Option{<:SubsetShrinkage}) -> Vector{Vector{Int}}
mcd_refine(alg::FastMCD, Z::MatNum, starts, h::Integer, fixed::Bool,
reg::Option{<:SubsetShrinkage}) -> Vector{Vector{Int}}Keeps the best starts of a search.
The default method keeps every start. The FastMCD method does alg.n_csteps concentration steps from each start with mcd_csteps, and returns the alg.n_best subsets with the smallest determinants, in increasing order of the determinant. A start that the shrinkage excludes leaves fewer starts, and the method then keeps at most that number.
Arguments
alg: The search algorithm.Z: The standardised data.starts: The start subsets.h: The size of the subset.fixed: Whether the centre is fixed at zero.reg: TheSubsetShrinkageof the subset scatter, ornothing.
Returns
starts::Vector{Vector{Int}}: The subsets from which the search does concentration steps until they do not change.
Related
References
- [120] P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999). Section 3.2.
PortfolioOptimisers.MCDSample — Type
struct MCDSample{__T_X, __T_Z, __T_tgt, __T_intensity, __T_centre}Holds the data that each step of the fit of an MCDCovariance reads.
mcd_sample builds it. A reweighting step reads it too, see mcd_reweight.
Fields
X: Data matrix in its own units,observations × assets.
Z: Standardised data of the search, in the coordinates that turn the target into the identity matrix when the fit shrinks.
tgt: Target of the shrinkage in the units of the data, ornothing.
intensity: Shrinkage intensity or its rule, ornothing.
centre: Fixed centre of the fit, ornothingfor a joint location.
Constructors
MCDSample( X::MatNum, Z::MatNum, tgt::Option{<:MatNum}, intensity, centre::Option{<:VecNum}) -> MCDSampleRelated
References
- [119]
- M. Hubert, P. J. Rousseeuw and T. Verdonck. A deterministic algorithm for robust location and scatter. Journal of Computational and Graphical Statistics 21, 618–637 (2012).
- [120]
- P. J. Rousseeuw and K. Van Driessen. A fast algorithm for the minimum covariance determinant estimator. Technometrics 41, 212–223 (1999).