rust_lstm/utils.rs
1/// Utility functions for the LSTM library.
2
3/// Sigmoid activation function.
4pub fn sigmoid(x: f64) -> f64 {
5 1.0 / (1.0 + (-x).exp())
6}
7
8#[cfg(test)]
9mod tests {
10 use super::*;
11
12 #[test]
13 fn test_sigmoid() {
14 assert!((sigmoid(0.0) - 0.5).abs() < 1e-6);
15 assert!((sigmoid(2.0) - 0.880797).abs() < 1e-6);
16 assert!((sigmoid(-2.0) - 0.1192029).abs() < 1e-6);
17 }
18}