neural_network_rs/neural_network/activation_function/
mod.rs

1use ndarray::Array;
2
3pub mod linear;
4pub mod relu;
5pub mod sigmoid;
6
7pub struct ActivationFunction {
8    pub f: fn(f64) -> f64,
9    pub d: fn(f64) -> f64,
10}
11
12impl ActivationFunction {
13    pub fn function<D>(&self, x: &Array<f64, D>) -> Array<f64, D>
14    where
15        D: ndarray::Dimension,
16    {
17        x.mapv(self.f)
18    }
19
20    pub fn derivative<D>(&self, x: &Array<f64, D>) -> Array<f64, D>
21    where
22        D: ndarray::Dimension,
23    {
24        x.mapv(self.d)
25    }
26}