fn update_minibatch(&mut self, minibatch: &mut [(Input, Label)], learning_rate: f64) {
        let per_example_lr = learning_rate / minibatch.len() as f64;

        let mut nabla_b: Vec<LayerBiases> = Vec::with_capacity(self.biases.len());
        let mut nabla_w: Vec<LayerWeights> = Vec::with_capacity(self.weights.len());

        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()));
        }

        for (input, label) in minibatch {
            let (dnabla_b, dnabla_w) = self.backprop(input, label);

            for (nb, dnb) in nabla_b.iter_mut().zip(&dnabla_b) {
                *nb += dnb;
            }

            for (nw, dnw) in nabla_w.iter_mut().zip(&dnabla_w) {
                *nw += dnw;
            }
        }

        // Update the weights and biases against the direction of the gradient
        for (b, nb) in self.biases.iter_mut().zip(nabla_b) {
            *b -= &(per_example_lr * nb);
        }

        for (w, nw) in self.weights.iter_mut().zip(&nabla_w) {
            *w -= &(per_example_lr * nw);
        }
    }
/// Updates weights and biases by doing gradient descent on a minibatch
Updates weights and biases by doing gradient descent on a minibatch
Updates weights and biases by doing gradient descent on a minibatch
fn update_minibatch(&mut self, minibatch: &mut [(Input, Label)], learning_rate: f64) {
        let per_example_lr = learning_rate / minibatch.len() as f64;
        let mut nabla_b: Vec<LayerBiases> = Vec::with_capacity(self.biases.len());
        let mut nabla_w: Vec<LayerWeights> = Vec::with_capacity(self.weights.len());
        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()));
        }
        for (input, label) in minibatch {
            let (dnabla_b, dnabla_w) = self.backprop(input, label);
            for (nb, dnb) in nabla_b.iter_mut().zip(&dnabla_b) {
                *nb += dnb;
            }
            for (nw, dnw) in nabla_w.iter_mut().zip(&dnabla_w) {
                *nw += dnw;
            }
        }
        // Update the weights and biases against the direction of the gradient
        for (b, nb) in self.biases.iter_mut().zip(nabla_b) {
            *b -= &(per_example_lr * nb);
        }
        for (w, nw) in self.weights.iter_mut().zip(&nabla_w) {
            *w -= &(per_example_lr * nw);
        }
    }
fn update_minibatch ( & mut self , minibatch : & mut [ ( Input , Label ) ] , learning_rate : f64 ) { let per_example_lr = learning_rate / minibatch . len ( ) as f64 ; let mut nabla_b : Vec < LayerBiases > = Vec :: with_capacity ( self . biases . len ( ) ) ; let mut nabla_w : Vec < LayerWeights > = Vec :: with_capacity ( self . weights . len ( ) ) ; 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 ( ) ) ) ; } for ( input , label ) in minibatch { let ( dnabla_b , dnabla_w ) = self . backprop ( input , label ) ; for ( nb , dnb ) in nabla_b . iter_mut ( ) . zip ( & dnabla_b ) { * nb += dnb ; } for ( nw , dnw ) in nabla_w . iter_mut ( ) . zip ( & dnabla_w ) { * nw += dnw ; } } // Update the weights and biases against the direction of the gradient for ( b , nb ) in self . biases . iter_mut ( ) . zip ( nabla_b ) { * b -= & ( per_example_lr * nb ) ; } for ( w , nw ) in self . weights . iter_mut ( ) . zip ( & nabla_w ) { * w -= & ( per_example_lr * nw ) ; } }
Updates weights and biases by doing gradient descent on a minibatch
Updates weights and biases by doing gradient descent on a minibatch
&mut self
minibatch
&mut [(Input, Label)]
learning_rate
f64
&mut self
minibatch
&mut [(Input, Label)]
learning_rate
f64