Grid search cross validation: private API

PortfolioOptimisers.lens_val_grid — Method
lens_val_grid(estval::AbstractVector{<:Pair{<:Any, <:AbstractVector}})
lens_val_grid(estval::AbstractDict{<:Any, <:AbstractVector})
lens_val_grid(estvals::AbstractVector{<:Union{AbstractVector{<:Pair{<:Any, <:AbstractVector}},
                                              AbstractDict{<:Any, <:AbstractVector}}})

Build the grid of a search, the lenses and the values of every candidate.

One parameter set gives the Cartesian product of the value vectors of its keys. A vector of parameter sets gives the concatenation of their grids, so the values of two sets never combine into one candidate.

Mathematical definition

\[\begin{align} \Theta &= V_1 \times V_2 \times \cdots \times V_k\,, \\ |\Theta| &= \prod_{j=1}^{k} |V_j|\,, \\ \Theta &= \Theta^{(1)} \Vert \Theta^{(2)} \Vert \cdots \Vert \Theta^{(m)}\,, \\ |\Theta| &= \sum_{l=1}^{m} |\Theta^{(l)}|\,. \end{align}\]

Where:

  • $\Theta$: Search grid, the sequence of grid points that lens_val_grid builds from p. For a Pipeline, pipeline_lens_val_grid builds it.
  • $V_j$: Candidate values of the $j$-th key of one parameter set, the value vector that the set gives the key.
  • $k$: Key count of one parameter set.
  • $\Theta^{(l)}$: Grid of the $l$-th parameter set, by the first two equations.
  • $m$: Parameter set count, the count of the parameter sets that the search concatenates.
  • $\Vert$: Concatenation of two sequences.

The first two equations hold for one parameter set, and the last two for a vector of sets. An empty $V_j$ makes the product empty.

Algorithm

For one parameter set, estval:

  1. Check the count of the grid through assert_search_grid_cap, before the function builds the product.
  2. Collect the product of the value vectors into vals, one tuple per grid point.
  3. Parse each key into a lens through parse_lens, and repeat that vector of lenses once per entry of vals, giving lenses.

For a vector of parameter sets, estvals:

  1. Build the grid of each set by the steps above, giving lenses_vals.
  2. Concatenate the lenses and the values of the sets in the order of estvals, giving lenses and vals.
  3. Check length(vals) through assert_search_grid_cap.

Arguments

  • estval: One parameter set, a vector of key => values pairs or a dictionary from key to values. A key is a property path that parse_lens reads, such as "opt.l1".
  • estvals: A vector of parameter sets, each of the form of estval.

Validation

  • Every value vector holds at least one value, through assert_search_grid_cap.
  • The grid holds at most RESOURCE_LIMITS[].max_search_grid candidates, through assert_search_grid_cap. The function checks the count of a set before it builds the product of that set. Under estvals it checks each set as it builds that set, and the sum of the sets after the concatenation.

Returns

  • lenses::AbstractVector: One vector of lenses per grid point.
  • vals::AbstractVector{<:Tuple}: One tuple of values per grid point, in the order of the lenses at that point. Inside one set the first key varies fastest, and a dictionary gives its keys in its own order of iteration.

Related

source