fn backprop(&self, input: &Input, label: &Label) -> (Vec<LayerBiases>, Vec<LayerWeights>) {
        let mut nabla_b: Vec<LayerBiases> = Vec::with_capacity(self.layer_sizes.len() - 1);
        let mut nabla_w: Vec<LayerWeights> = Vec::with_capacity(self.layer_sizes.len() - 1);

        for layer_biases in &self.biases {
            nabla_b.push(Array::zeros(layer_biases.raw_dim()));
        }

        for layer_weights in &self.weights {
            nabla_w.push(Array::zeros(layer_weights.raw_dim()));
        }

        // Store the raw and non-linear activations at each layer, feeding forward
        // the input through the network
        let (activations, zs) = self.feedforward_get_all_activations(input.clone());

        let mut delta = Self::cost_derivative(&activations[activations.len() - 1], label);
        let (nbl, nwl) = (nabla_b.len(), nabla_w.len());
        nabla_b[nbl - 1] = delta.clone();
        nabla_w[nwl - 1] = delta.dot(&activations[activations.len() - 2].t());

        for layer_ind in 2..self.layer_sizes.len() {
            let z = &zs[zs.len() - layer_ind];
            delta = self.weights[self.weights.len() - layer_ind + 1]
                .t()
                .dot(&delta)
                * z.map(|x| Self::sigmoid_derivative(*x));

            nabla_b[nbl - layer_ind] = delta.clone();
            nabla_w[nwl - layer_ind] =
                delta.dot(&activations[activations.len() - layer_ind - 1].t());
        }

        (nabla_b, nabla_w)
    }
/// Compute the deltas from backpropagating a single training example
Compute the deltas from backpropagating a single training example
Compute the deltas from backpropagating a single training example
fn backprop(&self, input: &Input, label: &Label) -> (Vec<LayerBiases>, Vec<LayerWeights>) {
        let mut nabla_b: Vec<LayerBiases> = Vec::with_capacity(self.layer_sizes.len() - 1);
        let mut nabla_w: Vec<LayerWeights> = Vec::with_capacity(self.layer_sizes.len() - 1);
        for layer_biases in &self.biases {
            nabla_b.push(Array::zeros(layer_biases.raw_dim()));
        }
        for layer_weights in &self.weights {
            nabla_w.push(Array::zeros(layer_weights.raw_dim()));
        }
        // Store the raw and non-linear activations at each layer, feeding forward
        // the input through the network
        let (activations, zs) = self.feedforward_get_all_activations(input.clone());
        let mut delta = Self::cost_derivative(&activations[activations.len() - 1], label);
        let (nbl, nwl) = (nabla_b.len(), nabla_w.len());
        nabla_b[nbl - 1] = delta.clone();
        nabla_w[nwl - 1] = delta.dot(&activations[activations.len() - 2].t());
        for layer_ind in 2..self.layer_sizes.len() {
            let z = &zs[zs.len() - layer_ind];
            delta = self.weights[self.weights.len() - layer_ind + 1]
                .t()
                .dot(&delta)
                * z.map(|x| Self::sigmoid_derivative(*x));
            nabla_b[nbl - layer_ind] = delta.clone();
            nabla_w[nwl - layer_ind] =
                delta.dot(&activations[activations.len() - layer_ind - 1].t());
        }
        (nabla_b, nabla_w)
    }
fn backprop ( & self , input : & Input , label : & Label ) -> ( Vec < LayerBiases > , Vec < LayerWeights > ) { let mut nabla_b : Vec < LayerBiases > = Vec :: with_capacity ( self . layer_sizes . len ( ) - 1 ) ; let mut nabla_w : Vec < LayerWeights > = Vec :: with_capacity ( self . layer_sizes . len ( ) - 1 ) ; for layer_biases in & self . biases { nabla_b . push ( Array :: zeros ( layer_biases . raw_dim ( ) ) ) ; } for layer_weights in & self . weights { nabla_w . push ( Array :: zeros ( layer_weights . raw_dim ( ) ) ) ; } // Store the raw and non-linear activations at each layer, feeding forward // the input through the network let ( activations , zs ) = self . feedforward_get_all_activations ( input . clone ( ) ) ; let mut delta = Self :: cost_derivative ( & activations [ activations . len ( ) - 1 ] , label ) ; let ( nbl , nwl ) = ( nabla_b . len ( ) , nabla_w . len ( ) ) ; nabla_b [ nbl - 1 ] = delta . clone ( ) ; nabla_w [ nwl - 1 ] = delta . dot ( & activations [ activations . len ( ) - 2 ] . t ( ) ) ; for layer_ind in 2 .. self . layer_sizes . len ( ) { let z = & zs [ zs . len ( ) - layer_ind ] ; delta = self . weights [ self . weights . len ( ) - layer_ind + 1 ] . t ( ) . dot ( & delta ) * z . map ( | x | Self :: sigmoid_derivative ( * x ) ) ; nabla_b [ nbl - layer_ind ] = delta . clone ( ) ; nabla_w [ nwl - layer_ind ] = delta . dot ( & activations [ activations . len ( ) - layer_ind - 1 ] . t ( ) ) ; } ( nabla_b , nabla_w ) }
Compute the deltas from backpropagating a single training example
Compute the deltas from backpropagating a single training example
&self
input
&Input
label
&Label
&self
input
&Input
label
&Label