xor/
xor.rs

1use vexus::NeuralNetwork;
2
3fn main() {
4    // Create a neural network with 2 inputs, one hidden layer of 4 neurons, and 1 output
5    let mut nn = NeuralNetwork::new(vec![2, 4, 1], 0.1);
6
7    // Training data for XOR
8    let training_data = vec![
9        (vec![0.0, 0.0], vec![0.0]),
10        (vec![0.0, 1.0], vec![1.0]),
11        (vec![1.0, 0.0], vec![1.0]),
12        (vec![1.0, 1.0], vec![0.0]),
13    ];
14
15    // Train the network
16    for _ in 0..100000 {
17        for (inputs, expected) in &training_data {
18            nn.forward(inputs.clone());
19            let outputs = nn.get_outputs();
20            let errors = vec![expected[0] - outputs[0]];
21            nn.backwards(errors);
22        }
23    }
24
25    // Test the network
26    for (inputs, expected) in &training_data {
27        nn.forward(inputs.clone());
28        let outputs = nn.get_outputs();
29        println!(
30            "Input: {:?}, Expected: {:?}, Got: {:.4}",
31            inputs, expected[0], outputs[0]
32        );
33    }
34}