cg_function {cgraph}R Documentation

Create function

Description

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

Usage

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 val 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

#' # Create a custom negation function
f <- cg_function(
    def = function(x) -x,
    grads = list(function(x, val, grad) -grad)
)


[Package cgraph version 4.0.3 Index]