Reverse-mode autodiff for R
This package implements a proof-of-concept of reverse-mode autodiff for
R functions. The package is motivated and influenced by
jax
without being very mature or
computationally performant.
library(jar)
logpdf <- function(y, mu, sigma) {
-0.5 * ((y - mu) / sigma) ^ 2 - log(sigma) - 0.5 * log(2*pi)
}
grad(logpdf, 1L)(1.0, 0.0, 1.0)
## [1] -1
grad(logpdf, 2L)(1.0, 0.0, 1.0)
## [1] 1
grad(logpdf, 3L)(1.0, 0.0, 1.0)
## [1] 0
Get the package using:
devtools::install_github("dirmeier/jar")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.