brainy 0.2.3

A library for neural networks.
Documentation
//! Use to make a network from layers.

use crate::matrix::Matrix;
use crate::layer::{Map, Layer};

/// List of layers.
pub struct Network
{
    pub layers: Vec<Layer>
}

impl Network
{
    pub fn new() -> Self
    {
        let layers: Vec<Layer> = Vec::new();
        Self { layers }
    }

    /// Push a new layer at the tail of the neural network.
    pub fn append_layer(&mut self, map: Map)
    {
        self.layers.push(Layer::new(map))
    }

    /// Provide an initial input that is fed through all the layers.
    /// Then spit out the output.
    pub fn feedforward(&mut self, input: Matrix) -> Matrix
    {
        let mut x: Matrix = input;
        for i in 0..self.layers.len()
        {
            assert!((x.rows ==  self.layers[i].x.rows) && (x.cols == 1), "Input has incorrect dimensions");
            self.layers[i].x = x;
            x = self.layers[i].feedforward();
        }

        x
    }
}