Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bbdnn

A small, from-scratch C++ neural network library for demonstrative use. The goal is to keep the API easy to use while staying flexible enough for experimentation and learning. It focuses on simple feed-forward dense networks that you can assemble by hand, train with backpropagation, and inspect at each step.

Purpose

  • Demonstrate how feed-forward neural networks work without heavy dependencies.
  • Provide a compact, approachable API for building and training small networks.
  • Stay flexible so you can customize activations, layer sizes, and training loops.

Capabilities

  • Dense (fully connected) layers with configurable activations.
  • Common activations: Linear, ReLU, LeakyReLU, Sigmoid, Logistic, Tanh.
  • Xavier and Kaiming weight initialization in LayerConnection.
  • Forward propagation and backpropagation for gradient-based learning.
  • Lightweight Matrix and Vector types for basic linear algebra.
  • Optional helper utilities on NeuralNetwork such as train, evaluate, and predict.

Quick Start

Use the umbrella header:

#include "bbdnn/bbdnn.hpp"

Or include individual headers such as:

#include "bbdnn/Activations.hpp"

All library types live in the bbdnn namespace.

Demo: examples/nn_demo.cpp

The demo trains a tiny network on XOR and prints predictions:

  1. Builds a 2-3-1 network: input layer (2), hidden layer (3), output layer (1).
  2. Uses Linear, Tanh, and Sigmoid activations.
  3. Trains on XOR samples with train(features, labels, learningRate, epochs, isStochastic).
  4. Uses predict to get outputs for each input.

Key snippet from the demo:

NeuralNetwork nn(seed, {
    DenseLayer(2, Activation::Linear()),
    DenseLayer(8, Activation::Tanh()),
    DenseLayer(8, Activation::Tanh()),
    DenseLayer(1, Activation::Sigmoid()),
});

std::vector<Vector> features {
    Vector{0.0f, 0.0f},
    Vector{0.0f, 1.0f},
    Vector{1.0f, 0.0f},
    Vector{1.0f, 1.0f},
};

std::vector<Vector> labels {
    Vector{0.0f},
    Vector{1.0f},
    Vector{1.0f},
    Vector{0.0f},
};

// Performs full-batch training `epochs` times
nn.train(features, labels, 0.05f, 10000, false);

Sample output from demo:

Input: 0 0 => Prediction: 0.0049705
Input: 0 1 => Prediction: 0.989448
Input: 1 0 => Prediction: 0.987596
Input: 1 1 => Prediction: 0.0121131

Build

This project uses CMake:

cmake -S . -B build
cmake --build build

The nn_demo executable will be built from examples/nn_demo.cpp.

Build with Makefile

There is also a simple Makefile in the project root:

make
./nn_demo

To clean build artifacts:

make clean

About

A small C++ Machine Learning Library made from scratch, focused on user flexibility and ease-of-use

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages