|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "raw", |
5 | | - "id": "5f3c51d6", |
| 5 | + "id": "d29bfcfc", |
6 | 6 | "metadata": { |
7 | 7 | "raw_mimetype": "text/restructuredtext" |
8 | 8 | }, |
|
13 | 13 | }, |
14 | 14 | { |
15 | 15 | "cell_type": "markdown", |
16 | | - "id": "fa519b0e", |
| 16 | + "id": "8371f87e", |
17 | 17 | "metadata": {}, |
18 | 18 | "source": [ |
19 | 19 | "<div class=\"alert alert-info\">\n", |
|
27 | 27 | }, |
28 | 28 | { |
29 | 29 | "cell_type": "markdown", |
30 | | - "id": "b36fff16", |
| 30 | + "id": "18124dc8", |
31 | 31 | "metadata": {}, |
32 | 32 | "source": [ |
33 | 33 | "# Automatic Differentiation" |
34 | 34 | ] |
35 | 35 | }, |
36 | 36 | { |
37 | 37 | "cell_type": "markdown", |
38 | | - "id": "6a5e2c13", |
| 38 | + "id": "52b02dcc", |
39 | 39 | "metadata": { |
40 | 40 | "lines_to_next_cell": 2 |
41 | 41 | }, |
|
73 | 73 | }, |
74 | 74 | { |
75 | 75 | "cell_type": "markdown", |
76 | | - "id": "f49ecb98", |
| 76 | + "id": "391e0110", |
77 | 77 | "metadata": {}, |
78 | 78 | "source": [ |
79 | 79 | "## Introduction to MyGrad" |
80 | 80 | ] |
81 | 81 | }, |
82 | 82 | { |
83 | 83 | "cell_type": "markdown", |
84 | | - "id": "208bef8f", |
| 84 | + "id": "a402adf5", |
85 | 85 | "metadata": {}, |
86 | 86 | "source": [ |
87 | 87 | "\n", |
|
146 | 146 | }, |
147 | 147 | { |
148 | 148 | "cell_type": "markdown", |
149 | | - "id": "9159288c", |
| 149 | + "id": "3989dfa1", |
150 | 150 | "metadata": {}, |
151 | 151 | "source": [ |
152 | 152 | "It is important to reiterate that MyGrad *never gives us the actual function* $\\frac{\\mathrm{d}f}{\\mathrm{d}x}$; it only computes the derivative evaluated at a specific input $x=10$." |
153 | 153 | ] |
154 | 154 | }, |
155 | 155 | { |
156 | 156 | "cell_type": "markdown", |
157 | | - "id": "8e505337", |
| 157 | + "id": "0eb133b2", |
158 | 158 | "metadata": {}, |
159 | 159 | "source": [ |
160 | 160 | "### MyGrad Adds \"Drop-In\" AutoDiff to NumPy\n" |
161 | 161 | ] |
162 | 162 | }, |
163 | 163 | { |
164 | 164 | "cell_type": "markdown", |
165 | | - "id": "175e840c", |
| 165 | + "id": "0abe8175", |
166 | 166 | "metadata": {}, |
167 | 167 | "source": [ |
168 | 168 | "\n", |
|
186 | 186 | }, |
187 | 187 | { |
188 | 188 | "cell_type": "markdown", |
189 | | - "id": "e397f16c", |
| 189 | + "id": "7f737971", |
190 | 190 | "metadata": { |
191 | 191 | "lines_to_next_cell": 2 |
192 | 192 | }, |
|
218 | 218 | }, |
219 | 219 | { |
220 | 220 | "cell_type": "markdown", |
221 | | - "id": "fdaebad6", |
| 221 | + "id": "7352acee", |
222 | 222 | "metadata": {}, |
223 | 223 | "source": [ |
224 | 224 | "## Vectorized Auto-Differentiation" |
225 | 225 | ] |
226 | 226 | }, |
227 | 227 | { |
228 | 228 | "cell_type": "markdown", |
229 | | - "id": "ac75b5a9", |
| 229 | + "id": "f2614315", |
230 | 230 | "metadata": {}, |
231 | 231 | "source": [ |
232 | 232 | "Like NumPy's array, MyGrad's tensor supports [vectorized operations](https://www.pythonlikeyoumeanit.com/Module3_IntroducingNumpy/VectorizedOperations.html), allowing us to evaluate the derivative of a function at multiple points simultaneously.\n", |
|
273 | 273 | }, |
274 | 274 | { |
275 | 275 | "cell_type": "markdown", |
276 | | - "id": "4ba915d9", |
| 276 | + "id": "da65df83", |
277 | 277 | "metadata": {}, |
278 | 278 | "source": [ |
279 | 279 | "<div class=\"alert alert-info\">" |
280 | 280 | ] |
281 | 281 | }, |
282 | 282 | { |
283 | 283 | "cell_type": "markdown", |
284 | | - "id": "769f3243", |
| 284 | + "id": "0a704f14", |
285 | 285 | "metadata": {}, |
286 | 286 | "source": [ |
287 | 287 | "## Visualizing the Derivative\n", |
|
296 | 296 | { |
297 | 297 | "cell_type": "code", |
298 | 298 | "execution_count": 1, |
299 | | - "id": "ea11710e", |
| 299 | + "id": "3962a57c", |
300 | 300 | "metadata": { |
301 | 301 | "execution": { |
302 | | - "iopub.execute_input": "2022-01-30T01:36:28.789638Z", |
303 | | - "iopub.status.busy": "2022-01-30T01:36:28.787641Z", |
304 | | - "iopub.status.idle": "2022-01-30T01:36:30.944058Z", |
305 | | - "shell.execute_reply": "2022-01-30T01:36:30.944058Z" |
| 302 | + "iopub.execute_input": "2022-01-30T17:58:48.993757Z", |
| 303 | + "iopub.status.busy": "2022-01-30T17:58:48.990755Z", |
| 304 | + "iopub.status.idle": "2022-01-30T17:58:51.023711Z", |
| 305 | + "shell.execute_reply": "2022-01-30T17:58:51.022685Z" |
306 | 306 | } |
307 | 307 | }, |
308 | 308 | "outputs": [ |
|
353 | 353 | }, |
354 | 354 | { |
355 | 355 | "cell_type": "markdown", |
356 | | - "id": "32f3b8ef", |
| 356 | + "id": "d9b0203f", |
357 | 357 | "metadata": {}, |
358 | 358 | "source": [ |
359 | 359 | "## Seek and Derive" |
360 | 360 | ] |
361 | 361 | }, |
362 | 362 | { |
363 | 363 | "cell_type": "markdown", |
364 | | - "id": "e0fa9dee", |
| 364 | + "id": "5811b985", |
365 | 365 | "metadata": {}, |
366 | 366 | "source": [ |
367 | 367 | "Computers equipped with automatic differentiation libraries can make short work of derivatives that are well-beyond the reach of mere mortals.\n", |
|
397 | 397 | }, |
398 | 398 | { |
399 | 399 | "cell_type": "markdown", |
400 | | - "id": "74da8249", |
| 400 | + "id": "549bf18c", |
401 | 401 | "metadata": {}, |
402 | 402 | "source": [ |
403 | 403 | "<div class=\"alert alert-info\">\n", |
|
418 | 418 | }, |
419 | 419 | { |
420 | 420 | "cell_type": "markdown", |
421 | | - "id": "9af7bf0d", |
| 421 | + "id": "b00caa03", |
422 | 422 | "metadata": { |
423 | 423 | "lines_to_next_cell": 0 |
424 | 424 | }, |
|
428 | 428 | }, |
429 | 429 | { |
430 | 430 | "cell_type": "markdown", |
431 | | - "id": "e4cd5906", |
| 431 | + "id": "184b9ffc", |
432 | 432 | "metadata": {}, |
433 | 433 | "source": [ |
434 | 434 | "\n", |
|
447 | 447 | "Let's take a simple example.\n", |
448 | 448 | "We'll choose the function $f(x) = (x-8)^2$ and the starting point $x=-1.5$.\n", |
449 | 449 | "As we search for $x_\\mathrm{min}$ we don't want to make our updates to $x_o$\n", |
450 | | - "too big, so we will scale our updates by a factor of $3/10$ (which is somewhat haphazardly here).\n", |
| 450 | + "too big, so we will scale our updates by a factor of $3/10$ (the value of which is chosen somewhat haphazardly here).\n", |
451 | 451 | "\n", |
452 | 452 | "```python\n", |
453 | 453 | "# Performing gradient descent on f(x) = (x - 8) ** 2\n", |
|
491 | 491 | }, |
492 | 492 | { |
493 | 493 | "cell_type": "markdown", |
494 | | - "id": "44c65efd", |
| 494 | + "id": "3188cd27", |
495 | 495 | "metadata": {}, |
496 | 496 | "source": [ |
497 | 497 | "## Reading Comprehension Exercise Solutions" |
498 | 498 | ] |
499 | 499 | }, |
500 | 500 | { |
501 | 501 | "cell_type": "markdown", |
502 | | - "id": "e2167a40", |
| 502 | + "id": "92d9cc26", |
503 | 503 | "metadata": {}, |
504 | 504 | "source": [ |
505 | 505 | "**Auto-differentiation: Solution**" |
|
508 | 508 | { |
509 | 509 | "cell_type": "code", |
510 | 510 | "execution_count": 2, |
511 | | - "id": "15448e32", |
| 511 | + "id": "4ec64b05", |
512 | 512 | "metadata": { |
513 | 513 | "execution": { |
514 | | - "iopub.execute_input": "2022-01-30T01:36:30.952052Z", |
515 | | - "iopub.status.busy": "2022-01-30T01:36:30.951053Z", |
516 | | - "iopub.status.idle": "2022-01-30T01:36:30.960051Z", |
517 | | - "shell.execute_reply": "2022-01-30T01:36:30.960051Z" |
| 514 | + "iopub.execute_input": "2022-01-30T17:58:51.032677Z", |
| 515 | + "iopub.status.busy": "2022-01-30T17:58:51.031680Z", |
| 516 | + "iopub.status.idle": "2022-01-30T17:58:51.054848Z", |
| 517 | + "shell.execute_reply": "2022-01-30T17:58:51.053809Z" |
518 | 518 | } |
519 | 519 | }, |
520 | 520 | "outputs": [ |
|
548 | 548 | { |
549 | 549 | "cell_type": "code", |
550 | 550 | "execution_count": 3, |
551 | | - "id": "79c175e2", |
| 551 | + "id": "a150ad66", |
552 | 552 | "metadata": { |
553 | 553 | "execution": { |
554 | | - "iopub.execute_input": "2022-01-30T01:36:31.019052Z", |
555 | | - "iopub.status.busy": "2022-01-30T01:36:30.968050Z", |
556 | | - "iopub.status.idle": "2022-01-30T01:36:31.213057Z", |
557 | | - "shell.execute_reply": "2022-01-30T01:36:31.214051Z" |
| 554 | + "iopub.execute_input": "2022-01-30T17:58:51.128812Z", |
| 555 | + "iopub.status.busy": "2022-01-30T17:58:51.125813Z", |
| 556 | + "iopub.status.idle": "2022-01-30T17:58:51.310845Z", |
| 557 | + "shell.execute_reply": "2022-01-30T17:58:51.311817Z" |
558 | 558 | } |
559 | 559 | }, |
560 | 560 | "outputs": [ |
|
578 | 578 | { |
579 | 579 | "cell_type": "code", |
580 | 580 | "execution_count": 4, |
581 | | - "id": "d6e7e5a1", |
| 581 | + "id": "602820b0", |
582 | 582 | "metadata": { |
583 | 583 | "execution": { |
584 | | - "iopub.execute_input": "2022-01-30T01:36:31.225052Z", |
585 | | - "iopub.status.busy": "2022-01-30T01:36:31.221052Z", |
586 | | - "iopub.status.idle": "2022-01-30T01:36:31.229053Z", |
587 | | - "shell.execute_reply": "2022-01-30T01:36:31.230053Z" |
| 584 | + "iopub.execute_input": "2022-01-30T17:58:51.318815Z", |
| 585 | + "iopub.status.busy": "2022-01-30T17:58:51.317817Z", |
| 586 | + "iopub.status.idle": "2022-01-30T17:58:51.326845Z", |
| 587 | + "shell.execute_reply": "2022-01-30T17:58:51.327816Z" |
588 | 588 | } |
589 | 589 | }, |
590 | 590 | "outputs": [ |
|
618 | 618 | { |
619 | 619 | "cell_type": "code", |
620 | 620 | "execution_count": 5, |
621 | | - "id": "d3e2ab46", |
| 621 | + "id": "eaa3d402", |
622 | 622 | "metadata": { |
623 | 623 | "execution": { |
624 | | - "iopub.execute_input": "2022-01-30T01:36:31.236056Z", |
625 | | - "iopub.status.busy": "2022-01-30T01:36:31.235085Z", |
626 | | - "iopub.status.idle": "2022-01-30T01:36:31.455059Z", |
627 | | - "shell.execute_reply": "2022-01-30T01:36:31.453052Z" |
| 624 | + "iopub.execute_input": "2022-01-30T17:58:51.334817Z", |
| 625 | + "iopub.status.busy": "2022-01-30T17:58:51.332813Z", |
| 626 | + "iopub.status.idle": "2022-01-30T17:58:51.567820Z", |
| 627 | + "shell.execute_reply": "2022-01-30T17:58:51.570825Z" |
628 | 628 | } |
629 | 629 | }, |
630 | 630 | "outputs": [ |
|
648 | 648 | { |
649 | 649 | "cell_type": "code", |
650 | 650 | "execution_count": 6, |
651 | | - "id": "8de8439e", |
| 651 | + "id": "887cd4b1", |
652 | 652 | "metadata": { |
653 | 653 | "execution": { |
654 | | - "iopub.execute_input": "2022-01-30T01:36:31.468053Z", |
655 | | - "iopub.status.busy": "2022-01-30T01:36:31.467052Z", |
656 | | - "iopub.status.idle": "2022-01-30T01:36:31.482078Z", |
657 | | - "shell.execute_reply": "2022-01-30T01:36:31.483106Z" |
| 654 | + "iopub.execute_input": "2022-01-30T17:58:51.588820Z", |
| 655 | + "iopub.status.busy": "2022-01-30T17:58:51.587824Z", |
| 656 | + "iopub.status.idle": "2022-01-30T17:58:51.621816Z", |
| 657 | + "shell.execute_reply": "2022-01-30T17:58:51.623839Z" |
658 | 658 | } |
659 | 659 | }, |
660 | 660 | "outputs": [ |
|
688 | 688 | { |
689 | 689 | "cell_type": "code", |
690 | 690 | "execution_count": 7, |
691 | | - "id": "c3eec605", |
| 691 | + "id": "693a1ee1", |
692 | 692 | "metadata": { |
693 | 693 | "execution": { |
694 | | - "iopub.execute_input": "2022-01-30T01:36:31.511078Z", |
695 | | - "iopub.status.busy": "2022-01-30T01:36:31.510073Z", |
696 | | - "iopub.status.idle": "2022-01-30T01:36:31.703106Z", |
697 | | - "shell.execute_reply": "2022-01-30T01:36:31.703106Z" |
| 694 | + "iopub.execute_input": "2022-01-30T17:58:51.649818Z", |
| 695 | + "iopub.status.busy": "2022-01-30T17:58:51.646839Z", |
| 696 | + "iopub.status.idle": "2022-01-30T17:58:52.483426Z", |
| 697 | + "shell.execute_reply": "2022-01-30T17:58:52.484422Z" |
698 | 698 | } |
699 | 699 | }, |
700 | 700 | "outputs": [ |
|
718 | 718 | { |
719 | 719 | "cell_type": "code", |
720 | 720 | "execution_count": 8, |
721 | | - "id": "2ce01084", |
| 721 | + "id": "8859b9f9", |
722 | 722 | "metadata": { |
723 | 723 | "execution": { |
724 | | - "iopub.execute_input": "2022-01-30T01:36:31.710075Z", |
725 | | - "iopub.status.busy": "2022-01-30T01:36:31.709073Z", |
726 | | - "iopub.status.idle": "2022-01-30T01:36:31.719076Z", |
727 | | - "shell.execute_reply": "2022-01-30T01:36:31.719076Z" |
| 724 | + "iopub.execute_input": "2022-01-30T17:58:52.495446Z", |
| 725 | + "iopub.status.busy": "2022-01-30T17:58:52.492440Z", |
| 726 | + "iopub.status.idle": "2022-01-30T17:58:52.516422Z", |
| 727 | + "shell.execute_reply": "2022-01-30T17:58:52.515423Z" |
728 | 728 | } |
729 | 729 | }, |
730 | 730 | "outputs": [ |
|
758 | 758 | { |
759 | 759 | "cell_type": "code", |
760 | 760 | "execution_count": 9, |
761 | | - "id": "701c3f29", |
| 761 | + "id": "6eb1cf09", |
762 | 762 | "metadata": { |
763 | 763 | "execution": { |
764 | | - "iopub.execute_input": "2022-01-30T01:36:31.734075Z", |
765 | | - "iopub.status.busy": "2022-01-30T01:36:31.733075Z", |
766 | | - "iopub.status.idle": "2022-01-30T01:36:31.961828Z", |
767 | | - "shell.execute_reply": "2022-01-30T01:36:31.962830Z" |
| 764 | + "iopub.execute_input": "2022-01-30T17:58:52.528432Z", |
| 765 | + "iopub.status.busy": "2022-01-30T17:58:52.526426Z", |
| 766 | + "iopub.status.idle": "2022-01-30T17:58:53.033072Z", |
| 767 | + "shell.execute_reply": "2022-01-30T17:58:53.032071Z" |
768 | 768 | } |
769 | 769 | }, |
770 | 770 | "outputs": [ |
|
0 commit comments