Skip to content

Instantly share code, notes, and snippets.

/// 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);
@mikecvet
mikecvet / max.rs
Last active October 17, 2023 18:42
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();
/// 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 {
/// 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 {