Skip to content

A minimal neural network that learns XOR from scratch using only the Rust standard library + rand.

Notifications You must be signed in to change notification settings

rust-dd/xor-neural-network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Tiny XOR Neural Network in Rust

A minimalist, fully handcrafted neural network built in pure Rust β€” trained to solve the classic XOR problem. No frameworks, no magic β€” just neurons, layers, and backpropagation.

Rust NeuralNet


✨ Features

  • βœ… Feedforward neural network (MLP)
  • βœ… Manual backpropagation implementation
  • βœ… Learns XOR from scratch
  • βœ… Only uses rand crate β€” no ML dependencies
  • βœ… Fully commented and beginner-friendly

🧠 What it learns

The XOR logic gate:

Input A Input B Expected Output
0 0 0
0 1 1
1 0 1
1 1 0

πŸš€ Getting Started

git clone https://github.com/your-username/rust-xor-mlp.git
cd rust-xor-mlp
cargo run --release

πŸ”§ Configuration

You can tweak the training parameters in main.rs:

let mut network = Network::new(2, 2); // hidden layer size
network.train(100_000, 0.1); // epochs, learning rate

πŸ“ˆ Sample Output (after training)

Input: [0.0, 0.0] β†’ Output: 0.02 (Expected: 0)
Input: [0.0, 1.0] β†’ Output: 0.97 (Expected: 1)
Input: [1.0, 0.0] β†’ Output: 0.98 (Expected: 1)
Input: [1.0, 1.0] β†’ Output: 0.03 (Expected: 0)

About

A minimal neural network that learns XOR from scratch using only the Rust standard library + rand.

Topics

Resources

Stars

Watchers

Forks

Languages