cg_function {cgraph} | R Documentation |
Initialize a new function that can be used by operators in a graph.
cg_function(def, grads = list())
def |
function, the definition of the function. |
grads |
list of functions, the gradient functions with respect to each input (optional). |
cg_function object.
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.
Ron Triepels
#' # Create a custom negation function f <- cg_function( def = function(x) -x, grads = list(function(x, val, grad) -grad) )