knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(RAutoDiff)

Introduction

This document provides an overview of the different functions currently implemented (overloaded) for used with the Automatic Differentiation provided in package RAutoDiff. Most of the functions are written in order to "work" in the same way as the corresponding functions taking regular R-variables as inputs. Therefore this document provides only limited description of these, and the documentation elsewhere is also rather sparse.

Summary of functions and classes

Classes

The package provides three S4 classes and one class union:

In what remains, fAD and fAD2 should have a similar behavior (in the sense that the methods available for manipulating these should have the same names) as the built in numeric vector class numeric, and AD_matrix should have a similar behavior as built in numeric matrix class

Examples: (in general please avoid accessing and manipulating the slots of the classes directly)

x.n <- c(1,2)
x <- independent2(x.n)
print(x@val) # value of variable
print(x@jac) # jacobian wrt to x.n
print(x@hessian) # hessians of x[i] with respect to x.n

m <- diag(x) # diagonal 2x2 AD_matrix
print(m@nrow)
print(m@ncol)
print(m@vals) 

In general, calculation with fAD-types is somewhat faster (close to fully vectorized) than for fAD2 (several functions have for-loops), and hence fAD2 should be avoided if you do not need second derivatives.

Creation and extraction

Creating AD types

Extracting from AD types

Available functions for ADtypes

Non-numerical

Binary numerical

All of the below apply also for mixed (numeric and ADtype) class argument, e.g. 3 + x or x * c(1,2.5). The methods recycle element in case of different sizes of the arguments.

Binary non-numerical

Unary numerical

Reductions

Available functions for AD_matrix

Non-numerical

Elementwise binary numerical

Including between mixed types:

Elementwise unary numerical

Linear Algebra

Reductions



torekleppe/RAutoDiff documentation built on Dec. 23, 2021, noon