use fnn::prelude::*;
fn main() {
let mut nn = FeedForward::<Sigmoid, 2, 2, 1>::new();
let training_data = [
([0.0, 0.0], [0.0]),
([0.0, 1.0], [1.0]),
([1.0, 0.0], [1.0]),
([1.0, 1.0], [0.0]),
];
for _ in 0..50_000 {
for (input, target) in &training_data {
let input = SVector::from_column_slice(input);
let target = SVector::from_column_slice(target);
nn.train(&input, &target, 0.1);
}
}
for (input, expected) in &training_data {
let output = nn.forward(&SVector::from_column_slice(input));
let difference = (expected[0] - output[0]).abs() * 100.0;
println!(
"Input: {input:?}, Output: {}, Expected: {}, Accuracy: {}%",
output[0],
expected[0],
100.0 - difference
);
}
}