SoftTreeLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
A differentiable soft decision tree layer for GANDALF and similar architectures.
Inheritance: LayerBase<T> → SoftTreeLayer<T>
Implements: IShapeContract
For Beginners
A soft tree is like a fuzzy decision tree:
- Regular tree: “Is age > 30? Go left or right”
- Soft tree: “Is age > 30? Go 70% left, 30% right”
The soft splits make the tree trainable with neural network methods while maintaining the interpretable structure of decision trees.
How It Works
This layer implements a soft (differentiable) decision tree that can be trained with gradient descent. Each internal node uses soft splits (sigmoid) instead of hard decisions, allowing gradients to flow through the tree structure.
Constructors
| Constructor | Summary |
|---|---|
SoftTreeLayer(int inputDim, int depth, int outputDim, double temperature, double initScale) |
Initializes a new soft tree layer. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int Depth { get; } |
Gets the tree depth. |
int NumLeaves { get; } |
Gets the number of leaf nodes in this tree. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
T[] GetFeatureImportance() |
Gets feature importance based on split weight magnitudes. |
void ClearGradients() |
|
void ResetState() |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
|
void UpdateParameters(Vector<T> parameters) |
|
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |