This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Runs forward propagation in this layer of the network. Flattens input, computes probabilities of | |
/// outputs based on the dot product with this layer's weights and softmax outputs. | |
pub fn | |
forward_propagation<'a> (&mut self, input: &'a Array3<f64>, ctx: &mut SoftmaxContext<'a>) -> Array1<f64> | |
{ | |
let flattened: Array1<f64> = input.to_owned().into_shape((input.len(),)).unwrap(); | |
let dot_result = flattened.dot(&self.weights).add(&self.bias); | |
let probabilities = softmax(&dot_result); | |
ctx.input = Some(input); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let patches = self.patches(input); | |
for p in patches.iter() { | |
let depth = p.data.dim().2; | |
let v: Vec<f64> = (0..depth).map(|i| { | |
p.data | |
.slice(s![.., .., i]) | |
.fold(f64::NEG_INFINITY, |acc, &v| acc.max(v)) | |
}).collect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A patch is a concept from image processing which captures subregions of the image pixels, | |
/// used to capture groups of spatial features from the underlying image. | |
pub fn | |
patches (&mut self, image: &Array2<f64>) -> Vec<Patch> | |
{ | |
let mut data: Vec<Patch> = Vec::new(); | |
for x in 0..(image.shape()[0] - self.rows + 1) { | |
for y in 0..(image.shape()[1] - self.cols + 1) { | |
let p = Patch { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A patch is a concept from image processing which captures subregions of the image pixels, | |
/// used to capture groups of spatial features from the underlying image. | |
pub fn | |
patches (&mut self, image: &Array2<f64>) -> Vec<Patch> | |
{ | |
let mut data: Vec<Patch> = Vec::new(); | |
for x in 0..(image.shape()[0] - self.rows + 1) { | |
for y in 0..(image.shape()[1] - self.cols + 1) { | |
let p = Patch { |