use crate::{Element, Value};
use super::Module;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Activation {
Tanh,
Relu,
}
impl Activation {
pub fn gain(self) -> f64 {
match self {
Activation::Tanh => 5.0 / 3.0,
Activation::Relu => 2.0_f64.sqrt(),
}
}
pub fn express<'tape, E: Element>(self, value: Value<'tape, E>) -> Value<'tape, E> {
match self {
Activation::Tanh => value.tanh(),
Activation::Relu => value.relu(),
}
}
}
#[cfg(test)]
#[path = "tests/activation_tests.rs"]
mod tests;
impl<E: Element> Module<E> for Activation {
fn express<'tape>(&self, input: Value<'tape, E>) -> Value<'tape, E> {
Activation::express(*self, input)
}
}