A lightweight, user-friendly Neural Network written from scratch without external libraries. It includes forward- and backpropagation as well as gradient descent.
- 2D Matrix Library (
Matrix2D): Custom implementation supporting Matrix Multiplication, Addition, Subtraction, Transposition, and more which are required for Neural Networks. - Layers: Implements a base
Layerclass as well as two subclasses (LinearLayerandActivationLayer). - Activation Functions: Built-in implementations of
ReLU,Tanh, andSigmoidalongside their derivatives. - Loss Functions:
MSE(Mean Squared Error) andCEL(Cross-Entropy Loss) also come built-in. - Flexible Network Architecture: Features a
Sequentialclass similar to that of Pytorch, where you can customize the layout of your Neural Network easily.
- C++ Compiler supporting C++23
- GoogleTest (only required for running the test suite)
You can quickly compile and run the main application by using the included Makefile.
make
./main.exeThe same applies for compiling and running the tests.
make tests
./tests.exe#include "matrix.h"
#include "nn.h"
int main() {
Matrix2D inputs;
Matrix2D outputs;
inputs.addRow({0.1, 0.2});
outputs.addRow({0.2});
// Define Model Architecture
Sequential model(
LinearLayer(2, 4),
ActivationLayer(
NeuralNet::ApplyTanh,
NeuralNet::DTanh
),
LinearLayer(4, 1)
);
// Train the model (inputs, targets, epochs, learning rate)
model.train(inputs, outputs, 1000, 0.1);
return 0;
}