Deep Learning Algorithm Implementations 1.0.0
C++ implementations of fundamental deep learning algorithms
Loading...
Searching...
No Matches
Deep Learning & Machine Learning Algorithm Implementations

A comprehensive C++ library for implementing and learning both deep learning and traditional machine learning algorithms from scratch, featuring modern C++ design patterns, extensive documentation, and automated CI/CD.

CI Documentation [License](LICENSE)

๐ŸŽฏ Project Goals

This project provides a structured framework for implementing fundamental deep learning and traditional machine learning algorithms in C++. It's designed for educational purposes and hands-on learning of:

Deep Learning Algorithms:

  • Neural network architectures (Feedforward, CNN, RNN, LSTM, GRU)
  • Optimization algorithms (SGD, Adam, RMSprop)
  • Activation functions (ReLU, Sigmoid, Tanh, Softmax, LeakyReLU)
  • Loss functions (MSE, Cross-entropy, Hinge loss)

Traditional Machine Learning Algorithms:

  • Dimensionality reduction (Principal Component Analysis)
  • Clustering algorithms (K-Means)
  • Classification algorithms (Support Vector Machine)

Utilities:

  • Mathematical utilities and high-performance matrix operations
  • Data processing with comprehensive loading and preprocessing utilities

๐Ÿš€ Key Features

  • ๐Ÿ“š Comprehensive Documentation: Full Doxygen documentation with examples and mathematical descriptions
  • ๐Ÿ”ง Modern C++: Uses C++23 features and best practices
  • ๐Ÿงช Tested: Comprehensive test suite with Google Test
  • ๐Ÿ”„ CI/CD: Automated testing, static analysis, and documentation deployment
  • ๐Ÿ“Š Performance: Optimized matrix operations and memory management
  • ๐ŸŽ“ Educational: Detailed comments and learning-focused design

๐Ÿ“ Project Structure

deep-learning-algo-impls/
โ”œโ”€โ”€ include/ # Header files
โ”‚ โ”œโ”€โ”€ neural_networks/ # Deep learning architectures
โ”‚ โ”‚ โ”œโ”€โ”€ feedforward.hpp # Feedforward neural networks
โ”‚ โ”‚ โ”œโ”€โ”€ cnn.hpp # Convolutional neural networks
โ”‚ โ”‚ โ””โ”€โ”€ rnn.hpp # Recurrent neural networks (RNN/LSTM/GRU)
โ”‚ โ”œโ”€โ”€ optimization/ # Optimization algorithms
โ”‚ โ”‚ โ””โ”€โ”€ optimizers.hpp # SGD, Adam, RMSprop optimizers
โ”‚ โ”œโ”€โ”€ activation/ # Activation functions
โ”‚ โ”‚ โ””โ”€โ”€ functions.hpp # ReLU, Sigmoid, Tanh, Softmax
โ”‚ โ”œโ”€โ”€ loss/ # Loss functions
โ”‚ โ”‚ โ””โ”€โ”€ functions.hpp # MSE, Cross-entropy, Hinge loss
โ”‚ โ”œโ”€โ”€ ml/ # Traditional ML algorithms
โ”‚ โ”‚ โ”œโ”€โ”€ ml.hpp # Main ML header (includes all algorithms)
โ”‚ โ”‚ โ”œโ”€โ”€ pca.hpp # Principal Component Analysis
โ”‚ โ”‚ โ”œโ”€โ”€ kmeans.hpp # K-Means clustering
โ”‚ โ”‚ โ””โ”€โ”€ svm.hpp # Support Vector Machine
โ”‚ โ””โ”€โ”€ utils/ # Utility classes
โ”‚ โ”œโ”€โ”€ matrix.hpp # Matrix operations
โ”‚ โ””โ”€โ”€ data_loader.hpp # Data loading and preprocessing
โ”œโ”€โ”€ src/ # Implementation files
โ”‚ โ”œโ”€โ”€ neural_networks/ # Deep learning implementations
โ”‚ โ”œโ”€โ”€ optimization/ # Optimizer implementations
โ”‚ โ”œโ”€โ”€ activation/ # Activation function implementations
โ”‚ โ”œโ”€โ”€ loss/ # Loss function implementations
โ”‚ โ”œโ”€โ”€ ml/ # Traditional ML implementations
โ”‚ โ”‚ โ”œโ”€โ”€ pca.cpp # PCA implementation
โ”‚ โ”‚ โ”œโ”€โ”€ kmeans.cpp # K-Means implementation
โ”‚ โ”‚ โ””โ”€โ”€ svm.cpp # SVM implementation
โ”‚ โ””โ”€โ”€ utils/ # Utility implementations
โ”œโ”€โ”€ tests/ # Unit tests
โ”‚ โ”œโ”€โ”€ test_feedforward.cpp # Neural network tests
โ”‚ โ”œโ”€โ”€ test_matrix.cpp # Matrix operation tests
โ”‚ โ””โ”€โ”€ test_optimizers.cpp # Optimizer tests
โ”œโ”€โ”€ .github/workflows/ # CI/CD pipelines
โ”‚ โ””โ”€โ”€ ci.yml # Automated testing workflow
โ”œโ”€โ”€ CMakeLists.txt # Build configuration
โ”œโ”€โ”€ Doxyfile # Documentation configuration
โ””โ”€โ”€ main.cpp # Example usage

๐Ÿ“– Documentation

Full API documentation is automatically generated using Doxygen with the modern Doxygen Awesome theme and deployed to GitHub Pages:

๐Ÿ”— View Documentation

The documentation features:

  • Modern, clean design with improved readability <mcreference link="https://jothepro.github.io/doxygen-awesome-css/" index="1">1</mcreference>
  • Mobile-responsive interface for documentation on any device <mcreference link="https://jothepro.github.io/doxygen-awesome-css/" index="1">1</mcreference>
  • Dark mode support for comfortable viewing <mcreference link="https://jothepro.github.io/doxygen-awesome-css/" index="1">1</mcreference>
  • Enhanced navigation with sidebar treeview
  • Complete API reference with examples
  • Mathematical descriptions of algorithms
  • Usage patterns and best practices
  • Implementation guides and tutorials

๐Ÿš€ Quick Start

Matrix Operations

#include "utils/matrix.hpp"
using namespace dl::utils;
// Create matrices
Matrix<double> a(3, 3, 1.0); // 3x3 matrix filled with 1.0
Matrix<double> b = Matrix<double>::random(3, 3); // Random 3x3 matrix
// Matrix operations
auto c = a * b; // Matrix multiplication
auto d = a + b; // Element-wise addition
auto e = a.transpose(); // Transpose
Matrix utility class for deep learning operations.

Principal Component Analysis

#include "utils/pca.hpp"
#include "utils/matrix.hpp"
using namespace dl::utils;
// Create a dataset
MatrixD data({
{2.5, 2.4},
{0.5, 0.7},
{2.2, 2.9},
{1.9, 2.2},
{3.1, 3.0}
});
// Create a PCA object
PCAD pca;
// Fit the PCA model to the data
pca.fit(data);
// Get the explained variance ratio
auto variance_ratio = pca.explained_variance_ratio();
for (size_t i = 0; i < variance_ratio.size(); ++i) {
std::cout << "Component " << i << ": " << variance_ratio[i] << std::endl;
}
// Reduce dimensions (e.g., to 1D)
MatrixD reduced_data = pca.transform(data, 1);
void fit(const Matrix< T > &data)
Fit the K-Means model to the data.
Definition kmeans.cpp:20
PCA< double > PCAD
Definition pca.hpp:110

Neural Network Training

#include "neural_networks/feedforward.hpp"
using namespace dl;
// Define network architecture
std::vector<size_t> layers = {784, 128, 64, 10}; // MNIST-like network
neural_networks::FeedforwardNetwork network(layers);
// Load and preprocess data
auto [features, labels] = utils::CSVLoader::load_features_labels(
"data.csv", {0, 1, 2, 3}, {4});
utils::Dataset<double> dataset(features, labels);
// Train the network
network.train(dataset, epochs=100, learning_rate=0.01);
// Make predictions
auto predictions = network.predict(test_features);
Data loading and preprocessing utilities for deep learning.

Data Loading and Preprocessing

using namespace dl::utils;
// Load CSV data
auto data = CSVLoader::load_csv("dataset.csv");
// Preprocess data
auto normalized = Preprocessor::normalize(data, 0.0, 1.0);
auto standardized = Preprocessor::standardize(data);
// Split dataset
auto [train, val, test] = Preprocessor::train_val_test_split(
dataset, 0.7, 0.15);
// Create data loader for batch processing
DataLoader<double> loader(train, batch_size=32, shuffle=true);
while (loader.has_next()) {
auto [batch_features, batch_labels] = loader.next_batch();
// Process batch...
}

๐Ÿ› ๏ธ Prerequisites

  • C++23 compatible compiler (GCC 11+, Clang 14+, or MSVC 2022+)
  • CMake 3.31 or higher
  • Google Test for unit testing
  • Git for version control

Installing Dependencies

Ubuntu/Debian

sudo apt-get update
sudo apt-get install -y cmake ninja-build libgtest-dev
sudo apt-get install -y gcc-11 g++-11 # or clang-14

macOS

brew install cmake ninja googletest

Windows (vcpkg)

vcpkg install gtest

๐Ÿš€ Building the Project

  1. Clone the repository
    git clone <repository-url>
    cd deep-learning-algo-impls
  2. Configure and build
    cmake -B build -DCMAKE_BUILD_TYPE=Release
    cmake --build build
  3. Run tests
    cd build
    ctest --output-on-failure
  4. Run the main executable
    ./build/deep_learning_algo_impls

๐Ÿ“š Implementation Guide

This project provides header files with comprehensive TODO comments and example structures. Each algorithm should be implemented following these guidelines:

1. Neural Networks

  • Feedforward Networks: Implement basic multilayer perceptrons with configurable architectures
  • CNNs: Add convolution, pooling, and feature extraction layers
  • RNNs: Implement sequence processing with LSTM and GRU variants

2. Optimization

  • SGD: Basic gradient descent with momentum support
  • Adam: Adaptive learning rates with bias correction
  • RMSprop: Root mean square propagation

3. Mathematical Utilities

  • Matrix Class: Efficient matrix operations for linear algebra
  • Activation Functions: Differentiable activation functions
  • Loss Functions: Various loss functions for different tasks

4. Data Processing

  • Data Loaders: CSV and image data loading utilities
  • Preprocessing: Normalization, standardization, and augmentation

๐Ÿงช Testing Strategy

The project includes comprehensive unit tests for:

  • Matrix operations and mathematical correctness
  • Neural network forward/backward propagation
  • Optimizer convergence and update rules
  • Activation and loss function derivatives

Running Specific Tests

# Run all tests
ctest
# Run specific test suite
./build/run_tests --gtest_filter="MatrixTest.*"
# Run with verbose output
./build/run_tests --gtest_filter="*" --gtest_output="verbose"

๐Ÿ”„ Continuous Integration

The project includes GitHub Actions workflows that automatically:

  • Build and test on multiple platforms (Ubuntu, macOS)
  • Test with different compilers (GCC, Clang)
  • Run static analysis and code formatting checks
  • Generate documentation (when implemented)
  • Perform memory leak detection

๐Ÿ“– Learning Path

Recommended implementation order for learning:

  1. Start with Matrix utilities - Foundation for all operations
  2. Implement activation functions - Simple mathematical functions
  3. Build feedforward networks - Core neural network concepts
  4. Add optimization algorithms - Learning and convergence
  5. Implement loss functions - Training objectives
  6. Extend to CNNs - Spatial data processing
  7. Add RNNs/LSTMs - Sequential data processing

๐Ÿค Contributing

This is a learning-focused project. Feel free to:

  • Implement the TODO items in the headers
  • Add comprehensive tests for your implementations
  • Improve documentation and examples
  • Optimize performance and memory usage
  • Add new algorithms and techniques

๐Ÿ“„ License

Apache License 2.0

๐Ÿ”— Resources


Happy Learning! ๐Ÿš€