A neural network library built from scratch in C++17. No external ML dependencies.
Supports configurable network topologies, multiple activation functions, three optimizers (SGD, SGD with momentum, Adam), two loss functions (MSE, cross-entropy), and training utilities like validation splits and early stopping.
make buildRequires CMake 3.15+ and a C++17 compiler.
./build/main train # train using config/train.json
./build/main test # evaluate using config/test.json
./build/main demo # run XOR demoTraining and testing are configured through JSON files in config/.
{
"topology": [2, 8, 1],
"learningRate": 0.05,
"momentum": 0.9,
"epochs": 5000,
"trainingData": "data/train.csv",
"weightsFile": "weights/model.weights",
"lossExport": "weights/loss.csv",
"hiddenActivation": "relu",
"outputActivation": "sigmoid",
"lossFunction": "mse",
"optimizer": "sgd_momentum",
"validationSplit": 0.2,
"patience": 50
}Activations: relu, leaky_relu, sigmoid, tanh, linear
Optimizers: sgd, sgd_momentum, adam
Loss functions: mse, cross_entropy
Early stopping: Set validationSplit > 0 and patience > 0. Training stops if validation loss does not improve for patience consecutive epochs.
CSV files in data/. Columns are split based on the topology: the first N columns are inputs (where N = first layer size), remaining columns are targets.
0,0,0
0,1,1
1,0,1
1,1,0
For XOR with topology [2, 8, 1]: 2 input columns, 1 target column.
headers/
Neuron.h Activation functions and derivatives
Layer.h Neuron container with matrix conversion
Matrix.h Linear algebra operations, weight initialization
NeuralNetwork.h Network core: forward pass, backprop, optimizers
NetworkTrainer.h
NetworkTester.h
NetworkDemo.h
utils/
DataLoader.h CSV loading, normalization, shuffling, train/val split
src/
NeuralNetwork/
constructor.cpp
FeedForward.cpp
BackPropagation.cpp
ErrorFunctions.cpp
train.cpp
mutators.cpp
weightsIO.cpp
IOHelpers.cpp
MIT