o
odin.langpkg.dev
packages / library / odin-autodiff

odin-autodiff

85bd762library

Basic automatic differentiation in Odin

MIT · updated 3 years ago

Odin AutoDiff

A basic library for automatic differentiation in Odin.

This implements Forward Accumulation by storing a list of operations (including derivatives) that get re-executed to calculate the effect of varying one (or more) inputs on the system.

The basic building block is a Var, which is an arbitray-length vector (including 1) representing constants, inputs, intermediate values, and outputs. Var are related by Op (operations), such as add(). The lists of Vars, Ops, and backing memory are bundled in a Graph

Usage

graph : ^Graph = graph_init()
x : Var = var_copy(graph, []f64{3}, "x")
y : Var = var_copy(graph, []f64{4}, "y")

z : Var = mult(x, y, "z")

uncertainty_collect(graph, targets = []Var{z}, knobs = []Var{x,y})

There are more examples in the code!