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, and should be reasonably fast as it uses a matrix-based approach to calculations. It is particularly suitable for low-resource machines or environments in which additional dependencies cannot be installed.
Cranium supports CBLAS integration. Simply uncomment line 7 in matrix.h to enable the BLAS sgemm function for fast matrix multiplication.
Check out the detailed documentation here for information on individual structures and functions.
Features
- Activation functions
- sigmoid
- ReLU
- tanh
- softmax (classification)
- linear (regression)
- Loss functions
- Cross-entropy loss (classification)
- Mean squared error (regression)
- Optimization algorithms
- Batch Gradient Descent
- Stochastic Gradient Descent
- Mini-Batch Stochastic Gradient Descent
- L2 Regularization
- Learning rate annealing
- Simple momentum
- Fan-in weight initialization
- CBLAS support for fast matrix multiplication
- Serializable networks
Usage
Since Cranium is header-only, simply copy the src directory into your project, and #include "src/cranium.h" to begin using it.
Its only required compiler dependency is from the `````` header, so compile with -lm.
If you are using CBLAS, you will also need to compile with -lcblas and include, via -I, the path to wherever your particular machine's BLAS implementation is. Common ones include OpenBLAS and ATLAS.
It has been tested to work perfectly fine with any level of gcc optimization, so feel free to use them.
Example
Building and Testing
To run tests, look in the tests folder.
The Makefile has commands to run each batch of unit tests, or all of them at once.
Contributing
Feel free to send a pull request if you want to add any features or if you find a bug.
Check the issues tab for some potential things to do.