π Computing Derivatives with a Computation Graph
This notebook explains how to compute derivatives using a computation graph, following the example from Andrew Ng's neural networks course. It breaks down a simple function into smaller steps and shows how to apply the chain rule to calculate how changes in inputs affect the final output.
π§ The Functionβ
We are given:
J=3(a+bc)
Letβs break it into smaller steps:
- u=bΓc
- v=a+u
- J=3Γv
β
Forward Passβ
Given values:
- a=5
- b=3
- c=2
We compute:
- u=3Γ2=6
- v=5+6=11
- J=3Γ11=33
π Backward Pass (Derivatives)β
We use the chain rule to compute how much changing each input affects the output J.
Step 1: dvdJβ=3β
Because:
J=3vβIfΒ vβ1,Jβ3
Step 2: dudvβ=1β
Because:
v=a+uβIfΒ uβ1,vβ1
Step 3: dudJβ=dvdJβΓdudvβ=3Γ1=3β
1. dadJββ
- v=a+uβdadvβ=1
- dadJβ=dvdJβΓdadvβ=3Γ1=3
2. dbdJββ
- u=bΓcβdbduβ=c=2
- dbdJβ=dudJβΓdbduβ=3Γ2=6
3. dcdJββ
- u=bΓcβdcduβ=b=3
- dcdJβ=dudJβΓdcduβ=3Γ3=9
β
Final Summary Tableβ
Variable | Derivative |
---|
a | dadJβ=3 |
b | dbdJβ=6 |
c | dcdJβ=9 |
This tells us how much each input influences the final output J using derivatives and chain rule in a computation graph.