GANDALFNetwork<T>
Models & Types · AiDotNet.NeuralNetworks.Tabular
GANDALF (Gated Additive Neural Decision Forest) neural network for tabular data.
Inheritance: NeuralNetworkBase<T> → TabularNeuralNetworkBase<T> → GANDALFNetwork<T>
For Beginners
GANDALF works like a smart forest of decision trees:
Architecture:
- Gating Network: Learns which features are important (using FullyConnectedLayers)
- Neural Decision Trees: Trees with learnable soft split decisions (SoftTreeLayers)
- Additive Ensemble: Tree outputs are summed for final prediction
Key insight: Traditional trees have hard decisions (left or right). GANDALF uses soft decisions where a sample partially goes both ways, making the whole thing differentiable and trainable with gradient descent.
How It Works
GANDALF combines gated feature selection with an ensemble of differentiable decision trees. This implementation follows the standard neural network architecture pattern with:
- Proper inheritance from NeuralNetworkBase
- Layer-based architecture using ILayer components
- Engine-based tensor operations for CPU/GPU acceleration
- Full autodiff and JIT compilation support
Reference: “GANDALF: Gated Adaptive Network for Deep Automated Learning of Features” (2022)
Example
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var options = new GANDALFOptions<double> { NumFeatures = 20, NumTrees = 64, TreeDepth = 6 };
var input = Tensor<float>.CreateRandom(new[] { 1, 20 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new GANDALFNetwork<float>(architecture))
.Build(trainX, trainY);
var output = result.Predict(input);
Constructors
| Constructor | Summary |
|---|---|
GANDALFNetwork() |
Initializes a new GANDALF network with the specified architecture. |
GANDALFNetwork(NeuralNetworkArchitecture<T> architecture, GANDALFOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Properties
| Property | Summary |
|---|---|
GANDALFOptions<T> Options { get; } |
Gets the GANDALF-specific options. |
int NumTrees { get; } |
Gets the number of trees in the ensemble. |
int TreeDepth { get; } |
Gets the tree depth. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
Gets the learned feature importance from the soft decision trees. |
ModelMetadata<T> GetModelMetadata() |