concision_core/traits/propagation.rs
1/*
2 Appellation: predict <module>
3 Contrib: @FL03
4*/
5
6/// [Backward] propagate a delta through the system;
7pub trait Backward<X, Delta = X> {
8 type Elem;
9 type Output;
10
11 fn backward(
12 &mut self,
13 input: &X,
14 delta: &Delta,
15 gamma: Self::Elem,
16 ) -> crate::Result<Self::Output>;
17}
18
19/// This trait denotes entities capable of performing a single forward step
20pub trait Forward<Rhs> {
21 type Output;
22 /// a single forward step
23 fn forward(&self, input: &Rhs) -> crate::Result<Self::Output>;
24 /// this method enables the forward pass to be generically _activated_ using some closure.
25 /// This is useful for isolating the logic of the forward pass from that of the activation
26 /// function and is often used by layers and models.
27 fn forward_then<F>(&self, input: &Rhs, then: F) -> crate::Result<Self::Output>
28 where
29 F: FnOnce(Self::Output) -> Self::Output,
30 {
31 self.forward(input).map(then)
32 }
33}