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