# NOT RUN {
# Initialize a computational graph
graph <- cg_graph()
# Add an input
a <- cg_input(name = "a")
# Add a parameter
b <- cg_parameter(4, name = "b")
# Perform some operations
c <- cg_sin(a) + cg_cos(b) - cg_tan(a)
# Set a equal to 2
a$value <- 2
# Perform forward pass
cg_graph_forward(graph, c)
# Perform backward pass
cg_graph_backward(graph, c)
# Retrieve the derivative of c with respect to b
b$grad
# }
Run the code above in your browser using DataLab