<?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 Pete Garcin on Medium]]></title>
        <description><![CDATA[Stories by Pete Garcin on Medium]]></description>
        <link>https://medium.com/@rawktron?source=rss-8f6dc5f0b402------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YtCIs5vgrEq4U9K_.jpeg</url>
            <title>Stories by Pete Garcin on Medium</title>
            <link>https://medium.com/@rawktron?source=rss-8f6dc5f0b402------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:56:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rawktron/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[Reproducible Builds: Introducing predictability into your pipeline]]></title>
            <link>https://medium.com/@rawktron/reproducible-builds-introducing-predictability-into-your-pipeline-6b79c4a8d6a8?source=rss-8f6dc5f0b402------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b79c4a8d6a8</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[reproducibility]]></category>
            <dc:creator><![CDATA[Pete Garcin]]></dc:creator>
            <pubDate>Thu, 15 Feb 2018 15:03:04 GMT</pubDate>
            <atom:updated>2018-02-15T15:03:04.410Z</atom:updated>
            <content:encoded><![CDATA[<p>Can your build pipeline perfectly reproduce a build including its critical bug that is deployed to a particular subset of machines? Reproducible builds is a fundamental problem that any developer who’s shipped software has had to deal with at some point.</p><p>When we’re talking about reproducible builds there’s a wide range of definitions — from builds that are byte-for-byte identical, builds that have the identical set of input source-code, to builds that share the same version numbers.</p><p>Despite the exploding popularity of Go — reproducible builds is one of the largest barriers to the widespread adoption of Go in certain environments. There are a large number of reasons that Go is an excellent language for modern projects, but clearing the reproducibility hurdle is an important milestone to even more widespread usage.</p><p>When you’re dealing with open source software, the dependency trees for certain packages can grow extremely large. Dependency management is still an ‘in-progress’ solution for Go, and a hard problem in general. Pinning versions, resolving complex dependency trees, and multiple versions of the same packages are all problems that surface during development</p><p>Finally, containerization has made reproducible production environments feel like a solved problem, but many organizations are still making the transition to using containers for deployment — and are they really a silver bullet to making your deployments seamless?</p><p>Whether you’re actively using Go, looking to move to containerization for deployment, or simply struggling with complex build issues — join me on <a href="https://start.activestate.com/feb-roundtable-youtube/">February 22nd for an in-depth discussion</a> “Introducing predictability into your pipeline” with some of the brightest minds in the space:</p><ul><li>Jess Frazelle, Microsoft</li><li>Russ Cox, Google</li><li>Sam Boyer, Stripe</li></ul><p>This panel of experts, moderated by yours truly, joins us to share developments, discuss solutions and best practices to help introduce more reproducibility into your builds.</p><p>At ActiveState, we’ve been working on open source languages for over 20 years. We consider ourselves experts in build engineering and understanding what enterprises need and the challenges developers face. We’re trying to take over 20 years working on open source languages like Python, Perl, Tcl, Ruby and Go and make the developer experience an awesome one. True to our roots we’ll need to work with communities and the ‘coder crowd’ at large to solve them.</p><p>So join us <a href="https://start.activestate.com/feb-roundtable-youtube/">LIVE on Feb 22nd</a> for a killer discussion of how we can all introduce more predictability into our build pipelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jkwSNnoT4zRUeZaO." /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b79c4a8d6a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Game AI Using Machine Learning: Working with TensorFlow, Keras, and Intel MKL in Python]]></title>
            <link>https://medium.com/@rawktron/building-game-ai-using-machine-learning-working-with-tensorflow-keras-and-intel-mkl-in-python-55ea5482bb26?source=rss-8f6dc5f0b402------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ea5482bb26</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Pete Garcin]]></dc:creator>
            <pubDate>Thu, 25 May 2017 17:03:32 GMT</pubDate>
            <atom:updated>2017-05-30T17:17:37.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*kdVvOBo_MQ-iefKPgpRJ2g.jpeg" /></figure><p>Heading into PyCon, we wanted to put together something to demonstrate some of the excellent Python packages that are available in the machine learning space as well as showing off some of the newly integrated Intel® Math Kernel Library (MKL) optimizations in the <a href="https://www.activestate.com/activepython/downloads">latest ActivePython release</a>. That demo became “NeuroBlast”, a classic arcade space shooter game that features enemies powered by machine learning. It was a fun way to get folks engaged at our booth and to learn about what’s available in the incredible Python ecosystem. It also gave me an opportunity to build something non-trivial using machine learning techniques, and my background in games made an interactive demo a good fit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*3vj_vs4JTX01AWQi.jpg" /><figcaption><em>Demoing NeuroBlast to some interested folks at PyCon.</em></figcaption></figure><p>NeuroBlast is a vertically scrolling space shooter where you control a ship that tries to defeat increasing waves of enemies. Normally, these enemies fly in predefined formations, with predefined firing patterns, and come in waves. The big difference in NeuroBlast is that the enemies use machine learning to determine what their firing pattern should be.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FVQncN2b0yS8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVQncN2b0yS8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FVQncN2b0yS8%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7dd7e3c3de46a4916feeb3f20e5aae6/href">https://medium.com/media/f7dd7e3c3de46a4916feeb3f20e5aae6/href</a></iframe><h3>Under the Hood: TensorFlow, Keras, and Intel MKL</h3><p>To demonstrate what you can do with the tools available, we decided to build a Neural Network to drive the behaviour of the enemies in the game, and we built it using the popular Keras library using the TensorFlow backend. Plus, by using ActivePython to develop our game, we could leverage the Intel MKL optimizations compiled into the latest release so anything that uses certain core math functionality, eg. NumPy, would get a big speed-up out of the box.</p><p>For the game part of things, we’re using PyGame and generally speaking I was pretty performance conscious with the implementation to ensure that we could run the game at a solid framerate and still have a lot of CPU overhead available to do realtime neural net evaluations and visualization (eg. the game doesn’t feature pixel perfect collision).</p><h3>Training the Neural Net</h3><p>Our Neural Net is ultimately a very simple one — four inputs and a single output neuron. It will use supervised learning to do binary classification on a simple problem: was each shot a hit or a miss? It utilizes the delta between player and enemy position, and player and enemy velocity as the inputs. The single output neuron will fire if its activation value is &gt;= 0.5 and will not fire if it is &lt; 0.5.</p><p>When building the network, I initially had only a single hidden layer with 4 nodes but found that after training it, it was somewhat erratic. It seemed like it was very sensitive to the training data and would not ‘settle’ on a particular strategy in any consistent way. I experimented with a few different configurations, and ultimately settled on the one we used for the demo. It’s quite likely not the optimal setup, and may have more layers than is necessary. What appealed to me though was that even with a very small amount of training data, and regardless of how you trained it, it would consistently settle into a similar behaviour pattern which made it great for a floor demo where anyone could play or train the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*AEU9H8xLfK8QxTLC.png" /><figcaption><em>The inputs are the four nodes at the top, with the output node (primed to fire here) at the bottom. Thicker lines represent higher weights. Activation values appear in the node centers.</em></figcaption></figure><p>The visualization was cobbled together by myself to run inside PyGame natively. Inspired by <a href="https://medium.com/deep-learning-101/how-to-generate-a-video-of-a-neural-network-learning-in-python-62f5c520e85c">this blog post</a>, the visualization here shows connections between nodes as either red or green lines. Green lines indicate positive weights that will bias the network towards “shooting”, and red values inhibit shooting. Thicker lines indicate higher weight values and thus “stronger” connections. I had to implement it natively in PyGame because a traditional plotting library like matplotlib was just too slow.</p><p>After training, the network consistently seems to converge on the following strategy:</p><ul><li>If the player is within a reasonable cone of forward “vision” then fire indiscriminately.</li><li>If the player is not within that reasonable forward cone, then do not fire at all.</li></ul><p>At first, it was very interesting to me that the network did not settle on the more obvious “just fire constantly” strategy, but given that it does receive training data that indicates that “misses” are undesirable, it makes sense that it would avoid firing shots with a low probability of hitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*cM3xQfwhCY4BzQ8x.png" /><figcaption><em>In this image, notice that because I’m in a forward cone, most of the enemies are firing at my indiscriminately.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*0nqk9ZEOlputr5gy.png" /><figcaption><em>In this image, you’ll notice none of the enemies are firing because I am clearly outside their range of possible success. However, if you look at the activation values, you’ll see that the enemy who has just come onto the screen is about to blast me because his output is 0.83. Yikes!</em></figcaption></figure><p>In the training mode, the enemies fire randomly, and then each shot taken by the enemy is recorded as a hit or a miss along with its initial relative position/velocity values. Every one of these shots becomes a row in the training matrix and the network is trained in “realtime” after every row is added so you can see the network build and develop as you train.</p><p>It’s worth noting that in early iterations of the game, I was passing in raw pixel values for positions and velocities. This meant that there was a really wide variation between the values in the input and I found that the network would just not really converge to a consistent behaviour. So, I normalized the input data to be roughly between 0.0–1.0 and found that it basically instantly converged to a usable behaviour. So, lesson for you kids: normalize your input data!</p><p>Once the network is trained, when you play the game, every instance of an enemy spaceship uses its own instance of the neural network to make decisions about when it should fire.</p><h3>Using Keras</h3><p>Keras makes the setup and evaluation of neural nets extremely simple and the ability to choose between Theano or Tensorflow for the backend makes it very flexible. Let’s take a quick look at the Keras code to set up the network we used:</p><pre>self.keras = Sequential() <br>self.keras.add(Dense(4, input shape=(4,), activation=&#39;relu&#39;)) self.keras.add(Dense(6, activation=&#39;relu&#39;)) <br>self.keras.add(Dense(4, activation=&#39;relu&#39;)) <br>self.keras.add(Dense(4, activation=&#39;relu&#39;)) <br>self.keras.add(Dense(1, activation=&#39;sigmoid&#39;)) self.keras.compile(loss=&#39;binary_crossentropy&#39;, optimizer=&#39;adam&#39;, metrics=[&#39;accuracy&#39;])</pre><p><strong>Tip</strong>: I used Keras 2.0.4, but in an earlier versions of Keras, you will have to substitute the loss function to be “mean squared error”, and optimizer to “sgd” since the earlier version does not seem to support the binary_crossentropy/adam combination.</p><p>What’s great about Keras is that with only a very few lines of code, we can define our entire network without really needing to know much about how TensorFlow works, or even have to configure our own complex data structures to manage our own neural net.</p><p>Once we’ve finished training (in the game you can stop training at any point), we can train our model with a single line of code:</p><pre>self.keras.fit(x,y,epochs=150,batch size=10)</pre><p>That will put our input data X which is an n * 4 matrix of position/velocity data, as well as our Y data which is an n * 1 vector of 1s and 0s through 150 epochs of training. (<strong>Note:</strong> If you’re using an earlier version of Keras, epochs is nb_epoch).</p><p>During gameplay, the enemies each evaluate this NN every frame to determine whether they should be shooting at the player, again with only a single line of code:</p><pre>self.brain.keras.predict(np.array([list((dx,dy,du,dv))]))&gt;=0.5</pre><p>What you can see here is that if the final neuron outputs &gt;= 0.5, then the enemy will fire. You can also see we’re passing through the current relative position (dx,dy) and velocity (du,dv) as the input data for the brain to predict.</p><h3>Lessons Learned</h3><p>Generally speaking there were a few key lessons that I learned while putting together this demo:</p><ul><li><strong>Choosing the right data to train your network is important.</strong> There was a tonne of available data to choose from, but selecting the right set of physically accurate data was important to build a usable network. Thanks to our VP of Engineering Tom Radcliffe, who is an ML expert, he provided excellent guidance on the right kind of training data to use.</li><li><strong>“Prepping” your data is key.</strong> Normalize your input data! It isn’t strictly necessary, but it also isn’t likely to cause problems, and is cheap and easy to do. You should also get comfortable with NumPy and the proper way to format matrices so that Keras knows how to interpret the data you throw at it.</li><li><strong>Experiment with network topology.</strong> At first I was hesitant to mess with the layout of the network, and it felt strange to use trial and error to come up with a solution, but the more I learn about this space, the more I realize that this is an important part of the process.</li><li><strong>Visualization is important.</strong> Before I had the visualization implemented, I found it very difficult to debug and reason about what was happening with my NN. Even though there were many options available for visualization, the home-grown visualization that I cobbled together made sense to me and helped me immensely with identifying the behaviour of the network.</li></ul><p>It’s remarkable how consistent the behaviour of this simple network is, and even though there are a number of obvious improvements and additions that could be made to this, it nevertheless demonstrates the power of machine learning…and that it is now super accessible to anyone.</p><p>Moving forward I’ll look to make a few tweaks and improvements to this network. Ultimately I would like to push this to GitHub as I had a number of requests at PyCon to do so and would love to see others learn from this project.</p><p>If you want to ask questions about this project, feel free to hit me up on Twitter <a href="https://twitter.com/rawktron">@rawktron</a>.</p><p>Try out the new machine learning packages pre-bundled in ActivePython. <a href="https://www.activestate.com/activepython/downloads">Download ActivePython</a> Community Edition and get started in development for free.</p><p><em>Originally published at </em><a href="https://www.activestate.com/blog/2017/05/building-game-ai-using-machine-learning-working-tensorflow-keras-and-intel-mkl-python"><em>www.activestate.com</em></a><em> on May 25, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ea5482bb26" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>