NTDLS.Determinet Usage
A multilayer perceptron neural network for .NET with named inputs, Adam optimization and compact model save/load.
NTDLS.Determinet
What it is. A versatile multilayer perceptron (fully-connected feed-forward) neural network for .NET. It ships with 18 built-in activation functions, SGD or Adam (AdamW) optimization, single-sample or mini-batch training, named input/output labels, and compact save/load of the whole model including optimizer state so training can be resumed exactly. Inference via Forward() is thread-safe.
When to reach for it. You want to train and run small-to-medium MLPs in-process - classification, regression, anomaly detection on tabular features - without pulling in a heavyweight ML framework. Skip it if you need convolutional or recurrent architectures; Determinet is fully-connected only.
Getting started
Configure layers, build the network, then feed it samples. Here is a network that learns XOR:
using NTDLS.Determinet;
using NTDLS.Determinet.Types;
using static NTDLS.Determinet.DniParameters;
// 2 inputs -> 8 hidden (Tanh) -> 2 outputs (SoftMax), labeled.
var configuration = new DniConfiguration { LearningRate = 0.01 };
configuration.AddInputLayer(2);
configuration.AddIntermediateLayer(8, DniActivationType.Tanh);
configuration.AddOutputLayer(2, DniActivationType.SoftMax, ["false", "true"]);
var dni = new DniNeuralNetwork(configuration);
dni.Parameters.Set(Network.UseAdamOptimization, true);
// Each sample is (inputs, expected outputs); one-hot for classification.
(double[] inputs, double[] expected)[] samples =
[
([0, 0], [1, 0]),
([0, 1], [0, 1]),
([1, 0], [0, 1]),
([1, 1], [1, 0]),
];
for (int epoch = 0; epoch < 500; epoch++)
{
foreach (var (inputs, expected) in samples)
{
double loss = dni.Train(inputs, expected);
}
}
Predictions come back as raw values - probabilities when the output layer is SoftMax - or as labeled results:
double[] outputs = dni.Forward([1, 0]);
int index = outputs.IndexOfMaxValue(out double confidence); // 1, ~0.99
// Or use the output labels directly.
dni.Forward([1, 0], out var labels);
var best = labels.Max();
Console.WriteLine($"{best.Key} ({best.Value:n2})"); // true (0.99)
For regression, use an Identity output layer (squared-error loss is applied automatically). For smoother training on larger datasets, call TrainBatch(batch) instead of Train() per sample. The whole model - weights, configuration, parameters and optimizer state - round-trips through:
dni.SaveToFile("xor.dni");
var loaded = DniNeuralNetwork.LoadFromFile("xor.dni");
NuGet: NTDLS.Determinet