SparseKernelExpander

On-the-fly polynomial kernel expansion of sparse input.

This will perform polynomial kernel expansion of a set of sparse features based on a group attribute of this features. The features fed to this layer need to be a SparseFG[]. It assumes that the feature ids are uniform random numbers (hashes) so that we can efficiently generate a cross-feature hash by just XOR-ing together the single hashes of the monomial. This layer is meant to be used as part of a NeuralNet() topology at test time, but it's preferable to run the expansion outside the net at training time so that it can be run only once while building the dataset. This will avoid rebuilding the cross-features at every pass during training.

class SparseKernelExpander : InputLayer {
short[] here;
uint[][] single_hashes;
float[][] single_vals;
ushort[][] cross2build;
uint[] hash_buff;
float[] val_buff;
string _cross_features_str;
uint _max_group_id;
uint _buff_single_feats_sz;
}

Constructors

this
this(ulong dim_out, string cross_feats_str, uint max_group_id = 100u, uint buff_single_feats_sz = 50_000)

Instantiate a new SparseKernelExpander layer.

Examples

// polynomial kernel (x_1 * x_3, x_1 * x_2 * x_4) in a 1k dimensional space:
auto l = SparseKernelExpander(1_000, "1^3,1^2^4");

Meta