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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use std::f32; use std::f64; pub fn logistic32(x: f32, c: f32) -> f32 { 1.0 / (1.0 + (-c*x).exp()) } pub fn logistic64(x: f64, c: f64) -> f64 { 1.0 / (1.0 + (-c*x).exp()) } pub fn tanh32(x: f32, c: f32) -> f32 { (x*c).tanh() } pub fn tanh64(x: f64, c: f64) -> f64 { (x*c).tanh() } pub fn fast32(x: f32, c: f32) -> f32 { (x*c)/(1.0+(x*c).abs()) } pub fn fast64(x: f64, c: f64) -> f64 { (x*c)/(1.0+(x*c).abs()) } pub fn softplus32(x: f32, c: f32) -> f32 { (1.0+(x*c).exp()).ln() } pub fn softplus64(x: f64, c: f64) -> f64 { (1.0+(x*c).exp()).ln() } pub fn rectifier32(x: f32, c: f32) -> f32 { (x*c).max(0.0) } pub fn rectifier64(x: f64, c: f64) -> f64 { (x*c).max(0.0) } #[cfg(test)] mod tests { #[test] fn test_logistic() { assert!(logistic64()) } }