add backprop.

This commit is contained in:
publicmatt 2024-02-22 08:41:04 -08:00
parent 0ed01f7a84
commit 6cf0186544
5 changed files with 621 additions and 145 deletions

View File

@ -39,168 +39,182 @@
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"1215pt\" height=\"155pt\"\n",
" viewBox=\"0.00 0.00 1215.00 155.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<svg width=\"1299pt\" height=\"155pt\"\n",
" viewBox=\"0.00 0.00 1299.00 155.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 151)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-151 1211,-151 1211,4 -4,4\"/>\n",
"<!-- 140306720081952 -->\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-151 1295,-151 1295,4 -4,4\"/>\n",
"<!-- 140118324758560 -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>140306720081952</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"337,-8.5 337,-44.5 543,-44.5 543,-8.5 337,-8.5\"/>\n",
"<text text-anchor=\"middle\" x=\"388\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"439,-8.5 439,-44.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"491\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"<title>140118324758560</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"711,-63.5 711,-99.5 938,-99.5 938,-63.5 711,-63.5\"/>\n",
"<text text-anchor=\"middle\" x=\"721.5\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"732,-63.5 732,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"783\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 7.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"834,-63.5 834,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"886\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140306720081616+ -->\n",
"<!-- 140118324758464+ -->\n",
"<g id=\"node9\" class=\"node\">\n",
"<title>140306720081616+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"606\" cy=\"-81.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"606\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"<title>140118324758464+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"1001\" cy=\"-104.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"1001\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140306720081952&#45;&gt;140306720081616+ -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>140306720081952&#45;&gt;140306720081616+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M514.99,-44.53C524.49,-47.3 534.02,-50.31 543,-53.5 553.54,-57.25 564.77,-62.05 574.74,-66.62\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"573.3,-69.82 583.84,-70.89 576.27,-63.48 573.3,-69.82\"/>\n",
"</g>\n",
"<!-- 140306720081952* -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>140306720081952*</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"274\" cy=\"-26.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"274\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
"</g>\n",
"<!-- 140306720081952*&#45;&gt;140306720081952 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>140306720081952*&#45;&gt;140306720081952</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M301.35,-26.5C308.8,-26.5 317.4,-26.5 326.61,-26.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"326.8,-30 336.8,-26.5 326.8,-23 326.8,-30\"/>\n",
"</g>\n",
"<!-- 140306720082000 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>140306720082000</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"0,-110.5 0,-146.5 211,-146.5 211,-110.5 0,-110.5\"/>\n",
"<text text-anchor=\"middle\" x=\"53.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;1.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"107,-110.5 107,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"159\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140306720081520+ -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>140306720081520+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"938\" cy=\"-104.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"938\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140306720082000&#45;&gt;140306720081520+ -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>140306720082000&#45;&gt;140306720081520+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M211.33,-128.5C276.78,-128.5 362.8,-128.5 439,-128.5 439,-128.5 439,-128.5 607,-128.5 714.29,-128.5 840.7,-115.72 901.2,-108.81\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"901.84,-112.26 911.37,-107.64 901.04,-105.31 901.84,-112.26\"/>\n",
"</g>\n",
"<!-- 140306720082096+ -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>140306720082096+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"274\" cy=\"-81.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"274\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140306720082000&#45;&gt;140306720082096+ -->\n",
"<!-- 140118324758560&#45;&gt;140118324758464+ -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>140306720082000&#45;&gt;140306720082096+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M178.61,-110.47C189.49,-107.57 200.56,-104.53 211,-101.5 220.41,-98.77 230.56,-95.59 239.86,-92.59\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"241.13,-95.86 249.55,-89.43 238.96,-89.2 241.13,-95.86\"/>\n",
"<title>140118324758560&#45;&gt;140118324758464+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M938.48,-96.39C947.58,-97.59 956.27,-98.74 964.1,-99.77\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"963.83,-103.26 974.21,-101.1 964.75,-96.32 963.83,-103.26\"/>\n",
"</g>\n",
"<!-- 140306720081520 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>140306720081520</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"1001,-86.5 1001,-122.5 1207,-122.5 1207,-86.5 1001,-86.5\"/>\n",
"<text text-anchor=\"middle\" x=\"1052\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 6.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1103,-86.5 1103,-122.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1155\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"<!-- 140118324758560+ -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>140118324758560+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"648\" cy=\"-81.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"648\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140306720081520+&#45;&gt;140306720081520 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>140306720081520+&#45;&gt;140306720081520</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M965.35,-104.5C972.8,-104.5 981.4,-104.5 990.61,-104.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"990.8,-108 1000.8,-104.5 990.8,-101 990.8,-108\"/>\n",
"<!-- 140118324758560+&#45;&gt;140118324758560 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>140118324758560+&#45;&gt;140118324758560</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M675.12,-81.5C682.67,-81.5 691.45,-81.5 700.9,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"700.95,-85 710.95,-81.5 700.95,-78 700.95,-85\"/>\n",
"</g>\n",
"<!-- 140306720082096 -->\n",
"<!-- 140118324760816 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>140118324760816</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-0.5 2.5,-36.5 229.5,-36.5 229.5,-0.5 2.5,-0.5\"/>\n",
"<text text-anchor=\"middle\" x=\"13\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"23.5,-0.5 23.5,-36.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"74.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 1.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"125.5,-0.5 125.5,-36.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"177.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324758800* -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>140306720082096</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"337,-63.5 337,-99.5 543,-99.5 543,-63.5 337,-63.5\"/>\n",
"<text text-anchor=\"middle\" x=\"388\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 3.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"439,-63.5 439,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"491\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"<title>140118324758800*</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"295\" cy=\"-26.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"295\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
"</g>\n",
"<!-- 140306720082096&#45;&gt;140306720081616+ -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>140306720082096&#45;&gt;140306720081616+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M543.47,-81.5C552.37,-81.5 560.93,-81.5 568.69,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"568.72,-85 578.72,-81.5 568.72,-78 568.72,-85\"/>\n",
"</g>\n",
"<!-- 140306720082096+&#45;&gt;140306720082096 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>140306720082096+&#45;&gt;140306720082096</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M301.35,-81.5C308.8,-81.5 317.4,-81.5 326.61,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"326.8,-85 336.8,-81.5 326.8,-78 326.8,-85\"/>\n",
"</g>\n",
"<!-- 140306720081616 -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>140306720081616</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"669,-63.5 669,-99.5 875,-99.5 875,-63.5 669,-63.5\"/>\n",
"<text text-anchor=\"middle\" x=\"720\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 7.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"771,-63.5 771,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"823\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140306720081616&#45;&gt;140306720081520+ -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>140306720081616&#45;&gt;140306720081520+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M875.47,-95.87C884.65,-97.16 893.47,-98.39 901.42,-99.51\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"900.94,-102.98 911.33,-100.9 901.91,-96.04 900.94,-102.98\"/>\n",
"</g>\n",
"<!-- 140306720081616+&#45;&gt;140306720081616 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>140306720081616+&#45;&gt;140306720081616</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M633.35,-81.5C640.8,-81.5 649.4,-81.5 658.61,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"658.8,-85 668.8,-81.5 658.8,-78 658.8,-85\"/>\n",
"</g>\n",
"<!-- 140306737924848 -->\n",
"<g id=\"node10\" class=\"node\">\n",
"<title>140306737924848</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-55.5 2.5,-91.5 208.5,-91.5 208.5,-55.5 2.5,-55.5\"/>\n",
"<text text-anchor=\"middle\" x=\"53.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"104.5,-55.5 104.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"156.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140306737924848&#45;&gt;140306720081952* -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>140306737924848&#45;&gt;140306720081952*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M175.17,-55.47C187.14,-52.23 199.45,-48.82 211,-45.5 220.3,-42.83 230.34,-39.81 239.58,-36.98\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"240.69,-40.3 249.21,-34.01 238.62,-33.61 240.69,-40.3\"/>\n",
"</g>\n",
"<!-- 140306737924848&#45;&gt;140306720082096+ -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>140306737924848&#45;&gt;140306720082096+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M208.63,-78.41C218.68,-78.89 228.34,-79.35 236.99,-79.77\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"236.83,-83.27 246.99,-80.25 237.17,-76.27 236.83,-83.27\"/>\n",
"</g>\n",
"<!-- 140306720080368 -->\n",
"<g id=\"node11\" class=\"node\">\n",
"<title>140306720080368</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-0.5 2.5,-36.5 208.5,-36.5 208.5,-0.5 2.5,-0.5\"/>\n",
"<text text-anchor=\"middle\" x=\"53.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 1.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"104.5,-0.5 104.5,-36.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"156.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140306720080368&#45;&gt;140306720081952* -->\n",
"<!-- 140118324760816&#45;&gt;140118324758800* -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>140306720080368&#45;&gt;140306720081952*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M208.63,-23.41C218.68,-23.89 228.34,-24.35 236.99,-24.77\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"236.83,-28.27 246.99,-25.25 237.17,-21.27 236.83,-28.27\"/>\n",
"<title>140118324760816&#45;&gt;140118324758800*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M229.6,-23.59C239.57,-24.04 249.1,-24.47 257.63,-24.86\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"257.7,-28.36 267.85,-25.32 258.02,-21.37 257.7,-28.36\"/>\n",
"</g>\n",
"<!-- 140118745713392 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>140118745713392</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-55.5 2.5,-91.5 229.5,-91.5 229.5,-55.5 2.5,-55.5\"/>\n",
"<text text-anchor=\"middle\" x=\"13\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"23.5,-55.5 23.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"74.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"125.5,-55.5 125.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"177.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118745713392&#45;&gt;140118324758800* -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>140118745713392&#45;&gt;140118324758800*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M197.64,-55.45C209.21,-52.6 220.94,-49.58 232,-46.5 241.44,-43.87 251.6,-40.73 260.9,-37.73\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"262.17,-40.99 270.58,-34.55 259.99,-34.34 262.17,-40.99\"/>\n",
"</g>\n",
"<!-- 140118324758992+ -->\n",
"<g id=\"node11\" class=\"node\">\n",
"<title>140118324758992+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"295\" cy=\"-81.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"295\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140118745713392&#45;&gt;140118324758992+ -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>140118745713392&#45;&gt;140118324758992+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M229.6,-78.59C239.57,-79.04 249.1,-79.47 257.63,-79.86\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"257.7,-83.36 267.85,-80.32 258.02,-76.37 257.7,-83.36\"/>\n",
"</g>\n",
"<!-- 140118324758800 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>140118324758800</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"358,-8.5 358,-44.5 585,-44.5 585,-8.5 358,-8.5\"/>\n",
"<text text-anchor=\"middle\" x=\"368.5\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"379,-8.5 379,-44.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"430\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 4.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"481,-8.5 481,-44.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"533\" y=\"-22.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324758800&#45;&gt;140118324758560+ -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>140118324758800&#45;&gt;140118324758560+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M551.97,-44.51C563.14,-47.56 574.42,-50.91 585,-54.5 595.34,-58.01 606.35,-62.53 616.18,-66.87\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"614.99,-70.17 625.54,-71.1 617.87,-63.79 614.99,-70.17\"/>\n",
"</g>\n",
"<!-- 140118324758800*&#45;&gt;140118324758800 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>140118324758800*&#45;&gt;140118324758800</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M322.12,-26.5C329.67,-26.5 338.45,-26.5 347.9,-26.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"347.95,-30 357.95,-26.5 347.95,-23 347.95,-30\"/>\n",
"</g>\n",
"<!-- 140118324758848 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>140118324758848</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"0,-110.5 0,-146.5 232,-146.5 232,-110.5 0,-110.5\"/>\n",
"<text text-anchor=\"middle\" x=\"10.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"21,-110.5 21,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"74.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;1.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"128,-110.5 128,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"180\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324758848&#45;&gt;140118324758464+ -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>140118324758848&#45;&gt;140118324758464+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M232.03,-128.5C301.15,-128.5 390.87,-128.5 470.5,-128.5 470.5,-128.5 470.5,-128.5 649,-128.5 764.19,-128.5 900.15,-115.48 963.77,-108.62\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"964.5,-112.06 974.06,-107.49 963.74,-105.1 964.5,-112.06\"/>\n",
"</g>\n",
"<!-- 140118324758848&#45;&gt;140118324758992+ -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>140118324758848&#45;&gt;140118324758992+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M197.64,-110.45C209.21,-107.6 220.94,-104.58 232,-101.5 241.44,-98.87 251.6,-95.73 260.9,-92.73\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"262.17,-95.99 270.58,-89.55 259.99,-89.34 262.17,-95.99\"/>\n",
"</g>\n",
"<!-- 140118324758464 -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>140118324758464</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"1064,-86.5 1064,-122.5 1291,-122.5 1291,-86.5 1064,-86.5\"/>\n",
"<text text-anchor=\"middle\" x=\"1074.5\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1085,-86.5 1085,-122.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1136\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 6.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1187,-86.5 1187,-122.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1239\" y=\"-100.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324758464+&#45;&gt;140118324758464 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>140118324758464+&#45;&gt;140118324758464</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1028.12,-104.5C1035.67,-104.5 1044.45,-104.5 1053.9,-104.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1053.95,-108 1063.95,-104.5 1053.95,-101 1053.95,-108\"/>\n",
"</g>\n",
"<!-- 140118324758992 -->\n",
"<g id=\"node10\" class=\"node\">\n",
"<title>140118324758992</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"358,-63.5 358,-99.5 585,-99.5 585,-63.5 358,-63.5\"/>\n",
"<text text-anchor=\"middle\" x=\"368.5\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\"> </text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"379,-63.5 379,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"430\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 3.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"481,-63.5 481,-99.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"533\" y=\"-77.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324758992&#45;&gt;140118324758560+ -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>140118324758992&#45;&gt;140118324758560+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M585.48,-81.5C594.49,-81.5 603.09,-81.5 610.87,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"610.91,-85 620.91,-81.5 610.91,-78 610.91,-85\"/>\n",
"</g>\n",
"<!-- 140118324758992+&#45;&gt;140118324758992 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>140118324758992+&#45;&gt;140118324758992</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M322.12,-81.5C329.67,-81.5 338.45,-81.5 347.9,-81.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"347.95,-85 357.95,-81.5 347.95,-78 347.95,-85\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x7f9bb42e4e80>"
"<graphviz.graphs.Digraph at 0x7f6fd6f6cf70>"
]
},
"execution_count": 3,
@ -214,9 +228,283 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "8491fa95-c89e-4283-95fe-d685d50f7e07",
"metadata": {},
"outputs": [
{
"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=\"1717pt\" height=\"210pt\"\n",
" viewBox=\"0.00 0.00 1716.69 210.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 206)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-206 1712.69,-206 1712.69,4 -4,4\"/>\n",
"<!-- 140118324770320 -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>140118324770320</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"1110,-109.5 1110,-145.5 1342,-145.5 1342,-109.5 1110,-109.5\"/>\n",
"<text text-anchor=\"middle\" x=\"1123\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">n</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1136,-109.5 1136,-145.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1187\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.2000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1238,-109.5 1238,-145.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1290\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770464tanh -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>140118324770464tanh</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"1409.85\" cy=\"-127.5\" rx=\"31.7\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"1409.85\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">tanh</text>\n",
"</g>\n",
"<!-- 140118324770320&#45;&gt;140118324770464tanh -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>140118324770320&#45;&gt;140118324770464tanh</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1342.17,-127.5C1351.08,-127.5 1359.66,-127.5 1367.53,-127.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1367.78,-131 1377.78,-127.5 1367.78,-124 1367.78,-131\"/>\n",
"</g>\n",
"<!-- 140118324770320+ -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>140118324770320+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"1047\" cy=\"-127.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"1047\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140118324770320+&#45;&gt;140118324770320 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>140118324770320+&#45;&gt;140118324770320</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1074.12,-127.5C1081.53,-127.5 1090.14,-127.5 1099.4,-127.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1099.69,-131 1109.69,-127.5 1099.69,-124 1099.69,-131\"/>\n",
"</g>\n",
"<!-- 140118313495584 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>140118313495584</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"4.5,-55.5 4.5,-91.5 244.5,-91.5 244.5,-55.5 4.5,-55.5\"/>\n",
"<text text-anchor=\"middle\" x=\"21.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">x2</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"38.5,-55.5 38.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"89.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"140.5,-55.5 140.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"192.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770128* -->\n",
"<g id=\"node12\" class=\"node\">\n",
"<title>140118324770128*</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"312\" cy=\"-73.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"312\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
"</g>\n",
"<!-- 140118313495584&#45;&gt;140118324770128* -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>140118313495584&#45;&gt;140118324770128*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M244.55,-73.5C255.31,-73.5 265.54,-73.5 274.62,-73.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"274.7,-77 284.7,-73.5 274.7,-70 274.7,-77\"/>\n",
"</g>\n",
"<!-- 140118324770464 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>140118324770464</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"1477.69,-109.5 1477.69,-145.5 1708.69,-145.5 1708.69,-109.5 1477.69,-109.5\"/>\n",
"<text text-anchor=\"middle\" x=\"1490.19\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">y</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1502.69,-109.5 1502.69,-145.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1553.69\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.1974</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"1604.69,-109.5 1604.69,-145.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"1656.69\" y=\"-123.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770464tanh&#45;&gt;140118324770464 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>140118324770464tanh&#45;&gt;140118324770464</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1442.02,-127.5C1449.61,-127.5 1458.19,-127.5 1467.31,-127.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1467.4,-131 1477.4,-127.5 1467.4,-124 1467.4,-131\"/>\n",
"</g>\n",
"<!-- 140118324769984 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>140118324769984</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"749.5,-137.5 749.5,-173.5 981.5,-173.5 981.5,-137.5 749.5,-137.5\"/>\n",
"<text text-anchor=\"middle\" x=\"762.5\" y=\"-151.8\" font-family=\"Times,serif\" font-size=\"14.00\">b</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"775.5,-137.5 775.5,-173.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"826.5\" y=\"-151.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 6.2000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"877.5,-137.5 877.5,-173.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"929.5\" y=\"-151.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324769984&#45;&gt;140118324770320+ -->\n",
"<g id=\"edge14\" class=\"edge\">\n",
"<title>140118324769984&#45;&gt;140118324770320+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M981.7,-137.53C991.99,-135.92 1001.8,-134.4 1010.51,-133.04\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1011.21,-136.47 1020.55,-131.47 1010.13,-129.55 1011.21,-136.47\"/>\n",
"</g>\n",
"<!-- 140118324770032 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>140118324770032</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"375,-110.5 375,-146.5 621,-146.5 621,-110.5 375,-110.5\"/>\n",
"<text text-anchor=\"middle\" x=\"392.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">h1</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"410,-110.5 410,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"463.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"517,-110.5 517,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"569\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770176+ -->\n",
"<g id=\"node15\" class=\"node\">\n",
"<title>140118324770176+</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"684\" cy=\"-100.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"684\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">+</text>\n",
"</g>\n",
"<!-- 140118324770032&#45;&gt;140118324770176+ -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>140118324770032&#45;&gt;140118324770176+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M617.35,-110.49C628.08,-108.86 638.29,-107.3 647.32,-105.93\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"647.98,-109.37 657.34,-104.4 646.93,-102.45 647.98,-109.37\"/>\n",
"</g>\n",
"<!-- 140118324770032* -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>140118324770032*</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"312\" cy=\"-128.5\" rx=\"27\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"312\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">*</text>\n",
"</g>\n",
"<!-- 140118324770032*&#45;&gt;140118324770032 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>140118324770032*&#45;&gt;140118324770032</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M339.36,-128.5C346.73,-128.5 355.28,-128.5 364.5,-128.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"364.75,-132 374.75,-128.5 364.75,-125 364.75,-132\"/>\n",
"</g>\n",
"<!-- 140118313493232 -->\n",
"<g id=\"node9\" class=\"node\">\n",
"<title>140118313493232</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"4.5,-165.5 4.5,-201.5 244.5,-201.5 244.5,-165.5 4.5,-165.5\"/>\n",
"<text text-anchor=\"middle\" x=\"21.5\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">x1</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"38.5,-165.5 38.5,-201.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"89.5\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 2.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"140.5,-165.5 140.5,-201.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"192.5\" y=\"-179.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118313493232&#45;&gt;140118324770032* -->\n",
"<g id=\"edge13\" class=\"edge\">\n",
"<title>140118313493232&#45;&gt;140118324770032*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M218.13,-165.46C228.63,-162.77 239.1,-159.78 249,-156.5 259.71,-152.96 271.05,-148.16 281.07,-143.54\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"282.67,-146.66 290.2,-139.21 279.67,-140.33 282.67,-146.66\"/>\n",
"</g>\n",
"<!-- 140118313498944 -->\n",
"<g id=\"node10\" class=\"node\">\n",
"<title>140118313498944</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"2.5,-0.5 2.5,-36.5 246.5,-36.5 246.5,-0.5 2.5,-0.5\"/>\n",
"<text text-anchor=\"middle\" x=\"21.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">w2</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"40.5,-0.5 40.5,-36.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"91.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 1.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"142.5,-0.5 142.5,-36.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"194.5\" y=\"-14.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118313498944&#45;&gt;140118324770128* -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>140118313498944&#45;&gt;140118324770128*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M214.42,-36.55C226.15,-39.54 237.93,-42.87 249,-46.5 259.46,-49.93 270.57,-54.47 280.46,-58.84\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"279.31,-62.17 289.87,-63.12 282.21,-55.79 279.31,-62.17\"/>\n",
"</g>\n",
"<!-- 140118324770128 -->\n",
"<g id=\"node11\" class=\"node\">\n",
"<title>140118324770128</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"377.5,-55.5 377.5,-91.5 618.5,-91.5 618.5,-55.5 377.5,-55.5\"/>\n",
"<text text-anchor=\"middle\" x=\"395\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">h2</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"412.5,-55.5 412.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"463.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">data 0.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"514.5,-55.5 514.5,-91.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"566.5\" y=\"-69.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770128&#45;&gt;140118324770176+ -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>140118324770128&#45;&gt;140118324770176+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M618.65,-91.06C628.89,-92.56 638.64,-93.99 647.3,-95.26\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"646.89,-98.74 657.29,-96.73 647.9,-91.81 646.89,-98.74\"/>\n",
"</g>\n",
"<!-- 140118324770128*&#45;&gt;140118324770128 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>140118324770128*&#45;&gt;140118324770128</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M339.36,-73.5C347.5,-73.5 357.06,-73.5 367.38,-73.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"367.49,-77 377.49,-73.5 367.49,-70 367.49,-77\"/>\n",
"</g>\n",
"<!-- 140118313484640 -->\n",
"<g id=\"node13\" class=\"node\">\n",
"<title>140118313484640</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"0,-110.5 0,-146.5 249,-146.5 249,-110.5 0,-110.5\"/>\n",
"<text text-anchor=\"middle\" x=\"19\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">w1</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"38,-110.5 38,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"91.5\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;3.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"145,-110.5 145,-146.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"197\" y=\"-124.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118313484640&#45;&gt;140118324770032* -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>140118313484640&#45;&gt;140118324770032*</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M249.23,-128.5C258.37,-128.5 267.05,-128.5 274.87,-128.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"274.95,-132 284.95,-128.5 274.95,-125 274.95,-132\"/>\n",
"</g>\n",
"<!-- 140118324770176 -->\n",
"<g id=\"node14\" class=\"node\">\n",
"<title>140118324770176</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"747,-82.5 747,-118.5 984,-118.5 984,-82.5 747,-82.5\"/>\n",
"<text text-anchor=\"middle\" x=\"760\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">h</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"773,-82.5 773,-118.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"826.5\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">data &#45;6.0000</text>\n",
"<polyline fill=\"none\" stroke=\"black\" points=\"880,-82.5 880,-118.5 \"/>\n",
"<text text-anchor=\"middle\" x=\"932\" y=\"-96.8\" font-family=\"Times,serif\" font-size=\"14.00\">grad 0.0000</text>\n",
"</g>\n",
"<!-- 140118324770176&#45;&gt;140118324770320+ -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>140118324770176&#45;&gt;140118324770320+</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M984.23,-118.21C993.6,-119.62 1002.52,-120.96 1010.52,-122.16\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1010.06,-125.63 1020.47,-123.66 1011.1,-118.71 1010.06,-125.63\"/>\n",
"</g>\n",
"<!-- 140118324770176+&#45;&gt;140118324770176 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>140118324770176+&#45;&gt;140118324770176</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M711.1,-100.5C718.61,-100.5 727.33,-100.5 736.75,-100.5\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"736.78,-104 746.78,-100.5 736.78,-97 736.78,-104\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x7f6fd6f97820>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# inputs\n",
"x1 = Value(2.0, label='x1')\n",
"x2 = Value(0.0, label='x2')\n",
"\n",
"# weights\n",
"w1 = Value(-3.0, label='w1')\n",
"w2 = Value(1.0, label='w2')\n",
"\n",
"# bias\n",
"b = Value(6.2, label='b')\n",
"\n",
"h1 = x1 * w1\n",
"h1.label = 'h1'\n",
"h2 = x2 * w2\n",
"h2.label = 'h2'\n",
"\n",
"h = h1 + h2\n",
"h.label = 'h'\n",
"\n",
"n = h + b\n",
"n.label = 'n'\n",
"y = n.tanh()\n",
"y.label = 'y'\n",
"\n",
"draw_dot(y)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "543bd866-2ce7-4b9a-8d8b-55a160a7c83b",
"metadata": {},
"outputs": [],
"source": []
}

View File

@ -6,6 +6,25 @@ class Value:
self._prev = set(_children)
self._op = _op
self.label = label
self._backward = lambda: None
def backward(self):
def topological(root):
ordered = []
visited = set()
def build_topo(v):
if v not in visited:
visited.add(v)
for child in v._prev:
build_topo(child)
ordered.append(v)
build_topo(root)
return ordered
ordered = topological(self)
self.grad = 1.0
for node in reversed(ordered):
node._backward()
def __repr__(self):
return f"Value(data={self.data})"
@ -13,6 +32,11 @@ class Value:
def __add__(self, other):
out = Value(data=self.data + other.data,
_children=(self, other), _op='+')
def _backward():
self.grad = 1.0 * out.grad
other.grad = 1.0 * out.grad
out._backward = _backward
return out
def __sub__(self, other):
@ -23,4 +47,20 @@ class Value:
def __mul__(self, other):
out = Value(data=self.data * other.data,
_children=(self, other), _op='*')
def _backward():
self.grad = other.data * out.grad
other.grad = self.data * out.grad
out._backward = _backward
return out
def tanh(self):
from math import exp
t = (exp(2 * self.data) - 1) / (exp(2 * self.data) + 1)
out = Value(data=t, _children=(self,),
_op='tanh', label='tanh')
def _backward():
self.grad = (1 - t**2) * out.grad
out._backward = _backward
return out

104
test/test_backprop.py Normal file
View File

@ -0,0 +1,104 @@
import pytest
from micrograd.engine import Value
def test_backward_tanh():
# inputs
x = Value(0.8814)
y = x.tanh()
y.grad = 1.0
y._backward()
assert pytest.approx(x.grad, 0.1) == 0.5
def test_large_backprop():
# inputs
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias
b = Value(6.8813735870195432, label='b')
h1 = x1 * w1
h1.label = 'h1'
h2 = x2 * w2
h2.label = 'h2'
h = h1 + h2
h.label = 'h'
n = h + b
n.label = 'n'
y = n.tanh()
y.label = 'y'
y.grad = 1.0
y._backward()
assert pytest.approx(n.grad, 0.001) == 0.5
assert h.grad == 0.0
n._backward()
assert pytest.approx(b.grad, 0.001) == 0.5
assert pytest.approx(h.grad, 0.001) == 0.5
b._backward()
h._backward()
assert pytest.approx(h1.grad, 0.001) == 0.5
assert pytest.approx(h2.grad, 0.001) == 0.5
h1._backward()
h2._backward()
assert pytest.approx(x1.grad, 0.001) == -1.5
assert pytest.approx(w1.grad, 0.001) == 1.0
assert pytest.approx(x2.grad, 0.001) == 0.5
assert pytest.approx(w2.grad, 0.001) == 0.0
@pytest.mark.skip(reason="non-deterministic")
def test_auto_diff():
# inputs
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias
b = Value(6.8813735870195432, label='b')
h1 = x1 * w1
h1.label = 'h1'
h2 = x2 * w2
h2.label = 'h2'
h = h1 + h2
h.label = 'h'
n = h + b
n.label = 'n'
y = n.tanh()
y.label = 'y'
y.backward()
assert pytest.approx(n.grad, 0.001) == 0.5
assert h.grad == 0.0
assert pytest.approx(b.grad, 0.001) == 0.5
assert pytest.approx(h.grad, 0.001) == 0.5
assert pytest.approx(h1.grad, 0.001) == 0.5
assert pytest.approx(h2.grad, 0.001) == 0.5
assert pytest.approx(x1.grad, 0.001) == -1.5
assert pytest.approx(w1.grad, 0.001) == 1.0
assert pytest.approx(x2.grad, 0.001) == 0.5
assert pytest.approx(w2.grad, 0.001) == 0.0

31
test/test_neuron.py Normal file
View File

@ -0,0 +1,31 @@
import pytest
from micrograd.engine import Value
# @pytest.mark.skip(reason="complicated assertion")
def test_big_neuron():
# inputs
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias
b = Value(6.8813735870195432, label='b')
h1 = x1 * w1
h1.label = 'h1'
h2 = x2 * w2
h2.label = 'h2'
h = h1 + h2
h.label = 'h'
n = h + b
n.label = 'n'
y = n.tanh()
y.label = 'y'
assert pytest.approx(y.data, 0.01) == 0.7071

View File

@ -56,3 +56,16 @@ def test_operations():
add = v1 + v2
assert mul._op == '*'
assert add._op == '+'
def test_tanh():
t = Value(2.0).tanh()
assert t.data > 0
assert t.data < 1
t = Value(0.0).tanh()
assert t.data == 0
t = Value(-2.0).tanh()
assert t.data < 0
assert t.data > -1