Nabla ML
A lightweight neural network library implemented in Rust, focusing on simplicity and educational purposes. It is inspired by NumPy, providing a multi-dimensional array implementation with various mathematical and array manipulation functionalities.
Features
Core Components
-
NDArray: A multi-dimensional array implementation supporting:
- Basic operations (add, subtract, multiply, divide)
- Broadcasting support for operations like [N, M] + [1, M]
- Shape manipulation (reshape, transpose)
- Matrix operations (dot product)
- Statistical operations (sum, mean)
- Element-wise operations (exp, log, sqrt)
- Padding functionality for batches
Moreover...
- Array Creation: Create 1D and 2D arrays using vectors and matrices.
- Random Arrays: Generate arrays with random numbers, including uniform and normal distributions.
- Arithmetic Operations: Perform element-wise addition, subtraction, multiplication, and division.
- Mathematical Functions: Apply functions like square root, exponential, sine, cosine, logarithm, hyperbolic tangent, ReLU, Leaky ReLU, and Sigmoid to arrays.
- Array Reshaping: Change the shape of arrays while maintaining data integrity.
- File I/O: Save and load arrays in a compressed format.
- Linear Regression: Perform linear regression using gradient descent.
- MNIST Dataset Handling: Convert and load MNIST data for machine learning tasks.
-
Neural Network Layers:
- Dense (Fully Connected) layers
- Activation layers
- Support for various activation functions
Activation Functions
- ReLU (Rectified Linear Unit)

- Leaky ReLU

- Sigmoid

- Softmax (for classification)
Optimizers
- Adam optimizer with configurable parameters:
- Learning rate
- Beta1 and Beta2 momentum parameters
- Epsilon for numerical stability
- Automatic moment vector shape handling
Training Features
- Mini-batch training support
- Automatic batch padding
- Loss tracking
- Accuracy metrics
- Broadcasting for efficient computations
Example Usage
let mut model = new
.input // For MNIST: 28x28 = 784 input features
.add_dense
.add_dense
.add_dense
.build;
model.compile;
// Train the model
let history = model.fit;
model.summary;
Usage
Array Creation
use NDArray;
let arr = from_vec;
let matrix = from_matrix;
Random Arrays
use NDArray;
let random_array = randn;
let random_matrix = randn_2d;
Mathematical Functions
use NDArray;
let arr = from_vec;
let sqrt_arr = arr.sqrt;
let exp_arr = arr.exp;
let tanh_arr = arr.tanh;
let relu_arr = arr.relu;
let leaky_relu_arr = arr.leaky_relu;
let sigmoid_arr = arr.sigmoid;
File I/O with .nab Format
use ;
let array = from_vec;
save_nab.expect;
let loaded_array = load_nab.expect;
assert_eq!;
assert_eq!;
Linear Regression
use NDArray;
let X = from_matrix;
let y = from_vec;
let = linear_regression;
println!;
MNIST Dataset Handling
use NDArray;
mnist_csv_to_nab.expect;
let =
load_and_split_dataset.expect;
Mnist dataset in .nab format can be found here
One-Hot Encoding
use NDArray;
// Convert labels to one-hot encoded format
let labels = from_vec;
let one_hot = one_hot_encode;
// Result will be a 2D NDArray:
// [1, 0, 0] # Class 0
// [0, 1, 0] # Class 1
// [0, 0, 1] # Class 2
// [0, 1, 0] # Class 1
// [1, 0, 0] # Class 0

License
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.