zlearn

Crates.iozlearn
lib.rszlearn
version0.1.1
created_at2025-05-21 16:51:20.643187+00
updated_at2025-05-21 16:51:20.643187+00
descriptionA simple neural network implementation library in Rust
homepage
repositoryhttps://github.com/GrishmUmesh/zlearn
max_upload_size
id1683637
size13,438
Kryptos639 (GrishmUmesh)

documentation

README

zlearn

A simple neural network library in rust, designed for simplicity and higher control to the user.

Features

Builtin activation functions
Builtin Matrices
Backpropogation

XOR Example

use zlearn::activation::SIGMOID;
use zlearn:network::Network;

fn main() {
    // XOR input and target data
    let inputs = vec![
        vec![0.0, 0.0],
        vec![0.0, 1.0],
        vec![1.0, 0.0],
        vec![1.0, 1.0],
    ];
    let targets = vec![
        vec![0.0],
        vec![1.0],
        vec![1.0],
        vec![0.0],
    ];

    // Create a network: 2 input neurons, 2 hidden neurons, 1 output neuron
    let mut network = Network::new(vec![2, 2, 1], SIGMOID, 0.5);

    // Train the network for 10,000 epochs
    network.train(inputs.clone(), targets, 10000);

    // Test the network
    println!("\nTesting XOR after training:");
    for i in 0..inputs.len() {
        let output = network.feed_forward(inputs[i].clone());
        println!(
            "Input: [{:.1}, {:.1}]  Output: {:.3}  Expected: [{:.1}]",
            inputs[i][0], inputs[i][1], output[0], targets[i][0]
        );
    }
}
Commit count: 9

cargo fmt