reverse
Reverse mode automatic differentiation in Rust.
To use this in your crate, add the following to Cargo.toml
:
= "0.1"
reverse
Examples
use *;
Reverse mode automatic differentiation in Rust.
To use this in your crate, add the following to Cargo.toml
:
[dependencies]
reverse = "0.1"
use reverse::*;
fn main() {
let graph = Graph::new();
let a = graph.add_var(2.5);
let b = graph.add_var(14.);
let c = (a.sin() + b.ln() * 3.) - 5.;
let gradients = c.backward();
assert_eq!(gradients.wrt(&a), 2.5_f64.cos());
assert_eq!(gradients.wrt(&b), 3. / 14.);
}