Nabla ML
A user-friendly neural network library implemented in Rust, designed for simplicity and educational purposes. It draws inspiration from NumPy and TensorFlow, offering a robust multi-dimensional array implementation along with a wide range of mathematical and array manipulation functionalities. The library emphasizes ease of use, making it ideal for both beginners and experienced developers looking to explore machine learning concepts.
Features
Core Components
-
NDArray: A versatile multi-dimensional array implementation supporting:
- Fundamental operations (addition, subtraction, multiplication, division)
- Broadcasting for operations like [N, M] + [1, M]
- Shape manipulation (reshape, transpose)
- Matrix operations (dot product)
- Statistical functions (sum, mean)
- Element-wise operations (exp, log, sqrt)
- Padding functionality for batch processing
Additionally...
- Array Creation: Easily create 1D and 2D arrays from vectors and matrices.
- Random Arrays: Generate arrays filled with random numbers, supporting both uniform and normal distributions.
- Arithmetic Operations: Execute element-wise addition, subtraction, multiplication, and division.
- Mathematical Functions: Apply a variety of functions including square root, exponential, sine, cosine, logarithm, hyperbolic tangent, ReLU, Leaky ReLU, and Sigmoid to arrays.
- Array Reshaping: Modify the shape of arrays while preserving data integrity.
- File I/O: Save and load arrays in a compressed format for efficient storage.
- Linear Regression: Implement linear regression using gradient descent techniques.
- MNIST Dataset Handling: Convert and load MNIST data seamlessly for machine learning tasks.
-
Neural Network Layers:
- Dense (Fully Connected) layers
- Activation layers
- Support for a variety of activation functions
Activation Functions
- ReLU (Rectified Linear Unit)
- Leaky ReLU
- Sigmoid
- Softmax (for classification tasks)
Optimizers
- Adam optimizer with customizable parameters:
- Learning rate
- Beta1 and Beta2 momentum parameters
- Epsilon for numerical stability
- Automatic handling of moment vector shapes
Training Features
- Support for mini-batch training
- Automatic padding for batches
- Tracking of loss metrics
- Accuracy metrics for performance evaluation
- Broadcasting capabilities for efficient computations
Example Usage
use NabModel;
use NabLayer;
// Create model architecture
let input = input; // For MNIST: 28x28 = 784 input features
let dense1 = dense;
let x = input.apply;
let dense2 = dense;
let x = x.apply;
let output_layer = dense;
let output = x.apply;
// Create and compile model
let mut model = new_functional;
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;
let uniform_array = rand_uniform; // New function for uniform random arrays
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;
let power_arr = arr.power; // New power function
Loss Functions
use NabLoss;
let y_true = from_vec;
let y_pred = from_vec;
let mse = mean_squared_error;
Optimizers
use NablaOptimizer;
let mut weights = from_vec;
let gradients = from_vec;
let learning_rate = 0.1;
sgd_update;
Linear Regression
use Nabla;
let X = from_matrix;
let y = from_vec;
let = linear_regression;
Relevant Code Snippets
Here are the relevant functions that were highlighted in the README:
NDArray Functions
NabLoss Functions
Nabla Optimizer Functions
Nabla Linear Regression Function
File I/O with .nab Format
File I/O with .nab Format
use ;
let array = from_vec;
save_nab.expect;
let loaded_array = load_nab.expect;
assert_eq!;
assert_eq!;
Saving Multiple NDArrays
use ;
let array1 = from_vec;
let array2 = from_vec;
let arrays = vec!;
savez_nab.expect;
Loading Multiple NDArrays
use loadz_nab;
let loaded_arrays = loadz_nab.expect;
assert_eq!;
assert_eq!;
MNIST Dataset Handling
use NabMnist;
use NabUtils;
mnist_csv_to_nab.expect;
let =
load_and_split_dataset.expect;
Relevant Code Snippets
Here are the relevant functions that were highlighted in the README:
File I/O Functions
use File;
use ;
use ;
use ;
use crate NDArray;
/// Saves an NDArray to a .nab file with compression
/// Loads an NDArray from a compressed .nab file
MNIST Handling Functions
use crate NDArray;
use crate save_nab;
;
Mnist dataset in .nab format can be found here
License
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.