#neural-network #artificial-intelligence #brain #size

vexus

A neural network builder and trainer struct to make your own AI models

5 stable releases

Uses new Rust 2024

3.0.0 Mar 24, 2025
2.0.1 Mar 21, 2025
1.0.1 Feb 8, 2025

#275 in Machine learning

Download history 245/week @ 2025-02-08 19/week @ 2025-02-15 163/week @ 2025-03-15 180/week @ 2025-03-22 16/week @ 2025-03-29 2/week @ 2025-04-05

361 downloads per month

MIT license

18KB
140 lines

Vexus

A neural network builder and trainer to make your own AI models.

Features

  • Feed-forward neural network
  • Backpropagation learning
  • Configurable layer sizes
  • Sigmoid activation function
  • Save/load functionality

Installation

Add this to your Cargo.toml:

cargo add vexus

Quick Start

XOR Predictor

use neural_network::NeuralNetwork;

fn main() {
    // Create a neural network with:
    // - 2 input neurons
    // - 4 hidden neurons
    // - 1 output neuron
    let mut nn = NeuralNetwork::new(vec![2, 4, 1], 0.1);

    // Training data for XOR function
    let training_data = vec![
        (vec![0.0, 0.0], vec![0.0]),
        (vec![0.0, 1.0], vec![1.0]),
        (vec![1.0, 0.0], vec![1.0]),
        (vec![1.0, 1.0], vec![0.0]),
    ];

    // Train the network
    for _ in 0..10000 {
        for (inputs, expected) in &training_data {
            nn.forward(inputs.clone());
            let outputs = nn.get_outputs();
            let errors = vec![expected[0] - outputs[0]];
            nn.backwards(errors);
        }
    }

    // Test the network
    nn.forward(vec![1.0, 0.0]);
    println!("1 XOR 0 = {:.2}", nn.get_outputs()[0]); // Should be close to 1.0
}

Run Examples

cargo run --example xor

cargo run --example sine_waves

Todo

  • Add mutation
  • Implement different activation functions
    • ReLU
    • Tanh
    • Sigmoid
  • Add save/load functionality
  • Add documentation
  • Add more examples

License

MIT

Dependencies

~1–2MB
~40K SLoC