#neural-network #ai #neural #brain #networking

vexus

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

2 stable releases

1.0.1 Feb 8, 2025

#181 in Machine learning

Download history 219/week @ 2025-02-04 22/week @ 2025-02-11

241 downloads per month

MIT license

9KB
108 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

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.5MB
~18K SLoC