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_gridbuilds fromp. For aPipeline,pipeline_lens_val_gridbuilds 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:
- Check the count of the grid through
assert_search_grid_cap, before the function builds the product. - Collect the product of the value vectors into
vals, one tuple per grid point. - Parse each key into a lens through
parse_lens, and repeat that vector of lenses once per entry ofvals, givinglenses.
For a vector of parameter sets, estvals:
- Build the grid of each set by the steps above, giving
lenses_vals. - Concatenate the lenses and the values of the sets in the order of
estvals, givinglensesandvals. - Check
length(vals)throughassert_search_grid_cap.
Arguments
estval: One parameter set, a vector ofkey => valuespairs or a dictionary from key to values. A key is a property path thatparse_lensreads, such as"opt.l1".estvals: A vector of parameter sets, each of the form ofestval.
Validation
- Every value vector holds at least one value, through
assert_search_grid_cap. - The grid holds at most
RESOURCE_LIMITS[].max_search_gridcandidates, throughassert_search_grid_cap. The function checks the count of a set before it builds the product of that set. Underestvalsit 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
parse_lensassert_search_grid_cappipeline_lens_val_grid: the grid of aPipelinesearch, whose keys can name a step.GridSearchCrossValidationsearch_cross_validation