100/Cranium logo

100/Cranium

Free

🤖 A portable, header-only, artificial neural network library written in C99

FreeFree tier
Type
Open Source

About 100/Cranium

Cranium is a portable, header-only feedforward artificial neural network library written in vanilla C99. It supports fully-connected networks of arbitrary depth and structure, using matrix-based calculations for performance. Designed for low-resource machines or environments where additional dependencies cannot be installed, Cranium includes activation functions (sigmoid, ReLU, tanh, softmax, linear), loss functions (cross-entropy, mean squared error), and optimization algorithms (batch gradient descent, stochastic gradient descent, mini-batch SGD, L2 regularization, learning rate annealing, momentum, fan-in weight initialization). It optionally integrates with CBLAS for fast matrix multiplication and supports serializable networks. The library is header-only: simply copy the src directory, include 'cranium.h', and compile with -lm.

Key Features

Portable, header-only design written in vanilla C99
Fully-connected feedforward networks of arbitrary depth and structure
Matrix-based calculations for efficient forward and backward propagation
Support for activation functions: sigmoid, ReLU, tanh, softmax (classification), linear (regression)
Loss functions: cross-entropy (classification), mean squared error (regression)
Optimization algorithms: Batch Gradient Descent, Stochastic Gradient Descent, Mini-Batch SGD
L2 regularization, learning rate annealing, and simple momentum
Optional CBLAS integration for fast matrix multiplication via sgemm
Serializable networks (save/load model parameters)
Minimal dependencies – only requires math.h and optionally CBLAS

Pros & Cons

Pros
  • Lightweight and portable – no external dependencies beyond standard C libraries
  • Header-only library simplifies integration into C projects
  • Supports essential activation and loss functions for basic neural network tasks
  • CBLAS integration provides optional performance boost for matrix operations
  • Well-suited for low-power or embedded environments where larger frameworks are impractical
Cons
  • Limited to fully-connected feedforward architectures – no support for convolutional, recurrent, or attention layers
  • No built-in GPU acceleration (CPU-only, though CBLAS can improve performance)
  • Relatively basic compared to modern deep learning frameworks like TensorFlow or PyTorch
  • Documentation is minimal (primarily README and header comments)

Best For

Building and training small to medium-sized neural networks on embedded or resource-constrained systemsEducational projects to understand feedforward neural networks at the C levelClassification and regression tasks with tabular or structured dataPrototyping neural network architectures in pure C without heavy frameworks

FAQ

What is Cranium?
Cranium is a portable, header-only feedforward artificial neural network library written in vanilla C99. It is designed for low-resource machines or environments where additional dependencies cannot be installed.
How do I use Cranium in my project?
Since it is header-only, simply copy the src directory into your project and #include 'src/cranium.h'. Compile with -lm for math.h, and optionally with -lcblas if using CBLAS.
What activation functions does Cranium support?
Cranium supports sigmoid, ReLU, tanh, softmax (for classification), and linear (for regression) activation functions.
What optimization algorithms are available?
Cranium implements Batch Gradient Descent, Stochastic Gradient Descent, Mini-Batch Stochastic Gradient Descent, along with L2 regularization, learning rate annealing, and simple momentum.
Does Cranium require any external libraries?
The only required compiler dependency is math.h. Optionally, you can integrate CBLAS (e.g., OpenBLAS or ATLAS) for faster matrix multiplication.
Can I save and load a trained network?
Yes, Cranium supports serializable networks, allowing you to save and load model parameters.