dorset 0.1.0

A rust implementation of Stan Math automatic differentiation library.
Documentation
  • Coverage
  • 21.33%
    16 out of 75 items documented1 out of 40 items with examples
  • Size
  • Source code size: 35.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 38.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • yizhang-yiz/dorset
    10 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • yizhang-cae

Table of Contents

  1. dorset, a rust implementation of Stan Math library.
    1. Example
  2. Lisense

dorset, a rust implementation of Stan Math library.

The project is not intended to be an exact port of Math, but as a proof of concept to take advantage of some Rust features in automatic differentiation, hence meant to be experimental.

Example

Below is how to do the problem example in section 2.1 of the Stan Math paper, using dorset.

#[macro_use]
extern crate dorset;
use dorset::*;

fn main() {
    let y: Real = 1.3;
    let s = cstack!();
    let (mu, sigma) = (var!(s, 0.5), var!(s, 1.2));
    let mut lp = var!(s);
    lp = &lp - 0.5 * (2.0 * PI).ln();
    lp = &lp - ln(&sigma);
    lp = &lp - 0.5 * pow((y - &mu) / &sigma, 2.0);
    lp.grad();
    println!("f(mu, sigma) = {0:.6}", lp.val()); // f(mu, sigma) = -1.323482
    println!("d.f/d.mu = {0:.6}", mu.adj());     // d.f/d.mu = 0.555556
    println!("d.f/d.sigma = {0:.6}", sigma.adj()); // d.f/d.sigma = -0.462963
}

Lisense

BSD-3-Clause