/* Appellation: autodiff Contrib: FL03 */ extern crate acme; use acme::{autodiff, operator}; use num::Float; fn main() -> acme::prelude::BoxResult { let x = 5f64; let lex = sigmoid_lex(); println!("{}", sigmoid(x)); println!("{}", sigmoid_lex()); let dx = sigmoid_prime(x); // assert_eq!(dx, autodiff!(x: SIGMOID_LEXICAL)); println!("{}", dx); Ok(()) } #[operator(lexical = sigmoid_lex)] pub fn sigmoid(x: T) -> T where T: Float, { x.exp() / (T::one() + x.exp()) } pub fn sigmoid_prime(x: T) -> T where T: Float, { sigmoid(x) * (T::one() - sigmoid(x)) }