Skip to content

Commit 59a159b

Browse files
committed
Few edits on autodiff for clarity
1 parent ffc5bc7 commit 59a159b

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

tutorial.ipynb

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
" <img src=\"fig/compgraph.png\" alt=\"test\" style=\"width:60%; margin:auto; display:block;\"/>\n",
241241
"</a>\n",
242242
"\n",
243-
"| $\\frac{dz}{dx}$ | $\\frac{dz}{dy}$ |\n",
243+
"| $\\frac{\\partial z}{\\partial x}$ | $\\frac{\\partial z}{\\partial y}$ |\n",
244244
"|--------------|---------|\n",
245245
"| $ \\frac{\\partial z}{\\partial x} = \\frac{\\partial u_1}{\\partial x} + \\frac{\\partial u_2}{\\partial x}$ | $\\frac{\\partial z}{\\partial y} = \\frac{\\partial u_1}{\\partial y} + \\frac{\\partial u_2}{\\partial y}$ | \n",
246246
"| $\\frac{\\partial u_1}{\\partial x} = \\frac{\\partial (x^2)}{\\partial x} = 2x $ | $\\frac{\\partial u_1}{\\partial y} = \\frac{\\partial (x^2)}{\\partial y} = 0$ | \n",
@@ -260,19 +260,42 @@
260260
"source": [
261261
"<h2 style=\"color: #b51f2a\">Forward mode and reverse mode autodiff</h2>\n",
262262
"\n",
263+
"$z = x^2 + 3xy +1 \\ ; \\ u_1 = x^2 \\ ; \\ u_2 = 3xy \\ ; \\ z = u_1 + u_2 + 1$\n",
264+
"\n",
263265
"### Forward mode\n",
264-
"- Computes derivatives in a single forward pass in the computational graph, computing the derivatives alongside function values.\n",
265-
"- Computes derivatives **one input at a time**.\n",
266+
"- Propagates derivatives from inputs to outputs in a single forward pass in the computational graph by computing function values and their derivatives simultaneously.\n",
267+
" - the calculation is basically what we saw in the previous slide\n",
266268
"\n",
267269
"### Reverse mode\n",
268-
"- Computes gradients backward in the computational graph using the chain rule (used in <u>backpropagation</u>).\n",
269-
"- Computes derivatives **one output at a time** but for all inputs.\n",
270-
"\n",
270+
"- Computes gradients backward in the computational graph using the chain rule (used in <u>backpropagation</u>)\n",
271+
" - Start with $ \\frac{\\partial z}{\\partial z} = 1 $\n",
272+
" - Compute contributions to intermediate variables:\n",
273+
" - $ \\frac{\\partial z}{\\partial u_1} = 1, \\quad \\frac{\\partial z}{\\partial u_2} = 1 $\n",
274+
" - $ \\frac{\\partial u_1}{\\partial x} = 2x $\n",
275+
" - $ \\frac{\\partial u_2}{\\partial x} = 3y, \\quad \\frac{\\partial u_2}{\\partial y} = 3x $\n",
276+
" - Apply the chain rule:\n",
277+
" - $ \\frac{\\partial z}{\\partial x} = \\frac{\\partial z}{\\partial u_1} \\cdot \\frac{\\partial u_1}{\\partial x} + \\frac{\\partial z}{\\partial u_2} \\cdot \\frac{\\partial u_2}{\\partial x} = 2x + 3y $\n",
278+
" - $ \\frac{\\partial z}{\\partial y} = \\frac{\\partial z}{\\partial u_2} \\cdot \\frac{\\partial u_2}{\\partial y} = 3x $\n"
279+
]
280+
},
281+
{
282+
"cell_type": "markdown",
283+
"metadata": {
284+
"slideshow": {
285+
"slide_type": "slide"
286+
}
287+
},
288+
"source": [
289+
"<h2 style=\"color: #b51f2a\">Forward mode and reverse mode autodiff</h2>\n",
271290
"\n",
272291
"| Mode | Best for | Complexity | Common Use Cases |\n",
273292
"|--------------|---------|------------|------------------|\n",
274293
"| Forward Mode | Few inputs, many outputs | O(n) per input | Physics simulations, sensitivity analysis |\n",
275-
"| Reverse Mode | Many inputs, few outputs | O(n) per output | Deep learning, optimization problems |\n"
294+
"| Reverse Mode | Many inputs, few outputs | O(n) per output | Deep learning, optimization problems |\n",
295+
"\n",
296+
"<a href=https://e-dorigatti.github.io/math/deep%20learning/2020/04/07/autodiff.html>\n",
297+
" <img src=\"fig/compgraph.png\" alt=\"test\" style=\"width:60%; margin:auto; display:block;\"/>\n",
298+
"</a>"
276299
]
277300
},
278301
{

0 commit comments

Comments
 (0)