PiecewiseLinearEncodingLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Piecewise linear encoding (PLE) of numerical features, from Gorishniy, Rubachev and Babenko, “On Embeddings for Numerical Features in Tabular Deep Learning” (NeurIPS 2022).

Inheritance: LayerBase<T> → PiecewiseLinearEncodingLayer<T>

Implements: IShapeContract

For Beginners

Think of this like creating “bins” for each number. A value fully passes every bin below it (1), sits partway through its own bin, and has not reached the bins above it (0), so nearby values get nearby encodings while the model can still treat different ranges differently.

How It Works

Each feature x is split into T bins by edges b_0 < b_1 < … < b_T, and becomes the T values e_t = clamp((x - b_{t-1}) / (b_t - b_{t-1})): 0 below the bin, 1 above it, linear inside. The first bin is not clamped below and the last is not clamped above, exactly as the paper defines it, so a value outside the edges still moves the encoding. The output is [batch, features * T].

The paper builds the edges from quantiles of the training data and keeps them fixed; call FitBoundaries with the training features to do the same. Until then the edges are evenly spaced over [-2, 2], which suits standardized inputs. The edges are persisted state, not trainable parameters.

Constructors

Constructor Summary
PiecewiseLinearEncodingLayer(int numFeatures, int numBins) Initializes piecewise linear encoding with evenly spaced edges over [-2, 2].

Properties

Property Summary
bool SupportsTraining { get; }
int NumBins { get; } The number of bins each feature is split into.
int OutputDimension { get; } Gets the output dimension (numFeatures * numBins).

Methods

Method Summary
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers()
void FitBoundaries(Tensor<T> features) Sets each feature’s edges to the quantiles of features at 0, 1/T, …, 1, as the paper does.
void ResetState()
void UpdateParameters(T learningRate)