knitr::opts_chunk$set(echo = TRUE)
require(autodiffr) ad_setup() # to ensure it is established ores <- function(x){ x # Function will be the parameters. ofn is sum of squares } logit <- function(x) exp(x) / (1 + exp(x)) ofn <- function(x){ res <- ores(x) # returns a vector of residual values sum(logit(res) ^ 2) } ## Now try to generate the gradient function ogr <- makeGradFunc(ofn) system.time(ogr(runif(100))) system.time(ogr(runif(100))) ogr1 <- makeGradFunc(ofn, x = runif(100)) system.time(ogr1(runif(100))) system.time(ogr1(runif(100))) ogr2 <- makeGradFunc(ofn, x = runif(100), use_tape = TRUE) system.time(ogr2(runif(100))) system.time(ogr2(runif(100)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.