cg_function: Create function

Description Usage Arguments Value Note Author(s) Examples

View source: R/function.R

Description

Initialize a new function that can be used by operators in a graph.

Usage

1
cg_function(def, grads = list())

Arguments

def

function, the definition of the function.

grads

list of functions, the gradient functions with respect to each input (optional).

Value

cg_function object.

Note

If the function consumes any inputs, then the gradient function with respect to these inputs must be provided to argument grads. These gradients must be a function of each input's gradient and take as arguments the inputs of the function including argument value and grad. These latter two arguments evaluate to the value of the function and its gradient respectively at run-time.

Author(s)

Ron Triepels

Examples

1
2
3
4
5
#' # Create a custom negation function
f <- cg_function(
    def = function(x) -x,
    grads = list(function(x, value, grad) -grad)
)

cgraph documentation built on Feb. 9, 2020, 5:07 p.m.

Related to cg_function in cgraph...