pub trait Activation: Send + Sync {
fn call(&self, x: f64) -> f64;
fn derivative(&self, a_x: f64) -> f64;
}
#[derive(Debug, Clone, Copy)]
pub enum Activations {
Identity,
Sigmoid,
Arctan,
ReLU,
}
impl Activation for Activations {
fn call(&self, x: f64) -> f64 {
use Activations::*;
match self {
Identity => x,
Sigmoid => 1.0 / (1.0 + (-x).exp()),
Arctan => x.atan(),
ReLU => x.max(0.0),
}
}
fn derivative(&self, a_x: f64) -> f64 {
use Activations::*;
match self {
Identity => 1.0,
Arctan => 1.0 / (1.0 + a_x.tan() * a_x.tan()),
Sigmoid => a_x * (1.0 - a_x),
ReLU => {
if a_x > 0.0 {
1.0
} else {
0.0
}
}
}
}
}