cg_graph_forward: Forward Pass

Description Usage Arguments Value Note Author(s) Examples

View source: R/graph.R

Description

Perform a forward pass to evaluate a given target node in a graph.

Usage

1
cg_graph_forward(graph, target)

Arguments

graph

cg_graph object, graph that is evaluated.

target

cg_node object, node in the graph that is evaluated. Alternatively, argument target can be a character scalar denoting the name of the node in the graph that is evaluated.

Value

None.

Note

All nodes required to compute the target node must have a value or their value must be able to be computed at run-time. Only those nodes needed to compute the target node (including the target itself) are evaluated.

The value of a node can be retrieved via the values data member of a cg_node object.

If the name of the target node is supplied to argument target, a linear search is performed to retrieve the node from the graph. In case multiple nodes share the same name, the last node added to the graph is retrieved. Please note that this linear search can become relatively expensive for large graphs.

Author(s)

Ron Triepels

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Initialize a computational graph
graph <- cg_graph()

# Add an input
a <- cg_input(name = "a")

# Square the input (i.e. b = a^2)
b <- cg_pow(a, 2, name = "b")

# Set a equal to 2
a$value <- 2

# Perform forward pass
cg_graph_forward(graph, b)

# Retrieve the value of b
b$value

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