How naowalrahman/neural-network works
Project type and purpose
• This is a standalone C++ library/tool that implements a fully functional feedforward neural network, including weight initialization (Glorot uniform), multiple activation functions, stochastic gradient descent training via backpropagation, and example applications (XOR, MNIST).
• It is not a web app or microservice; it’s a compute-intensive command-line tool/library.
File structure
• Top‐level source files:
• Main.cpp – entry point; sets up network, loads data, runs training/evaluation
• NeuralNetwork.hpp/.cpp – orchestrates layers, forward pass, backpropagation
• Layer.hpp/.cpp – defines a single layer: neurons, weights, biases, activation
• Matrix.hpp/.cpp – lightweight matrix operations (vector/matrix math)
• Functions.hpp/.cpp – activation functions and derivatives
• Functions.cpp – contains sigmoid, ReLU, etc.
• backpropagation.md – theoretical reference
• mnist.txt – serialized pre-trained weights for example evaluation
• CMakeLists.txt, makefile, build.sh – build configuration/scripts
• There is no external dependency; everything lives in C++ STL modules.
README for insights
• Describes goals (pure C++ neural network), training setups (XOR, MNIST), build instructions, to-do list.
a. Main components
• Data Input/Loader
• Core Math Module (Matrix operations)
• Activation Module (Functions)
• Layer Module (Layer)
• Network Module (NeuralNetwork)
• Training Engine (drive forward+backprop loops, SGD)
• Application/CLI (Main.cpp)
• Build/Deployment (CMake, build.sh, makefile)
b. Relationships & interactions
• Application invokes Data Loader → provides training/test datasets
• Application instantiates NeuralNetwork → internally creates Layer objects
• NeuralNetwork uses Matrix and Functions modules for calculations
• Training Engine sits inside NeuralNetwork: repeats forward pass → compute loss → backpropagate → update weights
• NeuralNetwork outputs results → Application logs accuracy/loss or stores weights in mnist.txt
• Build tools compile all modules into an executable or library
c. Architectural patterns & principles
• Modular separation: math, activation, layers, network, application
• Single responsibility per module
• Data flow pipeline: Input → Forward → Loss → Backprop → Update → Output
• Dependency direction: high-level modules (Application, Training Engine) depend on low-level modules (Matrix, Functions)
d. Relevant technologies/frameworks
• C++17/20 (STL only)
• CMake, Make, custom shell script build.sh
• No third-party libraries
Detailed elements to capture
• Feedforward sequence: Input → Layer1 → … → LayerN → Output
• Feedback loop for backpropagation inside the Training Engine
• That activation functions and matrix multiplications are internal to each Layer
• Build pipeline: source files → CMake/Make → executable
• Call out that no external libraries are used, so all dependencies are internal modules.