Let f(x,y)=ax2log⁡(by+c), where the inputs x,y and the parameters a,b,c are all scalars and log⁡ is the natural log. What is the computational graph with intermediate nodes, and how do you use backpropagation on it to compute ∂f/∂b?

Deep learning, Backpropagation
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can break a function into a graph of simple nodes, and run the backward pass node by node, multiplying the upstream gradient by each local gradient.

Key idea

A computational graph has one node per simple operation. In the backward pass, each node's gradient is (upstream gradient) × (local gradient): the gradient arriving from later in the graph times the node's own derivative. Along the path b→v=by→w=v+c→s=log⁡w→f=t s, where t=ax2, this gives ∂f∂b=ax2⋅1by+c⋅1⋅y=ax2yby+c.

Steps

  1. Forward pass and graph: break f into one operation per node (u=x2, t=au, v=by, w=v+c, s=log⁡w, f=t⋅s), giving the two-branch graph x→u→t (with a into t) and b,y→v→w (with c into w) →s, joining at t,s→f.
  2. Start the backward pass with fˉ=∂f/∂f=1. A bar means the gradient of f with respect to that node, e.g. sˉ=∂f/∂s.
  3. Multiply node f=t s: its local gradient with respect to s is t, so sˉ=fˉ⋅t=ax2 (and tˉ=fˉ⋅s=log⁡(by+c)).
  4. Log node: wˉ=sˉ⋅1w=ax2by+c. Add node: vˉ=wˉ⋅1 (and cˉ=wˉ). Multiply node v=by: bˉ=vˉ⋅y.
  5. Result: ∂f∂b=ax2yby+c. The same pass also gives ∂f/∂a=x2log⁡(by+c) and ∂f/∂c=ax2by+c for free.
  6. Sanity check with numbers a=1,x=2,b=1,y=1,c=1: ∂f/∂b=4⋅1/2=2. This matches a finite difference of f=4log⁡(b+1) at b=1 (nudge b slightly and see how much f changes).

Common mistakes

How long your answer should be

Half a page: the graph, the backward pass node by node and a numeric check; about 4 minutes.

Read this

Previous in Deep learning: A three-class classifier outputs the probability vector y^=[0.3, 0.6, 0.1]⊤, and the true class is the second one. What is the cross-entropy loss?
Next in Deep learning: A convolutional layer takes a 32×32×3 input and applies 16 filters of size 5×5 with stride 1 and padding 2. What is the output shape, and how many learnable parameters does the layer have? What changes if the stride is 2 and the padding is 0?