
Last chance! 50% off unlimited learning
Sale ends in
Automatic differentiation
auto_diff(f, wrt = NULL, at)
A function of which the derivative is sought.
A character vector; the name of the variables to differentiate with respect to.
A named list of variables; the point at which the derivative is evaluated.
A dual number with components "x" and "dx". The first gives the value of `f`, and the second gives the derivative of `f`.
# NOT RUN {
f <- function(y, X, beta) { y - X %*% beta }
auto_diff(
f, wrt = "beta",
at = list(beta = c(5,6), X = matrix(1:4, 2, 2), y = c(2,3))
)
g <- function(X, Y) { X %*% Y }
X <- randn(2, 2)
Y <- randn(2, 2)
auto_diff(g, at = list(X = X, Y = Y))
# }
Run the code above in your browser using DataLab