Skip to content
Glacius
CalculusConcept reference

Computational graphs

A computational graph represents elementary operations as nodes connected by their input dependencies.

On this page 8 sections
  1. Overview
  2. Understand the idea
  3. Operation order changes the expression
  4. A value may feed more than one operation
  5. If an intermediate result is reused, draw its outgoing edges from the same node
  6. Key takeaway
  7. Sources & further reading
  8. Concept connections

01Understand the idea#

A computational graph breaks a formula into small operations connected by their dependencies. It shows which intermediate values must exist before later values can be computed. Training systems use the same dependency structure to propagate derivatives backward.

A computational graph names the small operations inside an expression. Each arrow points from an input value to an operation that uses it.

A schematic computation graph for y=(x+3)². The input x feeds u=x+3. The resulting u feeds y=u². Arrows follow the value dependencies; no scale is encoded.A schematic computation graph for y=(x+3)². The input x feeds u=x+3. The resulting u feeds y=u². Arrows follow the value dependencies; no scale is encoded.
Figure 1A schematic computation graph for y=(x+3)². The input x feeds u=x+3. The resulting u feeds y=u². Arrows follow the value dependencies; no scale is encoded.
Link to this figure ↗Download SVGDownload PNG

For y=(x+3)2y=(x+3)^2, first name the sum u=x+3u=x+3. Then write y=u2y=u^2. The square receives uu, so the edge runs from uu to yy.

These node equations also describe the graph in text: every variable on the right is an incoming dependency.

For y=(x+2)2y=(x+2)^2, create a node u=x+2u=x+2 and then a node y=u2y=u^2. At x=3x=3, the first node gives 5 and the next gives 25. The edge from uu to the square means the square consumes uu. An edge is a dependency, not an instruction to add the two node labels.

Check your reasoning

Represent y=(x+6)2y=(x+6)^2. Choose node equations.

  1. Au=x2u=x^2; y=u+6y=u+6
  2. Bu=x+6u=x+6; y=x2y=x^2
  3. Cu=x+6u=x+6; y=u2y=u^2
Show answer and explanation
u=x+6u=x+6; y=u2y=u^2

The square uses the sum uu.

02Operation order changes the expression#

Operation order changes the expression. Squaring first and then adding 33 gives x2+3x^2+3. To represent (x+3)2(x+3)^2, the add node must come first.

Each node can be one small operation. A whole model layer is not required.

Check your reasoning

Square input xx, then multiply the result by 77. Choose nodes for yy.

  1. Au=x2u=x^2; y=7uy=7u
  2. Bu=7xu=7x; y=u2y=u^2
  3. Cu=x2u=x^2; y=u+7y=u+7
Show answer and explanation
u=x2u=x^2; y=7uy=7u

Multiply the squared result by the fixed factor.

03A value may feed more than one operation#

A value may feed more than one operation. For y=x(x+1)y=x(x+1), write u=x+1u=x+1 and y=xuy=xu. The input xx feeds both the addition and the final multiplication.

Substitute the intermediate node into the output node to check that the graph represents the intended formula.

Check your reasoning

Target: y=x(x+8)y=x(x+8). A graph uses u=x2u=x^2; y=u+8y=u+8. Choose the repaired graph.

  1. Au=x+8u=x+8; y=u2y=u^2
  2. Bu=x+8u=x+8; y=xuy=xu
  3. Cu=x2u=x^2; y=u+8y=u+8
Show answer and explanation
u=x+8u=x+8; y=xuy=xu

The output multiplies original xx by sum uu.

04If an intermediate result is reused, draw its outgoing edges from the same node#

If an intermediate result is reused, draw its outgoing edges from the same node. That shared node matters later: its effect on a loss includes every downstream use. Replacing a dependency graph with the written order of symbols can hide those shared paths.

Key takeaway

Name the operations and connect each node to the inputs it uses.

  • Represent a scalar expression as a directed graph of elementary operations.

Sources & further reading

  1. [1]
    Stanford CS231n: BackpropagationStanford CS231n · Article

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Computational graphs.” Math behind ML. /learn/c-graph