fn feedforward_works() {
        // 1 input 1 output
        let network = Network::new(vec![1, 1]);
        let inp = Array::from_vec(vec![1. as f64]).into_shape((1, 1)).unwrap();
        let out = network.feedforward(inp)[[0, 0]];

        let bias = network.biases[0][[0, 0]];
        let weight = network.weights[0][[0, 0]];

        let expected_out = Network::sigmoid(1. * weight + bias);

        assert_eq!(out, expected_out);

        // 2 inputs, 1 output
        let network = Network::new(vec![2, 1]);
        let inp = Array::from_vec(vec![1. as f64, 1. as f64])
            .into_shape((2, 1))
            .unwrap();
        let out = network.feedforward(inp)[[0, 0]];

        let bias = network.biases[0][[0, 0]];
        let weight_1 = network.weights[0][[0, 0]];
        let weight_2 = network.weights[0][[0, 1]];

        let expected_out = Network::sigmoid(1. * weight_1 + 1. * weight_2 + bias);

        assert_eq!(out, expected_out);

        // 1 input through 2 layers
        let network = Network::new(vec![1, 1, 1]);
        let inp = Array::from_vec(vec![1. as f64]).into_shape((1, 1)).unwrap();
        let out = network.feedforward(inp)[[0, 0]];

        let bias_1 = network.biases[0][[0, 0]];
        let bias_2 = network.biases[1][[0, 0]];
        let weight_1 = network.weights[0][[0, 0]];
        let weight_2 = network.weights[1][[0, 0]];

        let expected_out =
            Network::sigmoid(Network::sigmoid(1. * weight_1 + bias_1) * weight_2 + bias_2);

        assert_eq!(out, expected_out);
    }
// Checks that feedforward computations are working correctly on a super simple examples
Checks that feedforward computations are working correctly on a super simple examples
Checks that feedforward computations are working correctly on a super simple examples
fn feedforward_works() {
        // 1 input 1 output
        let network = Network::new(vec![1, 1]);
        let inp = Array::from_vec(vec![1. as f64]).into_shape((1, 1)).unwrap();
        let out = network.feedforward(inp)[[0, 0]];
        let bias = network.biases[0][[0, 0]];
        let weight = network.weights[0][[0, 0]];
        let expected_out = Network::sigmoid(1. * weight + bias);
        assert_eq!(out, expected_out);
        // 2 inputs, 1 output
        let network = Network::new(vec![2, 1]);
        let inp = Array::from_vec(vec![1. as f64, 1. as f64])
            .into_shape((2, 1))
            .unwrap();
        let out = network.feedforward(inp)[[0, 0]];
        let bias = network.biases[0][[0, 0]];
        let weight_1 = network.weights[0][[0, 0]];
        let weight_2 = network.weights[0][[0, 1]];
        let expected_out = Network::sigmoid(1. * weight_1 + 1. * weight_2 + bias);
        assert_eq!(out, expected_out);
        // 1 input through 2 layers
        let network = Network::new(vec![1, 1, 1]);
        let inp = Array::from_vec(vec![1. as f64]).into_shape((1, 1)).unwrap();
        let out = network.feedforward(inp)[[0, 0]];
        let bias_1 = network.biases[0][[0, 0]];
        let bias_2 = network.biases[1][[0, 0]];
        let weight_1 = network.weights[0][[0, 0]];
        let weight_2 = network.weights[1][[0, 0]];
        let expected_out =
            Network::sigmoid(Network::sigmoid(1. * weight_1 + bias_1) * weight_2 + bias_2);
        assert_eq!(out, expected_out);
    }
fn feedforward_works ( ) { // 1 input 1 output let network = Network :: new ( vec ! [ 1 1 ] ) ; let inp = Array :: from_vec ( vec ! [ 1. as f64 ] ) . into_shape ( ( 1 , 1 ) ) . unwrap ( ) ; let out = network . feedforward ( inp ) [ [ 0 , 0 ] ] ; let bias = network . biases [ 0 ] [ [ 0 , 0 ] ] ; let weight = network . weights [ 0 ] [ [ 0 , 0 ] ] ; let expected_out = Network :: sigmoid ( 1. * weight + bias ) ; assert_eq ! ( out expected_out ) ; // 2 inputs, 1 output let network = Network :: new ( vec ! [ 2 1 ] ) ; let inp = Array :: from_vec ( vec ! [ 1. as f64 1. as f64 ] ) . into_shape ( ( 2 , 1 ) ) . unwrap ( ) ; let out = network . feedforward ( inp ) [ [ 0 , 0 ] ] ; let bias = network . biases [ 0 ] [ [ 0 , 0 ] ] ; let weight_1 = network . weights [ 0 ] [ [ 0 , 0 ] ] ; let weight_2 = network . weights [ 0 ] [ [ 0 , 1 ] ] ; let expected_out = Network :: sigmoid ( 1. * weight_1 + 1. * weight_2 + bias ) ; assert_eq ! ( out expected_out ) ; // 1 input through 2 layers let network = Network :: new ( vec ! [ 1 1 1 ] ) ; let inp = Array :: from_vec ( vec ! [ 1. as f64 ] ) . into_shape ( ( 1 , 1 ) ) . unwrap ( ) ; let out = network . feedforward ( inp ) [ [ 0 , 0 ] ] ; let bias_1 = network . biases [ 0 ] [ [ 0 , 0 ] ] ; let bias_2 = network . biases [ 1 ] [ [ 0 , 0 ] ] ; let weight_1 = network . weights [ 0 ] [ [ 0 , 0 ] ] ; let weight_2 = network . weights [ 1 ] [ [ 0 , 0 ] ] ; let expected_out = Network :: sigmoid ( Network :: sigmoid ( 1. * weight_1 + bias_1 ) * weight_2 + bias_2 ) ; assert_eq ! ( out expected_out ) ; }
Checks that feedforward computations are working correctly on a super simple examples
Checks that feedforward computations are working correctly on a super simple examples