Computational Graph

Computational Graph

  • The way computation can be modelled in a Neural Network .

  • Directional graph

  • Matrix operations are represented as compute nodes

  • Variables or scalar operators are vertex nodes

  • Directional edges show the flow of inputs to vertices

  • In a way the computational graph is equivalent to a syntax tree of a math expression

Evaluation #

Evaluating the neural network based on the Compute Graph and all the weights and input vector.

  • Evaluate by tree walking
  • starting at the leafs

Evaluation of the gradient #

For Gradient Descent we need to compute the gradient of the Loss Function (which is also part of the compute graph). So we are interested in:

computational_graph_b150762354b7ba83f35f4e2b03b5616cf45d0bdb.svg
  1. To do this, first evaluate the loss function as described above and let each node remember it’s intermediate result.
  2. Compute the partial derivatives for compute nodes. Here:
    • computational_graph_51170e5dc75704e12910d16879e92ed4abda324b.svg; computational_graph_2b4e4fcf7a14813db253a74dd593019d7262136a.svg; computational_graph_0fd4cd4a89bac84d4d5ad9bad09db47087eb43ff.svg
    • computational_graph_e2b968039a124904018f983e9f84c734a0a1403f.svg; computational_graph_a540bdcbc8440eac9af7d22a9833421610948b77.svg; computational_graph_5d0df9188d53a127fb4273342577cde39fba7a97.svg
  3. Walk the graph backwards
    • We know the parial derivative of the last node
    • We also know the evaluated values of the nodes contributing to the final node
    • So each node we can annotate with the value of their derivative under the current evaluation
    • Recursively do this until all leafs are reached
    • According to the chain rule, the resulting derivative value must be multiplied with the parents derivative value
Calendar October 22, 2023