This project is a modular neural network implementation in C++ designed for educational, experimental, and practical machine learning tasks. It provides core components for building, training, and evaluating neural networks, with a focus on extensibility and clarity. The codebase demonstrates how to implement and train a simple feedforward neural network for regression tasks, such as predicting housing prices.
- Customizable feedforward neural network architecture
- Support for various activation functions (ReLU, Sigmoid)
- Mean Squared Error (MSE) loss function
- Stochastic Gradient Descent (SGD) optimizer
- Example demonstration with synthetic data
- Integration with Eigen for efficient matrix operations
- C++20 compatible compiler (e.g., clang++, g++)
- Eigen library (install via Homebrew:
brew install eigen)
- Clone the repository:
git clone <repo-url> cd neural_network
- Build the demo:
clang++ -g -std=c++20 src/main.cpp -I/opt/homebrew/include/eigen3 -o neural_network
- Run the demo:
./neural_network
src/— Source code for neural network layers, activations, loss functions, optimizer, and main demoNeuralNetwork.cpp— Main neural network classLinearLayer.cpp— Linear layer implementationActivationFun.cpp— Activation functions (ReLU, Sigmoid)LossFun.cpp— Loss functions (MSE)Optimizer.cpp— Optimizer (SGD)main.cpp— Demonstration and entry point
include/— Header files for all componentsdata/— Example datasets (CSV files)build/— Build artifactsNN.so— Python bindings (if applicable)README.md— Project documentation
The demo in main.cpp generates synthetic data with a known linear relationship, trains the neural network, and prints predictions before and after training to show learning progress.