AUTOmatic Derivatives & Jacobians by djmaxus and you
```rust use autodj::single::*;
let x : DualF64 = 2.0.into_variable();
// Arithmetic operations are required by trait bounds let _f = x * x + 1.0.into();
// Arithmetic rules itself are defined in Dual
trait
// on borrowed values for extendability
let f = (x*x).add_impl(&1.0.into());
// Dual can be decomposed into a value-derivative pair assert_eq!(f.decompose(), (5.0, 4.0));
// fmt::Display resembles Taylor expansion assert_eq!(format!("{f}"), "5+4∆"); ```
Multivariate differentiation is based on multiple dual components. Such an approach requires no repetitive and "backward" differentiations. Each partial derivative is tracked separately from the start, and no repetitive calculations are made.
For built-in multivariate specializations,
independent variables can be created consistently using .into_variables()
method.
```rust use autodj::array::*;
// consistent set of independent variables
let [x, y] : [DualNumber
let f = x * (y - 1.0.into());
asserteq!(f.value() , & 4.); asserteq!(f.dual().asref(), &[2., 2.]); asserteq!(format!("{f}") , "4+[2.0, 2.0]∆"); ```
```rust use autodj::{ fluid::Dual, vector::* }; use std::ops::Add;
let x = vec![1., 2., 3., 4., 5.].into_variables();
let f : DualF64 = x.iter() .map(|x : &DualF64| x.mul_impl(&2.0.into())) .reduce(Add::add) .unwrap();
assert_eq!(f.value(), &30.);
f.dual() .asref() .iter() .foreach(|deriv| assert_eq!(deriv, &2.0) ); ```
rust
// A trait with all the behavior defined
use autodj::fluid::Dual;
// A generic data structure which implements Dual
use autodj::solid::DualNumber;
I do both academic & business R&D in the area of computational mathematics. As well as many of us, I've written a whole bunch of sophisticated Jacobians by hand.
One day, I learned about automatic differentiation based on dual numbers. Almost the same day, I learned about Rust as well :crab:
Then, I decided to:
You are very welcome to introduce issues to promote most wanted features or to report a bug.
num-traits
nalgebra
etc.)f64
autodiff
As far as I noticed, autodj
currently has the following differences
fmt::Display
for statically-known number of variables.into-variables()
, .eval()
, etc.f64
num
and nalgebra
cratesSome differences are planned to be eliminated as noted in the roadmap.
Within this crate, you may study & launch test target /tests/autodiff.rs
to follow some differences.
shell
cargo test --test autodiff -- --show-output