juggernaut/activation/
identity.rs1use activation::Activation;
2
3#[derive(Copy, Clone)]
4pub struct Identity;
5
6impl Identity {
7 pub fn new() -> Identity {
8 return Identity;
9 }
10}
11
12impl Activation for Identity {
13 fn calc(&self, x: Vec<f64>) -> Vec<f64> {
15 x
16 }
17
18 fn derivative(&self, v: Vec<f64>) -> Vec<f64> {
20 v.iter().map(|_| 1f64).collect::<Vec<_>>()
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::Activation;
27 use super::Identity;
28
29 #[test]
30 fn identity_test() {
31 let activation = Identity::new();
32 assert_approx_eq!(activation.calc(vec![5f64])[0], 5f64);
33 }
34
35 #[test]
36 fn identity_derivative_test() {
37 let activation = Identity::new();
38 assert_approx_eq!(activation.derivative(vec![15f64])[0], 1f64);
39 }
40}