Vector to scalar measures: private API
Summary statistics
Some estimators and constraints reduce a vector to one number. A field of type Num_VecToScaM can hold a fixed number, a VectorToScalarMeasure, or a function that does the reduction.
PortfolioOptimisers.Num_VecToScaM — Type
const Num_VecToScaM = Union{Number, VectorToScalarMeasure, Function}Union of a number, a VectorToScalarMeasure and a Function.
A function or a field with this type accepts all three. A caller can give a fixed number, an object that implements the VectorToScalarMeasure interface, or a plain reduction function. vec_to_real_measure returns a Number with no change, sends a VectorToScalarMeasure to its reduction, and applies a Function to the vector.
Related
A summary of a correlation column skips the correlations that the data do not define.
PortfolioOptimisers.finite_vec_to_real_measure — Function
finite_vec_to_real_measure(
measure::Union{Function, Number, VectorToScalarMeasure},
val::AbstractVector{<:Union{Number, AbstractJuMPScalar}}
) -> Any
Collapse the finite entries of val into one number with measure.
A non-finite entry is a value that the data do not define, such as the correlation with a constant column. It carries no information about the summary, so the function skips it. The measure reads the finite entries alone. Its observation weights lose the weights of the skipped entries through obs_weights_view, so each kept entry keeps its own weight. A DynamicAbstractWeights stays, because it resolves on the entries that the measure reads.
A measure that a user writes, with weights and with no method of obs_weights_view, keeps all of its weights. Its weights then have more entries than the vector that it reads.
Algorithm
- Mark the finite entries of
valinfin. - When every entry is finite, return
vec_to_real_measure(measure, val). When no entry is finite, the function has no entry to skip to, and it returns the same value. The non-finite entries then reach the measure. - Otherwise, cut the weights of
measuretofinwithobs_weights_view. Return the value of the cut measure onval[fin].
Arguments
measure: The measure that collapses the vector: a number, aVectorToScalarMeasure, or a function.val: The vector to collapse.
Returns
val::Number: The value ofmeasureon the finite entries ofval.
Examples
julia> PortfolioOptimisers.finite_vec_to_real_measure(MeanValue(), [1.0, NaN, 3.0])2.0julia> PortfolioOptimisers.finite_vec_to_real_measure(MeanValue(; w = aweights([1.0, 5.0, 3.0])), [1.0, NaN, 3.0])2.5Related