Skip to content

Latest commit

 

History

51 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MLP.h

A tiny, single-header, dependency-free Multi-Layer Perceptron library for C.

Drop MLP.h into your project — no build system, no linking, no external dependencies beyond the standard library.

Version: 0.10.0 · License: MIT


    MNIST TEST

Compile with:

cd examples && gcc mnist.c -O3 -flto -ffast-math -march=native
./a
[########################################] 
100% Epoch    50/   50  Loss 1.904e-02

Training completed.

Epochs     : 50
Final Loss : 1.90362931e-02
Reason     : Maximum epochs reached

Score: 9778/10000
Accuracy: 97.78%

Live Classifier: https://px7nn.github.io/MNIST/



Features

  • Zero External Dependencies: Pure, portable C99/C11. No linking required, with optional <math.h> support (MLP_USE_LIBM).
  • Flexible Network Configuration: Configure arbitrary topologies, activation functions (ReLU, Leaky ReLU, Sigmoid, Tanh, Softmax, Linear), weight initializers (He, Xavier, or MLP_AUTO_INITIALIZERS), and loss functions (MSE, BCE, CCE, or automatic inference via LOSS_AUTO) via NetworkConfig.
  • Model Persistence: Easily save and load trained networks to/from disk using compact binary files.
  • Built-in CSV Parsing: Streamline dataset preparation with automated CSV loading (MLP_LoadCSV) or wrap existing memory arrays.
  • Structured Error Handling: Features a robust global error reporting system with an opt-in fail-fast check (MLP_EXIT_ON_ERROR) to keep client code completely clean.

Quick start

#define MLP_IMPLEMENTATION   // in exactly one .c file
#include "MLP.h"

See docs/getting_started.md for a full walkthrough.

Documentation

See examples/ for full training examples:

  • xor_gate.c — trains a network on XOR and saves it to xor.mlp.
  • load_model.c — loads xor.mlp and runs inference without retraining.
  • load_csv.c — loads circle.csv via MLP_LoadCSV, trains, and predicts.
  • mnist.c — trains on handwritten digits using Softmax and Categorical Cross Entropy (compatible with the Live MNIST Canvas Demo).
  • visual_sin.c — fits a sine wave and saves a visualization plot.

Versioning

MLP_VERSION_STRING (and the matching _MAJOR/_MINOR/_PATCH macros) are defined at the top of MLP.h. This project is pre-1.0, so the public API may still change between minor versions.

About

A tiny dependency-free single-header Multi-Layer Perceptron library for C, written from scratch.

Topics

Resources

Stars

17 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages