|
240 | 240 | " <img src=\"fig/compgraph.png\" alt=\"test\" style=\"width:60%; margin:auto; display:block;\"/>\n",
|
241 | 241 | "</a>\n",
|
242 | 242 | "\n",
|
243 |
| - "| $\\frac{dz}{dx}$ | $\\frac{dz}{dy}$ |\n", |
| 243 | + "| $\\frac{\\partial z}{\\partial x}$ | $\\frac{\\partial z}{\\partial y}$ |\n", |
244 | 244 | "|--------------|---------|\n",
|
245 | 245 | "| $ \\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",
|
246 | 246 | "| $\\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 | 260 | "source": [
|
261 | 261 | "<h2 style=\"color: #b51f2a\">Forward mode and reverse mode autodiff</h2>\n",
|
262 | 262 | "\n",
|
| 263 | + "$z = x^2 + 3xy +1 \\ ; \\ u_1 = x^2 \\ ; \\ u_2 = 3xy \\ ; \\ z = u_1 + u_2 + 1$\n", |
| 264 | + "\n", |
263 | 265 | "### 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", |
266 | 268 | "\n",
|
267 | 269 | "### 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", |
271 | 290 | "\n",
|
272 | 291 | "| Mode | Best for | Complexity | Common Use Cases |\n",
|
273 | 292 | "|--------------|---------|------------|------------------|\n",
|
274 | 293 | "| 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>" |
276 | 299 | ]
|
277 | 300 | },
|
278 | 301 | {
|
|
0 commit comments