fast_neural_network/lib.rs
1//! # Fast Neural Network Library
2//! This library is a simple neural network library written in Rust. It is designed to be fast and easy to use. It supports saving and loading networks to and from JSON files.
3//! All of the heavy operations are parallelized. Stack-based networks are yet to be implemented.
4//!
5//! ## Example
6//!
7//! ```
8//! use fast_neural_network::{activation::*, neural_network::*};
9//! use ndarray::*;
10//!
11//! fn main() {
12//! let mut network = Network::new(2, 1, ActivationType::LeakyRelu, 0.01); // Create a new network with 2 inputs, 1 output, a LeakyRelu activation function, and a learning rate of 0.01
13//!
14//! network.add_hidden_layer_with_size(2); // Add a hidden layer with 2 neurons
15//!
16//! network.compile(); // Compile the network to prepare it for training
17//! // (will be done automatically during training)
18//! // The API is exposed so that the user can compile
19//! // the network on a different thread before training if they want to
20//!
21//! // Let's create a dataset to represent the XOR function
22//! let mut dataset: Vec<(ndarray::Array1<f64>, ndarray::Array1<f64>)> = Vec::new();
23//!
24//! dataset.push((array!(0., 0.), array!(0.)));
25//! dataset.push((array!(1., 0.), array!(1.)));
26//! dataset.push((array!(0., 1.), array!(1.)));
27//! dataset.push((array!(1., 1.), array!(0.)));
28//!
29//! network.train(&dataset, 20_000, 1_000); // train the network for 20,000 epochs with a decay_time of 1,000 epochs
30//!
31//! let mut res;
32//!
33//! // Let's check the result
34//! for i in 0..dataset.len() {
35//! res = network.forward(&dataset[i].0);
36//! let d = &dataset[i];
37//! println!(
38//! "for [{:.3}, {:.3}], [{:.3}] -> [{:.3}]",
39//! d.0[0], d.0[1], d.1[0], res
40//! );
41//! }
42//!
43//! network.save("network.json"); // Save the model as a json to a file
44//!
45//! // Load the model from a json file using the below line
46//! // let mut loaded_network = Network::load("network.json");
47//! }
48//!
49//!
50//! ```
51
52pub mod neural_network;
53pub mod activation;