Feature selector
A feature selector names the panel fields that a feature matrix stacks. feature_matrix, feature_labels and LabelGroup are documented with the feature distance that reads the matrix. This page documents the stack of every field of a panel, and the method that a new kind of panel field adds to it.
A static panel stacks to assets × features. A time-varying panel stacks to assets × features × observations, with the observations on the last axis, so the matrix of one observation is one contiguous block.
PortfolioOptimisers.panel_feature_matrix — Function
panel_feature_matrix(pnl::Union{Nothing, AssetPanel{Nothing}}) -> Tuple{Nothing, Nothing}
panel_feature_matrix(pnl::AssetPanel) -> Tuple{Vector{String}, Array}Derive the Feature Matrix an AssetPanel's Panel Fields stack into, and name its columns.
Input data that holds no panel, or a panel with no Panel Field, derives nothing. So the first method answers with two nothing values, and no consumer needs a branch of its own.
Nothing stores the result. A distance measures a Feature Matrix, so the distance builds it and drops it after the measure. The panel is the data, and the matrix is one view of it.
The column order is the Panel Field order. Within one Panel Field, its value columns come first and its observed-mask columns after. A numeric or a categorical Panel Field has one observed-mask column, and a tensor Panel Field has one per label. A static panel gives an assets × features matrix, and a time-varying one an assets × features × observations matrix.
Algorithm
The method that Julia selects decides whether there is anything to derive.
- Walk the Panel Fields in order. Claim each one's value columns from
panel_field_labels, then its observed-mask columns frompanel_field_observed_labelswhen it carries a mask. - Allocate the matrix as zeros,
assets × features, orassets × features × observationsover the panel's own observation axis, in the typepanel_value_eltypederives over the Panel Fields. - Write each Panel Field's values with
panel_field_stack!and its mask withpanel_field_stack_observed!.
Arguments
pnl: The Asset Panel.
Returns
nz::Vector{String}: One name per column of the derived Feature Matrix.Z::Array: The derived Feature Matrix, in the typepanel_value_eltypederives over the Panel Fields it stacks.
Related
PortfolioOptimisers.panel_field_stack! — Function
panel_field_stack!(Z::AbstractArray, f::NumericPanelField, cols::VecInt) -> nothing
panel_field_stack!(Z::AbstractArray, f::CategoricalPanelField, cols::VecInt) -> nothing
panel_field_stack!(Z::AbstractArray, f::TensorPanelField, cols::VecInt) -> nothingWrite one Panel Field's value columns into a derived Feature Matrix.
Z is allocated as zeros, which is what makes a one-hot column correct: the categorical method writes only the 1s.
Algorithm
The method that Julia selects is the algorithm.
NumericPanelField: write the values into the single column.CategoricalPanelField: write a1into the column its code names, for each cell.TensorPanelField: write one label slice per column.
Arguments
Z: The derived Feature Matrix under construction.f: The Panel Field.cols: The columns the Panel Field claims, in order.
Returns
nothing.
Related
The private page documents the other names of this topic.