Rust 玩具神经网络
用 Rust 实现的玩具神经网络,灵感来自于 11行Python代码实现玩具神经网络
// Original python code
// https://iamtrask.github.io/2015/07/12/basic-python-network/
// Neural Network = 3 inputs, 4 hidden, 1 output with sigmoid activation
use ndarray::{array, Array};
use ndarray_rand::{rand::SeedableRng, rand_distr::Uniform, RandomExt}; // random matrix generation
use rand_isaac::isaac64::Isaac64Rng; // for setting seed
fn main() -> std::io::Result<()> {
// set seeds
let seed = 42;
let mut rng = Isaac64Rng::seed_from_u64(seed);
// dataset
let x = array![[0., 0., 1.], [0., 1., 1.], [1., 0., 1.], [1., 1., 1.]];
let y = array![[0., 1., 1., 0.]].reversed_axes();
// initializing random weights
let mut w0 = Array::random_using((3, 4), Uniform::new(0., 1.), &mut rng); // syn0
let mut w1 = Array::random_using((4, 1), Uniform::n