Search cross-validation: private API

PortfolioOptimisers.pipeline_lensFunction
pipeline_lens(pipe::Pipeline, key) -> lens

Resolve a tuning key into an Accessors.jl lens on a Pipeline.

A leading step name resolves to the step's position (name → index → property path): "gap_fill.fill" targets the fill field of the step named "gap_fill", and a bare step name ("gap_fill", :gap_fill) or an integer position targets the whole step — swapping entire estimators as grid values needs no extra syntax. A key whose leading segment is not a step name falls through to parse_lens only when it is rooted at steps, so raw property paths ("steps[2].fill", "steps[2]") and prebuilt lenses keep working.

A key that misses the step-name table and is not a path rooted at steps (see is_pipeline_raw_path) is rejected instead — "gapfill" is a typo, not a path, and "names[1]" addresses the step-name table, so reinterpreting either as a property access on the Pipeline struct tunes nothing at best and writes into a real field at worst. The Symbol arm fails closed on the same rule, and tests for a dot as well, because a symbol key never reaches Meta.parse.

Arguments

  • pipe: The pipeline being tuned.
  • key: A GSCVKey: step name with optional trailing property path, integer step position, raw property path, Expr/Symbol, or a prebuilt lens.

Returns

  • lens: A composed Accessors.jl lens rooted at the pipeline.

Related

source
PortfolioOptimisers.is_pipeline_raw_pathFunction
is_pipeline_raw_path(key::AbstractString) -> Bool

Return true when key is a raw property path rooted at the steps field of a Pipeline"steps[1]", "steps[2].fill".

The predicate the AbstractString arm of pipeline_lens uses to separate a raw property path from a typo when the leading segment misses the step-name table. It names the one root a path may address instead of rejecting one shape. A Pipeline holds two fields, names and steps, and only steps holds the estimators a grid tunes, so "names[1]" is refused with "gapfill". An admitted key falls through to parse_lens.

The Symbol arm tests for a dot as well, because a symbol key is not run through Meta.parse: an index in a symbol is a character in a property name, not a lens path.

Related

source
PortfolioOptimisers.pipeline_lens_val_gridFunction
pipeline_lens_val_grid(
    pipe::Pipeline,
    estval::AbstractVector{<:Pair{<:Any, <:AbstractVector}}
) -> Tuple{Any, Any}

Build the (lens, value) grid for tuning a Pipeline — the pipeline-aware counterpart of lens_val_grid, resolving keys through pipeline_lens so step names and positions address steps.

Arguments

  • pipe: The pipeline being tuned.
  • estval: The parameter grid: key => values pairs, a dict, or a vector of either (independent grids concatenated).

Validation

  • The candidate count must not exceed RESOURCE_LIMITS[].max_search_grid, asserted by assert_search_grid_cap before the product is materialised.

Returns

  • (lenses, vals): Per-candidate lens vectors and value tuples.

Related

source