{"id":5084,"date":"2023-05-30T16:11:54","date_gmt":"2023-05-30T21:11:54","guid":{"rendered":"https:\/\/www.paleotechnologist.net\/?p=5084"},"modified":"2023-05-30T16:11:55","modified_gmt":"2023-05-30T21:11:55","slug":"neural-network-fractals","status":"publish","type":"post","link":"https:\/\/www.paleotechnologist.net\/?p=5084","title":{"rendered":"Neural-Network Fractals"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Last weekend, on a whim, I asked <a rel=\"noreferrer noopener\" href=\"https:\/\/openai.com\/research\/gpt-4\" target=\"_blank\">GPT-4<\/a> &#8220;Please teach me how to create simple neural networks in Python using <a href=\"https:\/\/pytorch.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">PyTorch<\/a>.&#8221; I wasn&#8217;t sure how well that would go, but figured it was worth a try.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I not only learned how to do that, but found out that <a rel=\"noreferrer noopener\" href=\"https:\/\/chat.openai.com\" target=\"_blank\">GPT-4<\/a>, at least when it isn&#8217;t <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hallucination_(artificial_intelligence)\" target=\"_blank\" rel=\"noreferrer noopener\">making things up<\/a>, is an <em>amazing <\/em>tutor. It not only provided the relevant code, but explained how it works, helped walk me through some snags installing the required libraries, and is continuing to explain how to tweak the code to implement new features of PyTorch for more efficient network training. I can now analyze arbitrary .csv file data with neural networks. Amazing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I had heard that, given sufficient data, a complex enough network, and enough training time, neural networks can learn the patterns underlying almost anything. So I decided to see how well it would do with the task I always start out with when learning a new language &#8212; generating images of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mandelbrot_set\" target=\"_blank\" rel=\"noreferrer noopener\">Mandelbrot Set<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"809\" src=\"https:\/\/www.paleotechnologist.net\/wp-content\/uploads\/2023\/05\/029-1024x809.png\" alt=\"\" class=\"wp-image-5086\" srcset=\"https:\/\/www.paleotechnologist.net\/wp-content\/uploads\/2023\/05\/029-1024x809.png 1024w, https:\/\/www.paleotechnologist.net\/wp-content\/uploads\/2023\/05\/029-300x237.png 300w, https:\/\/www.paleotechnologist.net\/wp-content\/uploads\/2023\/05\/029-768x607.png 768w, https:\/\/www.paleotechnologist.net\/wp-content\/uploads\/2023\/05\/029.png 1186w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong>An image of the Mandelbrot Set, as imagined by a 1500-neuron network.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s far from the best image of the Mandelbrot Set I&#8217;ve ever created &#8212; but there&#8217;s a reason. As JFK said, we do such things &#8220;not because they are easy, but because they are hard.&#8221; The Mandelbrot Set is, after all, a literally infinitely-complex object. Keep zooming in, and there will always be more somewhat-similar-but-not-quite-identical detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Creating such images is traditionally done by calculating the number of iterations for each point in the image, and coloring the point accordingly. The neural-network approach I used (which to be clear is <em>not<\/em> even approximately the most efficient way to do it) does it somewhat differently. Data on millions of randomly-chosen points and their associated iteration levels is stored in a .csv file. This file is then read into memory and used as the training (and verification) dataset to train a feedforward neural network to learn what iteration levels are associated with what points. Then, when training is done, this network is used as the function to draw the Set &#8212; it is queried for each point in the image instead of doing the iteration calculations for that point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This network doesn&#8217;t have vision. It is given a pair of numbers (representing the location in the complex plane) and outputs a single number (its guess at the iteration level). The image is somewhat unclear because it was, in effect, drawn by an &#8220;artist&#8221; who cannot see. It learned, through massively-repeated trials, what the Set looks like. Nobody &#8220;told&#8221; it, for example, that the Set is symmetrical about the X axis. It is, but the network had to figure that out for itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At first, the images only approximately resembled the Mandelbrot Set. But neural network design is still very much an art as well as a science (at least for now), so increasing the width and depth and switching to <a href=\"https:\/\/paperswithcode.com\/method\/he-initialization\" target=\"_blank\" rel=\"noreferrer noopener\">Kaiming initialization<\/a> (to avoid the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Vanishing_gradient_problem\" target=\"_blank\" rel=\"noreferrer noopener\">vanishing gradient<\/a> problem) resulted in an image that meets my initial goal: the locations of the second-level Mandelbrot lakes are visible. The coloration at the edges even hints at the infinitely-thin &#8220;Devil&#8217;s Polymer&#8221; links that connect the mini-lakes to the main lobes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GPT-4 still does get some things wrong. When asking it to guide me through tasks like obtaining a diamond pickaxe and then an Elytra in Minecraft (tasks that I know well), it mostly did a good job, but didn&#8217;t seem to know, for example, that hunger, Endermen, and Pillagers are not things that you have to be concerned about when playing on Peaceful mode. But even so, I was able to follow its directions to accomplish those goals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a new form of intelligence, if perhaps not sentience just yet. I&#8217;ve often said that I love living in the future. It just got dramatically more futuristic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last weekend, on a whim, I asked GPT-4 &#8220;Please teach me how to create simple neural networks in Python using PyTorch.&#8221; I wasn&#8217;t sure how well that would go, but figured it was worth a try. I not only learned &hellip; <a href=\"https:\/\/www.paleotechnologist.net\/?p=5084\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"footnotes":""},"categories":[530,216,633,762,555,761],"tags":[756,760,755,757,758,759],"class_list":["post-5084","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-coding","category-fractals","category-machine-learning-neural-networks","category-minecraft","category-python","tag-ai","tag-gpt","tag-machine-learning","tag-neural-networks","tag-python","tag-pytorch"],"_links":{"self":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/5084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5084"}],"version-history":[{"count":6,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/5084\/revisions"}],"predecessor-version":[{"id":5092,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=\/wp\/v2\/posts\/5084\/revisions\/5092"}],"wp:attachment":[{"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.paleotechnologist.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}