These functions give (optimized) gradient, jacobian or hessian functions for the target function.

makeJacobianFunc(func, ..., mode = c("reverse", "forward"), x = NULL,
  chunk_size = NULL, use_tape = FALSE, compiled = FALSE,
  debug = TRUE)

makeHessianFunc(func, ..., mode = c("reverse", "forward"), x = NULL,
  chunk_size = NULL, use_tape = FALSE, compiled = FALSE,
  debug = TRUE)

makeGradFunc(func, ..., mode = c("reverse", "forward"), x = NULL,
  chunk_size = NULL, use_tape = FALSE, compiled = FALSE,
  debug = TRUE)

makeDerivFunc(func, ..., mode = c("reverse", "forward"), x = NULL,
  chunk_size = NULL, use_tape = FALSE, compiled = FALSE,
  debug = TRUE)

Arguments

func

the target function to calculate gradient, jacobian or hessian.

...

other arguments passed to the target function func.

mode

whether to use forward or reverse mode automatic differentiation.

x

If x is given, then the returning functiopn will be optimized w.r.t. the input(s) of the same shape with x. Note that if x is not given, then all the following parameters will be ignored.

chunk_size

the chunk size to use in forward mode automatic differentiation. Note that this parameter is only effective when mode = "forward".

use_tape

whether or not to use tape for reverse mode automatic differentiation. Note that although use_tape can greatly improve the performance sometime, it can only calculate the derivatives w.r.t a certain branching, so it may not give the correct result for functions containing things like if. And this parameter is only effective when mode = "reverse".

compiled

whether or not to use compiled tape for reverse mode automatic differentiation. Note that tape compiling can take a lot of time and this parameter is only effective when use_tape = TRUE.

debug

Whether to activate debug mode. With the debug mode, users can have more informative error messages. Without the debug mode, functions will be more performant.

Value

if x is not given, the returned function will be a general function to calculate derivatives, which accepts other arguments to func besides x; if x is given, the returned function will be an optimized function speciallised for inputs of the same shape with the given x.