<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kamil Rocki on Medium]]></title>
        <description><![CDATA[Stories by Kamil Rocki on Medium]]></description>
        <link>https://medium.com/@kamil.rocki?source=rss-d4c93b50f9bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6QgL3iIkpYOTK4Ru.</url>
            <title>Stories by Kamil Rocki on Medium</title>
            <link>https://medium.com/@kamil.rocki?source=rss-d4c93b50f9bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:39:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kamil.rocki/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I taught myself how to build a turbocharged gasoline engine from a single YouTube video in 100…]]></title>
            <link>https://medium.com/hackernoon/i-taught-myself-how-to-build-a-turbocharged-gasoline-engine-from-a-single-youtube-video-in-100-88420f7d4bf3?source=rss-d4c93b50f9bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/88420f7d4bf3</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[cars]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Kamil Rocki]]></dc:creator>
            <pubDate>Mon, 31 Dec 2018 20:26:36 GMT</pubDate>
            <atom:updated>2019-01-08T05:32:49.415Z</atom:updated>
            <content:encoded><![CDATA[<h3>What do hackers do in their spare time? I spent 100 hours watching YouTube and I taught myself how to build a turbocharged gasoline engine</h3><h4>It is incredible how much knowledge and experience of other people is readily available nowadays. Inspired by this fact and also recent advancements in AI, I set out on a quest to accomplish a complex task by imitating behavior and working in a procedural way to determine how an algorithm would approach the problem.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*4cRXWFjr80nb4FQk42870g.gif" /><figcaption>Internal combustion process, source: Giphy</figcaption></figure><p>The last day of the year is usually a good time to recall what we have learned, accomplished since January 1st, possibly what we haven’t accomplished and what we are planning for the following year.</p><p>Exactly a year ago I challenged myself. Let me share my adventure with you. I hope that it will provide a useful data point and hopefully a source of inspiration for someone.</p><p>Just to give you a short introduction. I am a researcher. I like asking questions and figuring out how to answer them. My question was this:</p><p><strong><em>Given the abundance of human knowledge available online, could one learn something non-trivial in a self-taught (unsupervised) manner just by browsing the internet.</em></strong></p><p>While you could quickly say: <strong><em>Yes!</em></strong> or <strong><em>No!</em></strong>, I wanted to do it in a more scientific way. I decided to run an experiment on myself. In this article I will describe what I did and the outcome of this experiment as concretely as possible — because the essence of science is reproducibility, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*W6YJrVCXfOAOWZBllpJLbg.gif" /><figcaption>Source: Another World, Delphine Software</figcaption></figure><p>I hope that you are still with me. If so, then I’ll say a little bit more about my motivation.</p><p>The main reason is the fact that I do research on Artificial Intelligence (AI). More specifically, I am interested in unsupervised learning. This is a kind of AI that could gather data automatically and figure out what to do with it.</p><p>There is a nice blog post by Andrej Karpathy about trying to classify images manually in order to determine the human performance on data which would available to AI</p><ul><li><a href="http://karpathy.github.io/2014/09/02/what-i-learned-from-competing-against-a-convnet-on-imagenet/">Andrej Karpathy’s efforts with manual image classification</a></li></ul><p>I decided that it would be nice to do something like this, but on something more complex.</p><p>But that was not the only reason. Many times in my life I have heard that you really need formal education in order to do something and that it is essential to get proper training (by someone who is already a master at something). As a consequence, you need to determine your destiny very early in your life and then live with it. I disagree. I think that it used to be the case, but is not anymore.</p><p>Especially in machine learning community there is an ongoing debate on whether it is necessary to possess an official degree or not. I have a PhD degree in Computer Science, so I might be the right person to say that you don’t need one. What you do need is this:</p><ul><li>Curiosity</li><li>Perseverance (this is really important)</li><li>Ability to determine what is true in the data flood</li></ul><p>I think I am curious and I can endure a lot, the third one may need some practice, but can be learned. That’s it.</p><h3>OK. So here is the experiment.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*HvJ7cQjeN4Pyzx8yQDLfUg.gif" /><figcaption>Source: Another World, Delphine Software</figcaption></figure><h4><strong>THE TASK</strong></h4><p><em>Assembly of a 2.5-liter 4-cylinder turbocharged boxer engine (EJ257) with Active Valve Control System (AVCS) manufactured by Fuji Heavy Industries.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Qg94GYO4_95YwqhwIiMK2w.png" /><figcaption>EJ25 engine. Source: Subaru</figcaption></figure><p>I was lucky to some extent that I had something non-trivial that needed to be done (I had some time I could donate to science). It met all the conditions:</p><ul><li>I really had no idea how to do this. People told me I was doomed to fail.</li><li>There was data (unfiltered) available online</li><li>It looked complex enough that could be used as a proxy problem for something else (I estimated the time needed to accomplish it to be about 100 hours).</li><li>There was a simple <strong>YES/NO</strong> answer at the end</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*auevd9WIFEoOQg6Vx_GTzA.png" /><figcaption>April 2017, Buttonwillow raceway. I killed this engine then, so I could use it for science. It was dead, so I heard that everything had to be disassembled or replaced.</figcaption></figure><h4>THE GOAL</h4><p>Disassemble, repair, assemble. Run for 10000 miles (when you go to a professional mechanic, they will give you this kind of warranty)</p><h4>THE METHOD</h4><p>Imitate. Learn by watching a single YouTube video. Don’t do something overly clever.</p><p>It worked (passed 10000 mile mark today). Without further ado, I will describe what I did. If you are not interested in details, you can skip to the end.</p><h3>THE DETAILS</h3><p>In this section I will:</p><ul><li>Attempt to convince you that the problem is in fact not trivial</li><li>Show the steps taken</li></ul><p>Without further ado, I will describe what I did next.</p><p><strong>As mentioned before, I had almost zero knowledge about this</strong> (full disclaimer: I changed brake pads previously).</p><p><a href="https://www.youtube.com/watch?v=kUfNrB1Dy54">This is the video I used</a> and attempted to reverse engineer what was being done. I could assume that the guy (Frank?) knows what to do, because at the end he starts the engine and it works. But all I could do was to watch and imitate. Try it yourself (the is no commentary and everything is sped up)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkUfNrB1Dy54%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkUfNrB1Dy54&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkUfNrB1Dy54%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a77cbccc08742c0c520cd2d0c15eabc/href">https://medium.com/media/7a77cbccc08742c0c520cd2d0c15eabc/href</a></iframe><p>Based on the YT video, I tried to figure out what are the tools and parts necessary. For that I used <a href="https://parts.subaru.com/Subaru_2012_STI.html">Subaru site</a> and ordered parts which I needed (initially I did not even know what I needed, it turned out that the replacement parts cost me $500). I also found various discussions on <a href="https://forums.nasioc.com/">Subaru boards</a>, but they were not that much useful as there were either conflicting descriptions or people claimed (again), that only mechanics should handle this.</p><p>My budget for tools was $1000 (to make it realistic). I made a few purchases of Amazon: <a href="https://www.amazon.com/Dragway-Tools-Folding-Hydraulic-Engine/dp/B00294B0LS/ref=sr_1_4?ie=UTF8&amp;qid=1546177363&amp;sr=8-4">Engine Crane (~$300)</a>, <a href="https://www.amazon.com/DEWALT-DCF880HM2-20-volt-Lithium-2-Inch/dp/B00BWFIKJA/ref=sr_1_3?ie=UTF8&amp;qid=1546177465&amp;sr=8-3">Impact wrench</a> ($200), Some other wrenches ($200) and hoped I could figure out how to use them.</p><p>The experiment officially commenced on January 1st, 2018.</p><h4>Part I — Disassembly (Jan 1st — Feb 3rd)</h4><p>The main problem related to this part was to find proper tools and identify all the parts (segmentation?). I also anticipated further issues with figuring out with parts belonged where, so I needed a system to track them.</p><p>One pretty useful heuristic when solving this task was to identify all bolts/screws and remove them. I also compared consecutive frames in order to determine what was removed. This was little bit like ‘spot the difference’ game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*MEITyaQ0Yzsp6sJKp9JIQA.png" /><figcaption>LEFT: 3:01 in the video, RIGHT: ten seconds later</figcaption></figure><p>From the perspective of imitation learning, I primarily relied on image classification. I actually extracted frames from the video a few times and ran them through reverse image search. The hardest objects were the tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/82/1*OUjzy2jVk1lRoz_nO1yxfA.png" /><figcaption>What is this?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/1*mViFo3xnp7KAx07QZuA7Zw.png" /><figcaption>Piston ring compressor</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/238/1*ggDaS1PfKDoSJ-l8eJWLRw.png" /><figcaption>This one was pretty hard</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/1*8SIMKDtpuxhLZ5E4DEb7og.png" /><figcaption>Can of oil</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*suJACBk23mhLoG6trpJhNg.png" /><figcaption>Pistons</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*Lpp2RhfrJXAisLw_Gb3b6Q.png" /><figcaption>Got this crane of Amazon based on the video</figcaption></figure><p>Some more complex examples require action recognition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/1*3OWhwOmLvwRs0XFOX5gu_w.png" /><figcaption>This one is easy</figcaption></figure><p><strong>Here’s some documentation:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*M6pk8zQBGsAP0rt9k6XI1Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*CH_0L0rjKUDVMYW95kkvfg.jpeg" /><figcaption>LEFT: Jan 1st, 2018. Impact wrench, crane and coffee, RIGHT: Jan 2nd, 2018. Pulled it out, that’s about 15 hours so far and a approximately 5% of the total work.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ohSwjAx0JWiq0saUTkfjmg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUBc0bdeZn2nVxfJeXBd7w.png" /><figcaption>LEFT: Jan 20th. Here I already removed most of the stuff, intake and exhaust manifolds are off, wiring is off, what you see is the front — timing belt with 2 cylinder heads on the sides. RIGHT: Jan 24th. Taking off cylinder heads, removing the camshafts.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b59_Ey_Cw8m7KGnPY-smKQ.png" /><figcaption>Jan 25th. Moved inside the house because of rain. LEFT: The block and two cylinder heads. RIGHT: My `workshop`, when I wrote I was doing this by watching YOUTUBE, I meant it! This is the same video linked above.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fnOJSbiD9Q0wlp01UFuJVw.png" /><figcaption>Feb 1st, LEFT: Pistons are out, RIGHT: The block is split and the only things left are the piston rods and the crankshaft.</figcaption></figure><h4><strong>Part II — Diagnosis and fix (Feb 4th — March 14th)</strong></h4><p>Success. I was able to find the root cause of the problem. In order to fix the issue, I needed to replace 4 piston rod bearings. At the same time I decided to get a brand new set of forged pistons and rods, get the crankshaft and cylinder heads machined. Replace timing belt, etc. After all, I was not paying for labor. This part was mostly about figuring out part numbers and waiting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*S9CIKFYG32aRryq_YRsTGA.jpeg" /><figcaption>Feb 4th. I disassembled everything. Found the cause. Can you spot a problem? One of the piston rods was lacking a bearing due to excessive wear.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*cJSmaP8zwqZuYEWwKZJ1Kw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*w4SjpnIqkFcNqd2rX0s_2w.png" /><figcaption>LEFT: This is a replacement for the part which failed (rod bearing). RIGHT: New pistons.</figcaption></figure><h4>Part III — Assembly and debug (March 15th — April 17th)</h4><p>The hardest part (as expected). Here, I needed to purchase a few extra tools:</p><ul><li>A torque wrench ($50)</li><li>Piston ring gap file and ring compressor ($150)</li></ul><p>Most of the work was related to figuring out which bolt goes where. The heuristic used here was doing things in the reverse order (I put the parts in plastic bags with time and date during disassembly). There was also a lot of measuring and reassembling things 2 or 3 times, because I missed something.</p><p><strong>From the AI standpoint, the hardest part was related to the part at 12:24 in the video.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*XlSsTkOKOfzmHe5alxdlIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*K0VCH3nf5qtjkbMwi9Fv-Q.png" /><figcaption>I had really hard time figuring out what these numbers mean exactly and what they are used for. Eventually, I was able to link the numbers to the manual I got (RIGHT)</figcaption></figure><p><strong>SOME more photo-journalism:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dV6bf93fdDkDpSYks3AYxw.png" /><figcaption>These are my notes for doing the assembly. You can see how I planned the order and estimated time in hours. Also, the are some references to the Youtube video (i.e. Oil Cooler 19:20 refers to that point in the video).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cF1na3KLDwMCSa8T6q9S_Q.png" /><figcaption>Machined cylinder heads, cylinder walls and the crankshaft. ARP head studs mounted.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*M5v435oBhQC4hYlwjPatmg.jpeg" /><figcaption>April 2nd. One of the hardest parts. Took much more time than I anticipated. Adjusting the piston rings required some extra research and math. Pistons expand due to temperature and the gap needs to be just right.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*igzcXpn18d70SvvDAJozAw.png" /><figcaption>LEFT: Preparing to assemble the most important parts — the rotating assembly — RIGHT</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5DThJVyH9dHPLPn3QoIMA.png" /><figcaption>LEFT: Crankshaft is in the half-case, RIGHT: Pistons are in. Only 40h to go…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvGT8bC5BGv2-MRF5k43wQ.png" /><figcaption>This part is quite tricky, need to readjust clearances between camshafts and valve buckets before mounting the cylinder heads. 30h left?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gTns6YQO-JBiCrU4XZ6HGA.png" /><figcaption>LEFT: Block prepared for mounting cylinder heads, RIGHT: Cylinder heads in place. It requires quite a lot of strength to torque them properly.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*DAy3jdl-e12Nnwy-mupfKA.png" /><figcaption>Putting timing belt back on was tricky too. Almost done. 15 more hours and it should be ready.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZuzjiMNYL4QoRoB29nlzw.png" /><figcaption>Going where it belongs. Just 5 hours left to mount the engine.</figcaption></figure><h4>Part IV— Evaluation (April 18th — December 31st)</h4><p>After putting the engine in, there were a few parts which I had to fix (missing wire, etc). This took me about a day, then we everything ‘compiled’, the engine started on April 18th and today I decided to conclude.</p><p>During this phase, I tried anything to find an issue, I even used a microscope and looked for something in the oil, but nothing there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*nwJ19Rd7n4yxPDQH0zqetQ.png" /><figcaption>Nerdy me: I used a microscope to look for suspicious stuff in the oil every time I changed it. RIGHT: here’s what you can see if you zoom in a lot. What you should not see: pieces of metal (they would have crystal-like structure).</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FRH_Qb7qACkQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DRH_Qb7qACkQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FRH_Qb7qACkQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/24b52de50b481a5f98f1472f2171e4cf/href">https://medium.com/media/24b52de50b481a5f98f1472f2171e4cf/href</a></iframe><p>I have driven 10000 miles (just passed the mark today) and it still works. I have no issues with it. I also checked the power, it is exactly the same as before. Fuel consumption is even lower. Everything is in order.</p><h3>Conclusion</h3><p>It took about 100 hours of physical labor and probably twice as much time in research (watching that YouTube video over and over again, probably I watched it about 50 times). I believe that AI is changing the world and we will probably see bots learning from videos like this one.</p><p>The hardest part was getting through the noise in information — there are places where you will see conflicting directions. This is where it is kind of useful to have a PhD degree — you are just trained to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*ZNPVq8jN7ZSJnmhUeAnnPA.gif" /><figcaption>Source: Another World, Delphine Software</figcaption></figure><p>Overall, I can easily say that now I am at least as qualified as some mechanics I talked with before. Changing oil now takes me about 10 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*65YSigEByDCqf9YEQrgwkQ.png" /></figure><h4>The Real Conclusion</h4><p>If you really want to do something, just do it. The worst is that you’ll learn something and fail, and the best that if you consider what is available online nowadays, it will change your life and give you a lot of satisfaction. Just be prepared to fail a lot and be patient.</p><p><strong>Happy New Year! Let this inspire you to learn something new in 2019.</strong></p><p>P.S. Let me know if you would like to learn more about this work. I tried not to go too deep.</p><h3>Future work</h3><p>Armed with this knowledge, this is obvious, I’m now working on using Reinforcement Learning to swap the original control unit with a Neural Net based one:). Just started working on a piece of code which hopefully can provide more power and lower fuel consumption by learning how to control the combustion process — isn’t anyone working on this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ESDKowiUl558oYdpN9xZ7A@2x.jpeg" /></figure><h4>CREDITS</h4><ul><li>The paper <em>‘</em><a href="https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005268"><em>Could a Neuroscientist Understand a microprocessor’ (Jonas et al.)</em></a> provided a lot of inspiration. In order to determine if we are capable of understanding human brain by looking at neurons and activations, the authors wanted to figure out if we can understand a microprocessor using same methods. My question is: `Can a programmer understand an internal combustion engine by watching YouTube?`</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*FXTPhHdYQzN4BPaMW-Zw8g.png" /><figcaption>Source: <a href="https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005268"><em>Could a Neuroscientist Understand a microprocessor’ (Jonas et al.)</em></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88420f7d4bf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/i-taught-myself-how-to-build-a-turbocharged-gasoline-engine-from-a-single-youtube-video-in-100-88420f7d4bf3">I taught myself how to build a turbocharged gasoline engine from a single YouTube video in 100…</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A GAMEBOY supercomputer]]></title>
            <link>https://medium.com/data-science/a-gameboy-supercomputer-33a6955a79a4?source=rss-d4c93b50f9bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/33a6955a79a4</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[nintendo]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kamil Rocki]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 21:38:57 GMT</pubDate>
            <atom:updated>2018-11-06T13:03:59.455Z</atom:updated>
            <content:encoded><![CDATA[<p>At a total of slightly over 1 billion frames per second it is arguably the fastest 8-bit game console cluster in the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*B4symXkzExzOMlfqVPoA3w.gif" /><figcaption>Distributed Tetris (1989)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1_G9PvgZfRj8FhIjW_vA3w.png" /><figcaption>1 of 48 boards of IBM Neural Computer which was used for experiments</figcaption></figure><p>How to build one?</p><h4>The recipe</h4><p>Take a handful of silicon, pour <strong>reinforcement learning </strong>knowledge, <strong>supercomputing </strong>experience and <strong>computer architecture </strong>passion, then add sweat and tears, and finally stir for approximately 1000 hours until it boils and <em>voilà…</em></p><p><strong>Why would anyone want to have one?</strong></p><h4><strong>Short answer</strong>: to move towards strong artificial intelligence.</h4><p>And here’s the <strong>longer version</strong>:</p><p><strong>It is 2016</strong>. Deep learning is everywhere. Image recognition can be considered kind of solved by convolutional neural networks and my research interests gravitate towards neural networks with memories and reinforcement learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*qmfiLeHUwutY9BW-thYo6Q.png" /></figure><p>Specifically, in a paper showed by <em>Google Deepmind</em>, it has been shown that it is possible to achieve human or even superhuman-level performance on a variety of Atari 2600 (a home game console released in 1977) games using a simple reinforcement learning algorithm called <em>Deep Q-Neural Network</em>. All that done by just observing the gameplay. That caught my attention.</p><p><a href="https://www.nature.com/articles/nature14236">Client Challenge</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*jFGC1FC_YZs6QQEnxu44wg.gif" /><figcaption>One of the Atari 2600 games, Breakout. Trained using a simple RL algorithm. After millions of iterations, the computer agent plays at a super-human level.</figcaption></figure><p>I started running experiments on Atari 2600 games. As much as impressive it is, <em>Breakout</em> is not a complex game. One could define complexity by the degree of difficulty in connecting your actions (joystick) to results (score). A problem arises when one needs to wait a long time until an effect can be observed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*dCHzebBwc_uGOXwMEGyiag.gif" /><figcaption>An illustration of the problem with more complex games. LEFT: Breakout (ATARI 2600) is very reactive, we get feedback very quickly; RIGHT: Mario Land (NINTENDO GAMEBOY) does not provide immediate information about consequences of an action, there can be stretches of irrelevant observations between important events</figcaption></figure><p>In order to make learning more efficient, you could imagine trying to transfer some knowledge from simpler games. This is what remains unsolved right now and is a hot research topic. A recently published challenge by OpenAI tried to measure just that:</p><p><a href="https://contest.openai.com/2018-1/">OpenAI Retro Contest</a></p><p>Not only would having transfer learning capability make training faster, but I would even argue that some problems cannot be solved unless there is some prior knowledge present. What you need is <strong>data efficiency.</strong> Let’s take a look at Prince of Persia:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*ldPy20b-sxYGXS43NMbRLA.gif" /><figcaption>A short clip from Prince of Persia</figcaption></figure><ul><li>There is no obvious score</li><li>If no action is performed it takes 60 minutes to end the game (58 minutes left in the animation).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*mrygOlg_OBfJA449tlKf9A.gif" /><figcaption>Random actions</figcaption></figure><p>Could you try the exact same approach as in the Atari 2600 paper? I you think about it, how likely is it that you’ll get to the end by pressing keys at random?</p><p>This motivated me to contribute to the community by addressing this problem. So, in essence, have a chicken and egg problem — you need a better algorithm which allows you to transfer knowledge, but that requires research and experiments take a long time, because we don’t have a more efficient algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*sDywoUie4KfxwZLKgaPvnw.png" /><figcaption>Transfer learning example: Imagine first learning a very simple game, such as the one on the lefthand side, then you preserve concepts such as ‘race’, ‘car’, ‘track’, ‘win’, and learn colors or 3D models. We say that the common concepts are ‘transferrable’ between those games. One could define similarity by the amount of transferrable knowledge between two problems. I.e. Tetris and F1 racing will not be similar.</figcaption></figure><p>I decided to do the second best thing then, avoid the initial slowdown by making the environments much, much faster. My goals were to have:</p><ul><li><strong>Faster environment</strong> (imagine you could finish Prince of Persia in 1/100th the time) and run 100.000 games at the same time</li><li><strong>Better environment</strong> for research (focus on the problems, but not preprocessing, have variety of games)</li></ul><p>Initially, I thought that the performance bottleneck may be to some extent related to the complexity of the emulator code (for example Stella’s codebase is quite big, plus it relies on C++ abstractions which are not the best choice when it come to emulators).</p><h3><strong>Consoles</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Z_c4xJVL65gMQLQtD1rwNQ.jpeg" /><figcaption>Arcade Space Invaders</figcaption></figure><p>In total, I have worked on several platforms, starting with probably one of the first games ever (along with Pong) — the arcade ‘Space Invaders’, Atari 2600, NES and Gameboy. All that written in C.</p><p>The maximum frame-rate I could observe was about 2000–3000 FPS. In order to start seeing results of experiments, we need millions or billions of frames, so the gap was huge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*wm_6_uNb_UHwFf0oxMEiCQ.gif" /><figcaption>My Space Invaders running inside an FPGA — low speed debug mode, the counter in the FPGA shows clock cycles elapsed</figcaption></figure><p>I thought — what if we could hardware-accelerate those environment. For example, the original Space Invaders run on 8080 CPU operating at 1MHz. I was able to emulate a 40MHz 8080 CPU on a 3GHz Xeon. Not bad, but as a proof of concept, once put inside an FPGA, this went up to 400 MHz. This means 24000 FPS from a single instance — an equivalent of a 30GHz Xeon CPU! Did I mention that one you can fit around 100 8080 CPU in a mid-tier FPGA? That’s 2.4M FPS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*1PYYiCH0GH-6B--6C4tfiw.gif" /><figcaption>Hardware-accelerated Space Invaders, 100MHz, 1/4 of the full speed</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*WqVVf-DtUTSGcE4jSaOcgA.png" /><figcaption>Over one hundred tiny cores inside one Xilinx Kintex 7045 FPGA (bright colors, the blue patch in the middle is shared logic for display)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*dtCxUHd6yhB27xp1zbRVSQ.png" /><figcaption>Irregular Execution Path</figcaption></figure><p>At this point, you might ask, what about GPUs? The short answer is you need MIMD parallelism, not SIMD. Back in my student years, I spent some time working on a GPU implementation of Monte Carlo Tree Search (MCTS was used in AlphaGo).</p><p><a href="http://olab.is.s.u-tokyo.ac.jp/~kamil.rocki/rocki_ipdps11.pdf">http://olab.is.s.u-tokyo.ac.jp/~kamil.rocki/rocki_ipdps11.pdf</a></p><p>At that time I have spent countless hours trying to make GPUs and other kind of SIMD hardware (IBM Cell, Xeon Phi, AVX CPUs) run this kind of code efficiently and failed. A few years ago I started to believe that I would be really nice to be able to design my own piece of hardware, aimed at RL kind of problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*lpfWyn7ZEk18EBb5sXVtsg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*xP_DiXv4Q1engAMWkqfHKQ.png" /><figcaption>Multiple Instruction Multiple Data (MIMD) Parallellism</figcaption></figure><h3>ATARI 2600, NES or GAMEBOY?</h3><p>In total, I implemented 8080 with space invaders, NES, 2600 and gameboy. Here are some facts about those and their individual advantages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*icJio0lP13Bxtcyc642RYg.png" /><figcaption>NES Pacman</figcaption></figure><p>The Space Invaders was just a warmup. We got it to work, but it’s just that one game, so it is not very useful.</p><p>Atari 2600 is de facto standard in reinforcement learning research. The CPU (MOS 6507) is a simplified version of the famous 6502 and it’s more elegant in design and more efficient than 8080. I did not choose 2600 just because I think that there a certain limitations regarding the games and graphics.</p><p>I implemented NES (Nintendo Entertainment System) as well, it shares the CPU with 2600. Games are much much better than the ones on 2600. Both NES and 2600 suffer from overcomplicated graphics processing pipeline and many cartridge formats which need to be supported.</p><p>In the meantime, I rediscovered Nintendo Gameboy. This was what I was looking for.</p><p><strong>Why is Gameboy so awesome?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KImHkfpGHVbD4dCO03JgoQ.jpeg" /><figcaption>1049 Classic games + 576 for Gameboy Color</figcaption></figure><ul><li>Over 1000 games in total (Classic + Color), very wide range, all high quality, some of them very challenging (Prince), games can be somewhat grouped and assign difficulty for research on transfer learning and curriculum learning (for example there are variants of Tetris, racing games, Marios). Trying to solve Prince of Persia may require transferring knowledge from some other similar game which has explicit score (Prince doesn’t!)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ZJuD6dyafZBoNGW2r53rmw.gif" /><figcaption>Nintendo Gameboy is my transfer learning research platform of choice. In this chart I tried to group the games and plot them according to their difficulty (subjective judgement) and their similarity (concepts such as racing, jumping, shooting, variety of Tetris games; Has anyone ever played HATRIS?).</figcaption></figure><ul><li>Gameboy classic has a very simple screen (160 by 144 2-bit color) which makes preprocessing simpler, we can focus on the important things. In case of 2600, even simple games have various colors. In addition to that Gameboy has much better way of displaying objects so no flickering or taking max of a few consecutive frames is required.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*y42BQ6QZTfB7GMslvkJZng.gif" /><figcaption>IBM Boot ROM + Super Marioland</figcaption></figure><ul><li>No crazy memory mappers as in NES or 2600 case. You can get most of the games work with 2–3 mappers in total.</li><li>It turned out to be quite compact, overall I was able to complete the C emulator in under 700 lines of code and my Verilog implementation in approximately 500.</li><li>It comes with the same simple version of Space Invaders as the arcade version</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*0Uq93Z3SQs9GO36GzoXsWg.gif" /><figcaption>Gameboy version of Space Invaders — Basically no preprocessing needed!</figcaption></figure><p>So, here it is, my Dot-Matrix Gameboy from 1989 and and FPGA version running through HDMI on a 4K screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/291/1*yi3Vd9FxG-LdstNCbcB8OQ.png" /></figure><p>An this is something that my old Gameboy cannot do:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*vVHnSlofPMPJZOC33kQwkw.gif" /><figcaption>Hardware accelerated Tetris, this is a realtime screen recording at 1/4 the max speed.</figcaption></figure><h3>Is it actually useful?</h3><p>Yes, it is. So far, I have tested it in a simple setting where there is an external policy network, which interacts with the Gameboy workers. More specifically I used distributed A3C (Advantage Actor Critic) algorithm and I’ll describe that part in a separate post. A colleague of mine also connected it to FPGA convnet and it works quite well. More to come in the upcoming post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*ZWASEPnALlDWNgm9XEHlFw.png" /><figcaption>FPGA-NN communication</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZylR1PjQ3f2TINytrfgsQ.png" /><figcaption>Distributed A3C setup</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*gCyO9nbV31QnM_BPLpNBVA.gif" /><figcaption>Mario land: Initial State. Pressing buttons at random does not get us far. Top right corner shows remaining time. If we get lucky and Goomba, we finish quickly as we touch Goomba. If not, it takes 400 seconds to ‘lose’.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*2AtLL44AT42ilfbYUJL4QQ.gif" /><figcaption>Mario land: after less than 1 hour of gameplay, Mario has learned to run, jump and even discovers a secret room by going into a pipe.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/160/1*s703qC6WkjGXhGZ6e-nBPA.gif" /><figcaption>Pac Man: after about one hour of training it can even finish the entire game once (eats all dots), then the games starts all over again.</figcaption></figure><h3>Conclusion</h3><p>I like to think of the next decade as a period when HPC and AI finally come together. I would like hardware which has some degree of customization allowed, depending on the AI algorithm of choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HG0bxS2b8Z2FxbgQ6TIihw.png" /><figcaption>The Next Decade</figcaption></figure><p>Here the GB C Code <a href="https://github.com/krocki/gb">https://github.com/krocki/gb</a></p><h3>Bonus A — Debugging</h3><p>This part probably deserves an article on its own, but for now, I am too tired.</p><p>I often get asked: what was the hardest part? Everything… it was very painful. There is no such thing as specification of gameboy to begin with. Everything what we know is the result of reverse engineering, and by that I mean: running some proxy task such as a game or any other snippet and observe if it executes. This is very different from standard software debugging as here the hardware which executes the code is being debugged. I had to come up with some ways of going through the process. Did I mention that it’s hard to see something when it runs at 100MHz? Oh, and there’s not printf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*nfFzqxsF2DFGGhYVJka-cg.png" /><figcaption>One approach to implementing the CPU is to group instructions into some clusters which do more or less the same thing. This is much easier with 6502. LR35092 has much more `random` stuff and many edge cases. Here is the chart which I used while I worked on the Gameboy CPU. I adopted a greedy strategy of taking the largest chunk of instructions, implementing it and then crossing it out, then repeat. In this case 1/4 of the instructions are ALU, 1/4 are register loads which can be implemented relatively quickly. On the other side of the spectrum, there are some outliers such as `load from HL to SP, signed` which need to be handled separately</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*-Gx5hblgqpUu9FODEPkfXA.jpeg" /><figcaption>Debugging: you run a piece of code on the hardware you are debugging, record a log for your implementation and some other reference implementation (here I compared Verilog code, left vs my C emulator, right). Then you run diff on the logs to identify discrepancies (blue). One reason for using some automated way is that in many cases I found problems after millions of cycles of execution, where a single CPU flag caused a snowball effect. I tried many approaches and this seemed to be one of the most effective ones.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*Ro2e9fSZ0sion6n1Ppwz4g.png" /><figcaption>You need coffee! Lots of it.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*r9oL8LXCECzd2fllb-7XXw.png" /><figcaption>These books are 40 years old — It’s incredible to go through them and see the world of computers through the eyes of the users then. I felt like a visitor from the future.</figcaption></figure><h3>Bonus B — OpenAI request for research</h3><p>Initially I wanted to approach the games from from the memory-view point as described in this post by OpenAI.</p><p><a href="https://openai.com/requests-for-research/#q-learning-on-the-ram-variant-of-atari">Requests for Research</a></p><blockquote>Surprisingly, getting Q-learning to work well when the inputs are RAM states has been unexpectedly challenging.</blockquote><blockquote>This project might not be solvable. It would be surprising if it were to turn out that Q-learning would never succeed on the RAM variants of Atari, but there is some chance that it will turn out to be challenging.</blockquote><p>Given the fact that Atari games use only 128B of RAM it was very appealing to process those 128B instead of entire screen frames. I was getting mixed results, so I started digging into this.</p><p>While I cannot prove that it is impossible to learn directly from memory, I can show that the assumption that the memory captures the entire state of the game, is wrong. Atari 2600 CPU (6507) uses 128B of RAM, but it has also access to extra registers which ‘live’ in a separate circuit (Television Interface Adapter, kind of a GPU). Those registers are used to store and process information about objects (paddle, missile, ball, colissions). In other words this will NOT be available when only RAM is considered. Similarly, NES and Gameboy have extra registers which are used for screen manipulation and scrolling. RAM alone does not reflect the full state of the game.</p><p>Only 8080 stores data into VRAM in a direct way, which would allow retrieval of the entire state. In other cases, the ‘GPU’ registers are plugged in between the CPU and Screen Buffer, outside RAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*C50jAZmMHMnc9BTDb-jh4w.png" /></figure><p><strong>Trivia</strong>: If you’re doing research on the history of GPUs, this might be the very first ‘graphics accelerator’ — 8080 has an external shift register to move the invaders using a single command, offloading the CPU.</p><h3>References</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FHyzD8pNlpwI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHyzD8pNlpwI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FHyzD8pNlpwI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d6da2be6684f0ce9cba538ae9e2540d/href">https://medium.com/media/0d6da2be6684f0ce9cba538ae9e2540d/href</a></iframe><ul><li><a href="https://medium.com/@fogleman/i-made-an-nes-emulator-here-s-what-i-learned-about-the-original-nintendo-2e078c9b28fe">I made an NES emulator. Here’s what I learned about the original Nintendo.</a></li><li><a href="https://blog.rekawek.eu/2017/02/09/coffee-gb/">Why did I spend 1.5 months creating a Gameboy emulator? · tomek&#39;s blog</a></li><li><a href="http://karpathy.github.io/2016/05/31/rl/">Deep Reinforcement Learning: Pong from Pixels</a></li></ul><p>And many more…</p><p>Gameboy and NES are registered trademarks of Nintendo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*WTBt7qp_gndCeksOyYN6QA.png" /></figure><p>EOF</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33a6955a79a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/a-gameboy-supercomputer-33a6955a79a4">A GAMEBOY supercomputer</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>