File size: 43,057 Bytes
525fbd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "class Value:\n",
        "\n",
        "    def __init__(self, data, _children=(), _op='', label=''):\n",
        "        self.data = data\n",
        "        self.grad = 0.0\n",
        "        self._prev = set(_children)\n",
        "        self._op = _op\n",
        "        self.label = label\n",
        "\n",
        "\n",
        "    def __repr__(self):   # This basically allows us to print nicer looking expressions for the final output\n",
        "        return f\"Value(data={self.data})\"\n",
        "\n",
        "    def __add__(self, other):\n",
        "        out = Value(self.data + other.data, (self, other), '+')\n",
        "        return out\n",
        "\n",
        "    def __mul__(self, other):\n",
        "        out = Value(self.data * other.data, (self, other), '*')\n",
        "        return out"
      ],
      "metadata": {
        "id": "jtRAdDVT6jf2"
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "AIP2sPDm6Los",
        "outputId": "685902a5-d209-4a47-90fc-97bf59a10af2"
      },
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Value(data=-8.0)"
            ]
          },
          "metadata": {},
          "execution_count": 17
        }
      ],
      "source": [
        "a = Value(2.0, label='a')\n",
        "b = Value(-3.0, label='b')\n",
        "c = Value(10.0, label='c')\n",
        "e = a*b; e.label='e'\n",
        "d= e + c; d.label='d'\n",
        "f = Value(-2.0, label='f')\n",
        "L = d*f; L.label='L'\n",
        "L"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from graphviz import Digraph\n",
        "\n",
        "def trace(root):\n",
        "    #Builds a set of all nodes and edges in a graph\n",
        "    nodes, edges = set(), set()\n",
        "    def build(v):\n",
        "        if v not in nodes:\n",
        "            nodes.add(v)\n",
        "            for child in v._prev:\n",
        "                edges.add((child, v))\n",
        "                build(child)\n",
        "    build(root)\n",
        "    return nodes, edges\n",
        "\n",
        "def draw_dot(root):\n",
        "    dot = Digraph(format='svg', graph_attr={'rankdir': 'LR'}) #LR == Left to Right\n",
        "\n",
        "    nodes, edges = trace(root)\n",
        "    for n in nodes:\n",
        "        uid = str(id(n))\n",
        "        #For any value in the graph, create a rectangular ('record') node for it\n",
        "        dot.node(name = uid, label = \"{ %s | data %.4f | grad %.4f }\" % ( n.label, n.data, n.grad), shape='record')\n",
        "        if n._op:\n",
        "            #If this value is a result of some operation, then create an op node for it\n",
        "            dot.node(name = uid + n._op, label=n._op)\n",
        "            #and connect this node to it\n",
        "            dot.edge(uid + n._op, uid)\n",
        "\n",
        "    for n1, n2 in edges:\n",
        "        #Connect n1 to the node of n2\n",
        "        dot.edge(str(id(n1)), str(id(n2)) + n2._op)\n",
        "\n",
        "    return dot"
      ],
      "metadata": {
        "id": "T0rN8d146jvF"
      },
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "draw_dot(L)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 247
        },
        "id": "k7wjwrfo6nUl",
        "outputId": "d78c4618-6574-49f9-8e80-f2faa8dad69a"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.43.0 (0)\n -->\n<!-- Title: %3 Pages: 1 -->\n<svg width=\"1148pt\" height=\"154pt\"\n viewBox=\"0.00 0.00 1148.00 154.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 150)\">\n<title>%3</title>\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-150 1144,-150 1144,4 -4,4\"/>\n<!-- 135449920624224 -->\n<g id=\"node1\" class=\"node\">\n<title>135449920624224</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"317,-27.5 317,-63.5 507,-63.5 507,-27.5 317,-27.5\"/>\n<text text-anchor=\"middle\" x=\"328.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">e</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"340,-27.5 340,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"425,-27.5 425,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"466\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920632192+ -->\n<g id=\"node8\" class=\"node\">\n<title>135449920632192+</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"571\" cy=\"-72.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"571\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n</g>\n<!-- 135449920624224&#45;&gt;135449920632192+ -->\n<g id=\"edge9\" class=\"edge\">\n<title>135449920624224&#45;&gt;135449920632192+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M507.05,-61.67C516.78,-63.35 526.18,-64.96 534.62,-66.42\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"534.3,-69.91 544.75,-68.16 535.49,-63.01 534.3,-69.91\"/>\n</g>\n<!-- 135449920624224* -->\n<g id=\"node2\" class=\"node\">\n<title>135449920624224*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"253\" cy=\"-45.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"253\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 135449920624224*&#45;&gt;135449920624224 -->\n<g id=\"edge1\" class=\"edge\">\n<title>135449920624224*&#45;&gt;135449920624224</title>\n<path fill=\"none\" stroke=\"black\" d=\"M280.28,-45.5C288.05,-45.5 297.08,-45.5 306.68,-45.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"306.88,-49 316.88,-45.5 306.88,-42 306.88,-49\"/>\n</g>\n<!-- 135449920621248 -->\n<g id=\"node3\" class=\"node\">\n<title>135449920621248</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"948,-81.5 948,-117.5 1140,-117.5 1140,-81.5 948,-81.5\"/>\n<text text-anchor=\"middle\" x=\"960.5\" y=\"-95.8\" font-family=\"Times,serif\" font-size=\"14.00\">L</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"973,-81.5 973,-117.5 \"/>\n<text text-anchor=\"middle\" x=\"1015.5\" y=\"-95.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;8.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"1058,-81.5 1058,-117.5 \"/>\n<text text-anchor=\"middle\" x=\"1099\" y=\"-95.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920621248* -->\n<g id=\"node4\" class=\"node\">\n<title>135449920621248*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"885\" cy=\"-99.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"885\" y=\"-95.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 135449920621248*&#45;&gt;135449920621248 -->\n<g id=\"edge2\" class=\"edge\">\n<title>135449920621248*&#45;&gt;135449920621248</title>\n<path fill=\"none\" stroke=\"black\" d=\"M912.28,-99.5C919.78,-99.5 928.44,-99.5 937.67,-99.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"937.87,-103 947.87,-99.5 937.87,-96 937.87,-103\"/>\n</g>\n<!-- 135449920632624 -->\n<g id=\"node5\" class=\"node\">\n<title>135449920632624</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"0,-55.5 0,-91.5 190,-91.5 190,-55.5 0,-55.5\"/>\n<text text-anchor=\"middle\" x=\"11.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"23,-55.5 23,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"108,-55.5 108,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"149\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920632624&#45;&gt;135449920624224* -->\n<g id=\"edge5\" class=\"edge\">\n<title>135449920632624&#45;&gt;135449920624224*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M190.34,-56.57C199.62,-54.9 208.58,-53.29 216.66,-51.84\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"217.49,-55.25 226.72,-50.04 216.26,-48.36 217.49,-55.25\"/>\n</g>\n<!-- 135449920619856 -->\n<g id=\"node6\" class=\"node\">\n<title>135449920619856</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-0.5 2.5,-36.5 187.5,-36.5 187.5,-0.5 2.5,-0.5\"/>\n<text text-anchor=\"middle\" x=\"14\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"25.5,-0.5 25.5,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"105.5,-0.5 105.5,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"146.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920619856&#45;&gt;135449920624224* -->\n<g id=\"edge8\" class=\"edge\">\n<title>135449920619856&#45;&gt;135449920624224*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M187.65,-34.36C197.94,-36.14 207.91,-37.87 216.81,-39.41\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"216.26,-42.87 226.71,-41.12 217.45,-35.97 216.26,-42.87\"/>\n</g>\n<!-- 135449920632192 -->\n<g id=\"node7\" class=\"node\">\n<title>135449920632192</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"635.5,-54.5 635.5,-90.5 820.5,-90.5 820.5,-54.5 635.5,-54.5\"/>\n<text text-anchor=\"middle\" x=\"647\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"658.5,-54.5 658.5,-90.5 \"/>\n<text text-anchor=\"middle\" x=\"698.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"738.5,-54.5 738.5,-90.5 \"/>\n<text text-anchor=\"middle\" x=\"779.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920632192&#45;&gt;135449920621248* -->\n<g id=\"edge7\" class=\"edge\">\n<title>135449920632192&#45;&gt;135449920621248*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M820.51,-88.44C830.48,-90.18 840.13,-91.86 848.77,-93.36\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"848.31,-96.84 858.77,-95.1 849.52,-89.94 848.31,-96.84\"/>\n</g>\n<!-- 135449920632192+&#45;&gt;135449920632192 -->\n<g id=\"edge3\" class=\"edge\">\n<title>135449920632192+&#45;&gt;135449920632192</title>\n<path fill=\"none\" stroke=\"black\" d=\"M598.29,-72.5C606.26,-72.5 615.54,-72.5 625.39,-72.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"625.41,-76 635.41,-72.5 625.41,-69 625.41,-76\"/>\n</g>\n<!-- 135449920619424 -->\n<g id=\"node9\" class=\"node\">\n<title>135449920619424</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"316,-82.5 316,-118.5 508,-118.5 508,-82.5 316,-82.5\"/>\n<text text-anchor=\"middle\" x=\"327.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"339,-82.5 339,-118.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 10.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"426,-82.5 426,-118.5 \"/>\n<text text-anchor=\"middle\" x=\"467\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920619424&#45;&gt;135449920632192+ -->\n<g id=\"edge4\" class=\"edge\">\n<title>135449920619424&#45;&gt;135449920632192+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M508.4,-83.49C517.69,-81.83 526.64,-80.23 534.71,-78.79\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"535.53,-82.2 544.76,-77 534.31,-75.31 535.53,-82.2\"/>\n</g>\n<!-- 135449920632288 -->\n<g id=\"node10\" class=\"node\">\n<title>135449920632288</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"634,-109.5 634,-145.5 822,-145.5 822,-109.5 634,-109.5\"/>\n<text text-anchor=\"middle\" x=\"644.5\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">f</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"655,-109.5 655,-145.5 \"/>\n<text text-anchor=\"middle\" x=\"697.5\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"740,-109.5 740,-145.5 \"/>\n<text text-anchor=\"middle\" x=\"781\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 135449920632288&#45;&gt;135449920621248* -->\n<g id=\"edge6\" class=\"edge\">\n<title>135449920632288&#45;&gt;135449920621248*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M822.29,-110.65C831.57,-108.97 840.52,-107.35 848.61,-105.89\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"849.46,-109.3 858.68,-104.07 848.21,-102.41 849.46,-109.3\"/>\n</g>\n</g>\n</svg>\n",
            "text/plain": [
              "<graphviz.graphs.Digraph at 0x7b30e4675ae0>"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "----------------------"
      ],
      "metadata": {
        "id": "UO6I8Z-_CaNv"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### **Now, let's start to fill those grad values**"
      ],
      "metadata": {
        "id": "wB-SONL3CltR"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "--------------"
      ],
      "metadata": {
        "id": "EhvqPDYqF50Z"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Let's first find the derivative of L w.r.t L**"
      ],
      "metadata": {
        "id": "dF0QlSFJCbsI"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#This is just a staging function to show how the calculation of each of the derivative is taking place\n",
        "def lol():\n",
        "\n",
        "  h = 0.001\n",
        "\n",
        "  #Here we are basically making them as local variables, to not affect the global variables on top\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  f = Value(-2.0, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L1 = L.data #L is basically a node, so we need its data\n",
        "\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  f = Value(-2.0, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L2 = L.data + h\n",
        "\n",
        "  print((L2-L1)/h)\n",
        "\n",
        "lol()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "AWQsdevqCUks",
        "outputId": "e08b83fd-b101-4fdc-a554-41561c00a08b"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1.000000000000334\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "This was theoritically obvious as well. The derivitive of L wrt L will be one.\n",
        "\n",
        "&nbsp;\n",
        "\n",
        "So, lets add that value manually. (Remember to run the global variables for this)"
      ],
      "metadata": {
        "id": "HbfBzVQ4EEHM"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "L.grad = 1.0"
      ],
      "metadata": {
        "id": "3TCgz-n6DbzI"
      },
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "draw_dot(L)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 212
        },
        "id": "RS6YodRTEX43",
        "outputId": "3b58ed12-b486-4452-b700-8048b1e03e3b"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.43.0 (0)\n -->\n<!-- Title: %3 Pages: 1 -->\n<svg width=\"1148pt\" height=\"128pt\"\n viewBox=\"0.00 0.00 1148.00 128.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 124)\">\n<title>%3</title>\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-124 1144,-124 1144,4 -4,4\"/>\n<!-- 139719306605568 -->\n<g id=\"node1\" class=\"node\">\n<title>139719306605568</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"634,-82.5 634,-118.5 822,-118.5 822,-82.5 634,-82.5\"/>\n<text text-anchor=\"middle\" x=\"644.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">f</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"655,-82.5 655,-118.5 \"/>\n<text text-anchor=\"middle\" x=\"697.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"740,-82.5 740,-118.5 \"/>\n<text text-anchor=\"middle\" x=\"781\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306596928* -->\n<g id=\"node3\" class=\"node\">\n<title>139719306596928*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"885\" cy=\"-72.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"885\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 139719306605568&#45;&gt;139719306596928* -->\n<g id=\"edge5\" class=\"edge\">\n<title>139719306605568&#45;&gt;139719306596928*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M822.29,-83.65C831.57,-81.97 840.52,-80.35 848.61,-78.89\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"849.46,-82.3 858.68,-77.07 848.21,-75.41 849.46,-82.3\"/>\n</g>\n<!-- 139719306596928 -->\n<g id=\"node2\" class=\"node\">\n<title>139719306596928</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"948,-54.5 948,-90.5 1140,-90.5 1140,-54.5 948,-54.5\"/>\n<text text-anchor=\"middle\" x=\"960.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">L</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"973,-54.5 973,-90.5 \"/>\n<text text-anchor=\"middle\" x=\"1015.5\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;8.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"1058,-54.5 1058,-90.5 \"/>\n<text text-anchor=\"middle\" x=\"1099\" y=\"-68.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 1.0000</text>\n</g>\n<!-- 139719306596928*&#45;&gt;139719306596928 -->\n<g id=\"edge1\" class=\"edge\">\n<title>139719306596928*&#45;&gt;139719306596928</title>\n<path fill=\"none\" stroke=\"black\" d=\"M912.28,-72.5C919.78,-72.5 928.44,-72.5 937.67,-72.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"937.87,-76 947.87,-72.5 937.87,-69 937.87,-76\"/>\n</g>\n<!-- 139719306594912 -->\n<g id=\"node4\" class=\"node\">\n<title>139719306594912</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"317,-55.5 317,-91.5 507,-91.5 507,-55.5 317,-55.5\"/>\n<text text-anchor=\"middle\" x=\"328.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">e</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"340,-55.5 340,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"425,-55.5 425,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"466\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306603120+ -->\n<g id=\"node7\" class=\"node\">\n<title>139719306603120+</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"571\" cy=\"-45.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"571\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n</g>\n<!-- 139719306594912&#45;&gt;139719306603120+ -->\n<g id=\"edge6\" class=\"edge\">\n<title>139719306594912&#45;&gt;139719306603120+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M507.05,-56.73C516.89,-54.97 526.39,-53.28 534.9,-51.76\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"535.52,-55.2 544.75,-50 534.29,-48.31 535.52,-55.2\"/>\n</g>\n<!-- 139719306594912* -->\n<g id=\"node5\" class=\"node\">\n<title>139719306594912*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"253\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"253\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 139719306594912*&#45;&gt;139719306594912 -->\n<g id=\"edge2\" class=\"edge\">\n<title>139719306594912*&#45;&gt;139719306594912</title>\n<path fill=\"none\" stroke=\"black\" d=\"M280.28,-73.5C288.05,-73.5 297.08,-73.5 306.68,-73.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"306.88,-77 316.88,-73.5 306.88,-70 306.88,-77\"/>\n</g>\n<!-- 139719306603120 -->\n<g id=\"node6\" class=\"node\">\n<title>139719306603120</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"635.5,-27.5 635.5,-63.5 820.5,-63.5 820.5,-27.5 635.5,-27.5\"/>\n<text text-anchor=\"middle\" x=\"647\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"658.5,-27.5 658.5,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"698.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"738.5,-27.5 738.5,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"779.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306603120&#45;&gt;139719306596928* -->\n<g id=\"edge8\" class=\"edge\">\n<title>139719306603120&#45;&gt;139719306596928*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M820.51,-61.44C830.48,-63.18 840.13,-64.86 848.77,-66.36\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"848.31,-69.84 858.77,-68.1 849.52,-62.94 848.31,-69.84\"/>\n</g>\n<!-- 139719306603120+&#45;&gt;139719306603120 -->\n<g id=\"edge3\" class=\"edge\">\n<title>139719306603120+&#45;&gt;139719306603120</title>\n<path fill=\"none\" stroke=\"black\" d=\"M598.29,-45.5C606.26,-45.5 615.54,-45.5 625.39,-45.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"625.41,-49 635.41,-45.5 625.41,-42 625.41,-49\"/>\n</g>\n<!-- 139719306604320 -->\n<g id=\"node8\" class=\"node\">\n<title>139719306604320</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"316,-0.5 316,-36.5 508,-36.5 508,-0.5 316,-0.5\"/>\n<text text-anchor=\"middle\" x=\"327.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"339,-0.5 339,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 10.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"426,-0.5 426,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"467\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306604320&#45;&gt;139719306603120+ -->\n<g id=\"edge7\" class=\"edge\">\n<title>139719306604320&#45;&gt;139719306603120+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M508.4,-34.91C517.69,-36.5 526.64,-38.04 534.71,-39.43\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"534.32,-42.91 544.76,-41.16 535.5,-36.02 534.32,-42.91\"/>\n</g>\n<!-- 139719306603840 -->\n<g id=\"node9\" class=\"node\">\n<title>139719306603840</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-83.5 2.5,-119.5 187.5,-119.5 187.5,-83.5 2.5,-83.5\"/>\n<text text-anchor=\"middle\" x=\"14\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"25.5,-83.5 25.5,-119.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"105.5,-83.5 105.5,-119.5 \"/>\n<text text-anchor=\"middle\" x=\"146.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306603840&#45;&gt;139719306594912* -->\n<g id=\"edge4\" class=\"edge\">\n<title>139719306603840&#45;&gt;139719306594912*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M187.65,-85.05C197.94,-83.2 207.91,-81.41 216.81,-79.82\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"217.48,-83.25 226.71,-78.04 216.25,-76.36 217.48,-83.25\"/>\n</g>\n<!-- 139719306608016 -->\n<g id=\"node10\" class=\"node\">\n<title>139719306608016</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"0,-28.5 0,-64.5 190,-64.5 190,-28.5 0,-28.5\"/>\n<text text-anchor=\"middle\" x=\"11.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"23,-28.5 23,-64.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"108,-28.5 108,-64.5 \"/>\n<text text-anchor=\"middle\" x=\"149\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306608016&#45;&gt;139719306594912* -->\n<g id=\"edge9\" class=\"edge\">\n<title>139719306608016&#45;&gt;139719306594912*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M190.34,-62.83C199.62,-64.44 208.58,-65.99 216.66,-67.38\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"216.27,-70.87 226.72,-69.12 217.46,-63.97 216.27,-70.87\"/>\n</g>\n</g>\n</svg>\n",
            "text/plain": [
              "<graphviz.graphs.Digraph at 0x7f12efa36800>"
            ]
          },
          "metadata": {},
          "execution_count": 11
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "-----------"
      ],
      "metadata": {
        "id": "4x1UEdrOHalT"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "**Now, we find the derivative of L wrt to f and d**"
      ],
      "metadata": {
        "id": "Hhj8DrcUF7fI"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "So, mathematically:\n",
        "\n",
        "dL/dd = ?\n",
        "\n",
        "**L = d * f**\n",
        "\n",
        "Therefore, dL/dd = f\n",
        "\n",
        "If we do manual calculation to verify,           \\\n",
        "\n",
        "=> f(x+h) - f(x) / h                                \\\n",
        "\n",
        "(Remember the f(x) is basically L here)          \\\n",
        "=> (d+h)*f - d*f / h                                \\\n",
        "=> df + hf - df / h                                 \\\n",
        "=> hf/h                                             \\\n",
        "= f\n"
      ],
      "metadata": {
        "id": "SUi_wdLTGCsq"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "So here if you see,\n",
        "\n",
        "The derivative of L wrt f is the value in d \\\n",
        "& \\\n",
        "The derivative of L wrt d is the value in f\n",
        "\n",
        "So, grad f is 4.0 \\\n",
        "and grad d is -2.0\n",
        "\n",
        "&nbsp;\n",
        "\n",
        "Lets check this in code!"
      ],
      "metadata": {
        "id": "8ApC2l-HHfHi"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# STARTING WITH d\n",
        "\n",
        "#This is just a staging function to show how the calculation of each of the derivative is taking place\n",
        "def lol():\n",
        "\n",
        "  h = 0.001\n",
        "\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  f = Value(-2.0, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L1 = L.data #L is basically a node, so we need its data\n",
        "\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  d.data = d.data + h\n",
        "  f = Value(-2.0, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L2 = L.data\n",
        "\n",
        "  print((L2-L1)/h)\n",
        "\n",
        "lol()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2wx02cE6EYOR",
        "outputId": "f284e1ac-4c6f-490b-c8f3-e94dfbd9923e"
      },
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "-2.000000000000668\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# NOW WITH f\n",
        "\n",
        "#This is just a staging function to show how the calculation of each of the derivative is taking place\n",
        "def lol():\n",
        "\n",
        "  h = 0.00001\n",
        "\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  f = Value(-2.0, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L1 = L.data #L is basically a node, so we need its data\n",
        "\n",
        "  a = Value(2.0, label='a')\n",
        "  b = Value(-3.0, label='b')\n",
        "  c = Value(10.0, label='c')\n",
        "  e = a*b; e.label='e'\n",
        "  d= e + c; d.label='d'\n",
        "  f = Value(-2.0 + h, label='f')\n",
        "  L = d*f; L.label='L'\n",
        "  L2 = L.data\n",
        "\n",
        "  print((L2-L1)/h)\n",
        "\n",
        "lol()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "5haMwvymIRxx",
        "outputId": "7b372e31-8fa4-42d3-c591-371d3c49c78d"
      },
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "4.000000000026205\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "So, now that we have verified that mathematically and on our code. Lets manually add those variables to the graph"
      ],
      "metadata": {
        "id": "EB8w0lF0IofD"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "f.grad = 4.0\n",
        "d.grad = -2.0"
      ],
      "metadata": {
        "id": "pS4NnAZVIML9"
      },
      "execution_count": 19,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "draw_dot(L)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 212
        },
        "id": "ko5oltNPJDtc",
        "outputId": "d78137fe-0afa-449f-db42-0a079ebfffa4"
      },
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 2.43.0 (0)\n -->\n<!-- Title: %3 Pages: 1 -->\n<svg width=\"1149pt\" height=\"128pt\"\n viewBox=\"0.00 0.00 1149.00 128.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 124)\">\n<title>%3</title>\n<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-124 1145,-124 1145,4 -4,4\"/>\n<!-- 139719306599472 -->\n<g id=\"node1\" class=\"node\">\n<title>139719306599472</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"316,-83.5 316,-119.5 508,-119.5 508,-83.5 316,-83.5\"/>\n<text text-anchor=\"middle\" x=\"327.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">c</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"339,-83.5 339,-119.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 10.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"426,-83.5 426,-119.5 \"/>\n<text text-anchor=\"middle\" x=\"467\" y=\"-97.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306607920+ -->\n<g id=\"node6\" class=\"node\">\n<title>139719306607920+</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"571\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"571\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n</g>\n<!-- 139719306599472&#45;&gt;139719306607920+ -->\n<g id=\"edge6\" class=\"edge\">\n<title>139719306599472&#45;&gt;139719306607920+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M508.4,-84.49C517.69,-82.83 526.64,-81.23 534.71,-79.79\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"535.53,-83.2 544.76,-78 534.31,-76.31 535.53,-83.2\"/>\n</g>\n<!-- 139719306595392 -->\n<g id=\"node2\" class=\"node\">\n<title>139719306595392</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"317,-28.5 317,-64.5 507,-64.5 507,-28.5 317,-28.5\"/>\n<text text-anchor=\"middle\" x=\"328.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">e</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"340,-28.5 340,-64.5 \"/>\n<text text-anchor=\"middle\" x=\"382.5\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"425,-28.5 425,-64.5 \"/>\n<text text-anchor=\"middle\" x=\"466\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306595392&#45;&gt;139719306607920+ -->\n<g id=\"edge4\" class=\"edge\">\n<title>139719306595392&#45;&gt;139719306607920+</title>\n<path fill=\"none\" stroke=\"black\" d=\"M507.05,-62.67C516.78,-64.35 526.18,-65.96 534.62,-67.42\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"534.3,-70.91 544.75,-69.16 535.49,-64.01 534.3,-70.91\"/>\n</g>\n<!-- 139719306595392* -->\n<g id=\"node3\" class=\"node\">\n<title>139719306595392*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"253\" cy=\"-46.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"253\" y=\"-42.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 139719306595392*&#45;&gt;139719306595392 -->\n<g id=\"edge1\" class=\"edge\">\n<title>139719306595392*&#45;&gt;139719306595392</title>\n<path fill=\"none\" stroke=\"black\" d=\"M280.28,-46.5C288.05,-46.5 297.08,-46.5 306.68,-46.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"306.88,-50 316.88,-46.5 306.88,-43 306.88,-50\"/>\n</g>\n<!-- 139719306594432 -->\n<g id=\"node4\" class=\"node\">\n<title>139719306594432</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"0,-56.5 0,-92.5 190,-92.5 190,-56.5 0,-56.5\"/>\n<text text-anchor=\"middle\" x=\"11.5\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"23,-56.5 23,-92.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"108,-56.5 108,-92.5 \"/>\n<text text-anchor=\"middle\" x=\"149\" y=\"-70.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306594432&#45;&gt;139719306595392* -->\n<g id=\"edge9\" class=\"edge\">\n<title>139719306594432&#45;&gt;139719306595392*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M190.34,-57.57C199.62,-55.9 208.58,-54.29 216.66,-52.84\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"217.49,-56.25 226.72,-51.04 216.26,-49.36 217.49,-56.25\"/>\n</g>\n<!-- 139719306607920 -->\n<g id=\"node5\" class=\"node\">\n<title>139719306607920</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"634,-55.5 634,-91.5 823,-91.5 823,-55.5 634,-55.5\"/>\n<text text-anchor=\"middle\" x=\"645.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">d</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"657,-55.5 657,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"697\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"737,-55.5 737,-91.5 \"/>\n<text text-anchor=\"middle\" x=\"780\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad &#45;2.0000</text>\n</g>\n<!-- 139719306602976* -->\n<g id=\"node9\" class=\"node\">\n<title>139719306602976*</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"886\" cy=\"-45.5\" rx=\"27\" ry=\"18\"/>\n<text text-anchor=\"middle\" x=\"886\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n</g>\n<!-- 139719306607920&#45;&gt;139719306602976* -->\n<g id=\"edge5\" class=\"edge\">\n<title>139719306607920&#45;&gt;139719306602976*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M823.1,-56.65C832.4,-54.97 841.38,-53.35 849.49,-51.89\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"850.37,-55.29 859.59,-50.07 849.13,-48.4 850.37,-55.29\"/>\n</g>\n<!-- 139719306607920+&#45;&gt;139719306607920 -->\n<g id=\"edge2\" class=\"edge\">\n<title>139719306607920+&#45;&gt;139719306607920</title>\n<path fill=\"none\" stroke=\"black\" d=\"M598.03,-73.5C605.66,-73.5 614.52,-73.5 623.94,-73.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"623.94,-77 633.94,-73.5 623.94,-70 623.94,-77\"/>\n</g>\n<!-- 139719306602352 -->\n<g id=\"node7\" class=\"node\">\n<title>139719306602352</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"634.5,-0.5 634.5,-36.5 822.5,-36.5 822.5,-0.5 634.5,-0.5\"/>\n<text text-anchor=\"middle\" x=\"645\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">f</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"655.5,-0.5 655.5,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"698\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"740.5,-0.5 740.5,-36.5 \"/>\n<text text-anchor=\"middle\" x=\"781.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 4.0000</text>\n</g>\n<!-- 139719306602352&#45;&gt;139719306602976* -->\n<g id=\"edge7\" class=\"edge\">\n<title>139719306602352&#45;&gt;139719306602976*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M822.65,-34.67C832.2,-36.33 841.43,-37.93 849.72,-39.37\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"849.24,-42.84 859.69,-41.11 850.44,-35.95 849.24,-42.84\"/>\n</g>\n<!-- 139719306602976 -->\n<g id=\"node8\" class=\"node\">\n<title>139719306602976</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"949,-27.5 949,-63.5 1141,-63.5 1141,-27.5 949,-27.5\"/>\n<text text-anchor=\"middle\" x=\"961.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">L</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"974,-27.5 974,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"1016.5\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;8.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"1059,-27.5 1059,-63.5 \"/>\n<text text-anchor=\"middle\" x=\"1100\" y=\"-41.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306602976*&#45;&gt;139719306602976 -->\n<g id=\"edge3\" class=\"edge\">\n<title>139719306602976*&#45;&gt;139719306602976</title>\n<path fill=\"none\" stroke=\"black\" d=\"M913.28,-45.5C920.78,-45.5 929.44,-45.5 938.67,-45.5\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"938.87,-49 948.87,-45.5 938.87,-42 938.87,-49\"/>\n</g>\n<!-- 139719306601968 -->\n<g id=\"node10\" class=\"node\">\n<title>139719306601968</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-1.5 2.5,-37.5 187.5,-37.5 187.5,-1.5 2.5,-1.5\"/>\n<text text-anchor=\"middle\" x=\"14\" y=\"-15.8\" font-family=\"Times,serif\" font-size=\"14.00\">a</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"25.5,-1.5 25.5,-37.5 \"/>\n<text text-anchor=\"middle\" x=\"65.5\" y=\"-15.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n<polyline fill=\"none\" stroke=\"black\" points=\"105.5,-1.5 105.5,-37.5 \"/>\n<text text-anchor=\"middle\" x=\"146.5\" y=\"-15.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n</g>\n<!-- 139719306601968&#45;&gt;139719306595392* -->\n<g id=\"edge8\" class=\"edge\">\n<title>139719306601968&#45;&gt;139719306595392*</title>\n<path fill=\"none\" stroke=\"black\" d=\"M187.65,-35.36C197.94,-37.14 207.91,-38.87 216.81,-40.41\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"216.26,-43.87 226.71,-42.12 217.45,-36.97 216.26,-43.87\"/>\n</g>\n</g>\n</svg>\n",
            "text/plain": [
              "<graphviz.graphs.Digraph at 0x7f12ef9a3eb0>"
            ]
          },
          "metadata": {},
          "execution_count": 20
        }
      ]
    }
  ]
}