<?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 Ryan Ghaida on Medium]]></title>
        <description><![CDATA[Stories by Ryan Ghaida on Medium]]></description>
        <link>https://medium.com/@ryaboug?source=rss-31f03d9a5d0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yzgInI53pHZtmJNJ.</url>
            <title>Stories by Ryan Ghaida on Medium</title>
            <link>https://medium.com/@ryaboug?source=rss-31f03d9a5d0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:54:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ryaboug/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[2D Projectile Motion using Canvas and JS]]></title>
            <link>https://medium.com/@ryaboug/2d-projectile-motion-using-canvas-and-js-41f77e971a07?source=rss-31f03d9a5d0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/41f77e971a07</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ryan Ghaida]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 00:56:26 GMT</pubDate>
            <atom:updated>2018-07-19T13:58:30.960Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog is designed to show how one can begin to set-up the necessary conditions to render projectile motion using Canvas and JavaScript. The example I will be referencing is from a cool 2-D Archery repo I found online while researching the topic; repo <a href="https://github.com/rgliever/ArcheryCanvasGame">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wI9xew1cy0qqfQ2OhSO2JQ.png" /><figcaption>End goal</figcaption></figure><p>This blog post will be mostly example-driven and practical, for more information on Canvas please refer to the MDN documentation <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial">here</a>.</p><p>Okay! So first-off we need to actually create the canvas before we can start doing any drawing or rendering. Fortunately, this is quite easy. Assuming you have a blank .js file and a basic index.html file to go along with it we can start. First, we want to write the following code at the very top:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*ksjUkLLIDvQGdhJ0-oJJxg.png" /></figure><p>This will give us our actual canvas, albeit being blank for now.</p><p>Next, lets go ahead and add that sky and ground in the background. To do so we just need to specify where we want the ground and sky to be. Since were dealing with projectile motion lets go ahead and add a gravity value that we will be needing later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*YZ2r5xly1mOQlAtnMn8Ccw.png" /></figure><p>Now we can begin to fill-in our setting!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*X36QDNINmZmng82wYSCXSw.png" /></figure><p>So there is a few terms here that may seem a bit unfamiliar:</p><ul><li>fillStyle: specifies the color or style to use inside shapes</li><li>fillRect(): draws a filled rectangle whose starting point is at the coordinates <em>(</em><em>x, </em><em>y)</em> with the specified widthand height and whose style is determined by the fillStyle attribute.</li><li>beginPath(): used when one wants to start a new path, in our case the ground; also clears all previous sub-paths.</li><li>moveTo(): moves the starting point of a new sub-path to the (x, y) coordinates specified.</li><li>lineTo():connects the last point in the sub-path to the x, y coordinates with a straight line (but does not actually draw it).</li><li>stroke(): draws the last specified line with a specified strokeStyle</li></ul><p>Now that we have our background its time to render our aiming circle for our bow and arrow.</p><p>Lets start by drawing our circles. We’ll need one smaller circle nested within a larger one to give the User somewhere to click to initiate the drawing of the arrow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*crKWiKiEsr-4GyG11zpunQ.png" /></figure><p>Great, this should work and now we can to get into the hardest part of our endeavour: the kinematics.</p><p>In order to accomplish what we want were going to need to listen for certain events and have something resembling ‘state’ to go along with it.</p><p>For example, we need to know when the User clicks within the innermost circle and drags out and then releases, thus creating a trajectory that we will calculate. We want the user to be able to aim the arrow and adjust both trajectory and power. The User should be able to do something like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*6jYnjsd5psTQKCGo1kUvtQ.gif" /></figure><p>Lets start with our EventListeners:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*l_eNIJ01KJCIo8SOY96k5A.png" /></figure><p>Since this is vanilla JS and not React, we can simulate state by setting boolean values. The rest of this should be simple to understand if you are familiar with JS, but there is a function we need to define for everything to come together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*6ztyg_3LbbkXGansthgJUQ.png" /></figure><p>Now we have a function that can grab the location of the Users mouse curser and we can move on to the next part, calculating trajectory. In order to do this we’ll need a few helper functions.</p><p>In order to calculate trajectory of a projectile in our given scenario, we’ll need a few things:</p><ul><li>distance between two point: to gauge power</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*2VQp2i9qzhYX-lIGHMzTKw.png" /></figure><ul><li>angle between clickDown event and clickUp event: to generate angle for hyperbolic curve</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*UWJe6P0zPAeRN9qVy4LhJQ.png" /></figure><p>Then we can bring the information from these two function together to create the Arc for the arrow to travel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*2aG3kFQLwbCMMfqLrSWmgw.png" /></figure><p>The last step is setting up some functions to track whether the arrow is being drawn or not and whether the User is clicking within the circles:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*geBVkMxR7xMQ1jizdRUMCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*1jARqoYjdnJ-X_lx4FFAsA.png" /></figure><p>Now, if you refer back to the GIF you can see that when a User draws back on the arrow there is a line that is generated to help them gauge where the arrow is going to go and how powerful the shot will be. This comes down to utlizing the information we already have and drawing a line to represent it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*JLc8-tjlbjcUAlMGWphpkA.png" /></figure><p>Perfect. The function checks to see firstly if the arrow is being drawn or not and then to see where the Users mouse position is thanks to our getAimCoords function.</p><p>Next, since this is Vanilla JS we’ll need someway of rendering and updating the scene so we can create a dynamic feel to the for the projectile motion.</p><p>Were going to need three things: update, render and requestAnimationFrame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*VWVVX76oEJREd-depwQhDA.png" /></figure><p>The Main function tells the program to first update the canvas to check whether the arrow is drawn back or fired, if it is fired then change state back to false to prepare for the next arrow.</p><p>Then render the circles for the User again along with the scene and lastly requestAnimationFrame:</p><ul><li>requestAnimationFrame: You should call this method whenever you’re ready to update your animation onscreen. This will request that your animation function be called before the browser performs the next repaint. The number of callbacks is usually 60 times per second.</li></ul><p>With this we can build the scaffolding necessary for creating and rendering projectile motion in Canvas, the steps left would be to create an Arrow prototype and have this render each time an arrow is fired. Although this is out of scope for this blog, I might tackle it in an upcoming edition! Thank you for reading, I hope you learned something and if you would like to see the fully-functional code referenced here please visit the creators repo linked at the top!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41f77e971a07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Networks | Deep Learning : Teaching a Computer to Read]]></title>
            <link>https://medium.com/@ryaboug/neural-networks-deep-learning-teaching-a-computer-to-read-3e856e2d4a50?source=rss-31f03d9a5d0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e856e2d4a50</guid>
            <category><![CDATA[text-recognition]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ryan Ghaida]]></dc:creator>
            <pubDate>Wed, 20 Jun 2018 17:03:45 GMT</pubDate>
            <atom:updated>2018-06-20T18:46:19.060Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jj6AsSP9c9hZiuASYic7Eg.jpeg" /><figcaption>Source: <a href="https://cdn-images-1.medium.com/max/1500/1*m2gDBT_nc-iE7R4AM3sHBQ.jpeg">https://cdn-images-1.medium.com/max/1500/1*m2gDBT_nc-iE7R4AM3sHBQ.jpeg</a></figcaption></figure><p><em>A majority of this blog is based off a youtube channel series created by 3Blue1Brown —most pictures are taken from his series and all credit goes to the hard work and research done by the creator and his team in developing the original series.</em></p><p>This blog post is intended to instill understanding, excitement and hopefully some confidence on a topic far too often deemed as ‘out of reach’ for those of us without advanced degrees in math and programming.</p><p>Let’s kick things off with a simple request:</p><h3><strong>What would it take to teach a computer how to recognize hand-written digits ?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*qn32L-gidgb9W_izql6NBw.png" /><figcaption>Deceptively easy for human brains to decipher!</figcaption></figure><p>The mental heavy-lifting our brains do just to read a simple string of numbers is mind boggling; 100 <em>billion </em>neurons, all inter-connected, all firing and all happening without you even being aware of it.</p><p>In order to begin to appreciate the magic in the mundane were going to need to break down these complex processes into models and their simplest possible derivatives to even have a chance at understanding. Where do we start?</p><p>Like most advances in human civilization we often look to Nature to inspire and guide us. Let us first think about what our brains are <em>actually</em> able to do when presented with a hand-written number.</p><p>Take a crudely rendered ‘3’ that is 28 x 28 pixels wide:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*nojdQynTFPIU1ymt8WYQUg.png" /></figure><p>This is pretty obviously a ‘3’ and we even a child would have no problem with such an assessment. But what about these examples?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/143/1*fdLpBOYn5lJDTwUxFgc5cw.png" /></figure><p>Besides the ugly-duckling in the first slot, most of these are pretty straight-forward as well, from a human’s perspective. Yet, if we were to think about it from a computers vantage point, the associated pixels are drastically different when compared to the initial ‘3’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/148/1*Lp_p_30ncWc7Y2l3l1-2Og.png" /><figcaption>How can we make this work?</figcaption></figure><p>Let us revisit our initial request one more time and be more analytical:</p><h3><strong>“How can we write a program that takes in a 28 x 28 grid of pixels and returns to us a number 0 through 9? “</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*g7B0htVXSFt6abulIgmUww.png" /><figcaption>How can we learn the ‘shape’ of a 3 ?</figcaption></figure><p>Suddenly, we have a seemingly daunting task ahead of us. However, we <em>also</em> have some very powerful tools at our disposal: Neural Networks and Calculus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*MINb-ejYCab5RKkhqAplDA.gif" /><figcaption>Your brain deciding what to have for lunch, simplified.</figcaption></figure><p>Were going to stick with the most basic ‘vanilla’ model of a Neural Network to help us get a good understanding of new concepts here and the calculus we end up touching upon will be supplemented with great visual aids — again, credit to 3Blue1Brown — to help make our ascent to understanding as smooth as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*EnUshxtMsqcqrPW3np8LaQ.png" /><figcaption>Neural Networks were inspired by the same structure our brains utilize.</figcaption></figure><p>Before getting into the architecture of this Neural Network, we need to quickly go over some important steps.</p><h4>What is a Neuron , pragmatically speaking?</h4><p>For our purposes here, think of a Neuron as something that holds a value from 0 to 1; 0 being “no stimulus” and 1 being “maximally stimulated” ; these values are called a neuron’s “Activation” — not dissimilar to the real thing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*p25aTB_gv-4hOj-ZJRYD-g.png" /></figure><p>Here we can see that each pixel in our grid has a corresponding neuron “activation” that represents a grey scale value.</p><p>Each of these 784 Neurons make the first “layer” of our network!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*40F_iwmQWIGMRBNthN7CGQ.png" /><figcaption>First layer of our “Plain vanilla” model</figcaption></figure><p>Skipping over the middle -which we’ll get to in just a moment- the last layer of our network is simply the 10 numbers we’re trying to predict and the associated “Activation” of each of <em>those</em> Neurons is how much our model ‘thinks’ that value corresponds to our image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*pKYtO3t2i_vYXq1MjtmXXw.png" /><figcaption>97% sure thats a 9.</figcaption></figure><p>So now we have some understanding of where the first and last layers are coming from <em>and </em>what the values of each Neuron correspond to.</p><p>What about the middle layers? These are commonly referred to as the “Hidden layers” and can be range in size, complexity and order based on what exactly we want our Neural Network to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*7xjVKxGv6sIiGsKgW_vK1w.png" /><figcaption>The ‘heart’ of the Neural Network</figcaption></figure><p>There is a lot of flexibility and room for experimentation when it comes to designing this aspect of a Neural Network. Before we jump into this, it would be helpful to think again think about how our own Neurons work in our brains.</p><p>Plainly speaking, activation of some many Neurons prior, influences and thereby activates subsequent Neurons of the next layer. Conventionally, the number of Neurons in coming layers <em>decreases</em>; this is how we can start with 784 inputs and funnel it down to just 10. This process will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*RK3IIZJNrvbW0BLXmr8Wfw.png" /><figcaption>The specific pattern of activation from the input layer causes a specific pattern in the next layer.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*9r6oD45fMd8JuSYH8soIQA.png" /><figcaption>Likewise, from one layer to the next.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*yIDX3boCBE6vw6IlF-eanA.png" /><figcaption>The Neuron with the highest value in our final pattern on the last layer is what our system’s ‘guess’</figcaption></figure><p>But how exactly does this work? Why even have layers to begin with? What do we think they’re even doing?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*OsfqkTPoZogSElCAqxAC0A.png" /><figcaption>Note: having 16 Neurons and 2 Layers is mostly arbitrary, many other arrangements are possible!</figcaption></figure><p>In order to better understand this let us start by contemplating about how we think. When we see something like a ‘9’, what do we see? An ‘8’? What about a ‘4’?</p><p>Well, if we had to break it up in our own words we might say: theres a circle on top and a sort of line sticking out the bottom for the 9. 8 looks like two circles and 4 sort of like three sticks, intersecting.</p><p>By extension, maybe our first layer is just for edge-detection or for very small lines that make up all sorts of more aggregate shapes like the long lines and circles mentioned above.</p><p>Could our layers be doing something like this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*udjtFFf21wg0XqV-Ob-BoQ.png" /><figcaption>Layer 1 Prediction: Edge Detection.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*vuvJw95DHYRmqfNyzRuXig.png" /><figcaption>Layer 2 Prediction: More aggregate structures?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*ChtxYhrYhWIcU7F-1eanAA.png" /><figcaption>Is this how our system is working?</figcaption></figure><p>In actuality the ‘magic’ of these Neural Networks is <em>in </em>the hidden layers, and because of this the actual way they organize themselves to learn the things we ask them to is largely unpredictable and unlike how we might intuit.</p><p>The process described above may make sense to us, but the networks in us have had the luxury of millions and millions of years of evolution that was intimately linked to our ability to perform pattern recognition. By contrast, our Neural Network here has yet to log a few minutes of runtime let alone be active long enough to eventually realize its own existence — God help it(or us) when it does.</p><p>Although, this may not end up being the way our system works there is a certain wisdom in aspiring for it to try to. What we described above is mainly edge-detection, and this is imperative in almost all visual detection software. Edges are immensely useful in such applications, and usually a first step.</p><p>Lets take a specific example of what we might want <em>one </em>of our Neurons in the second layer to look for.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*8PO6rbtYbCFwG-Yfb_AdRw.png" /><figcaption>Maybe this could be for detecting 7’s, 3’s, 8’s,9’s and 0 ?</figcaption></figure><p>Lets say we want this Neuron to assess whether or not the image has an edge in this <em>specific </em>layer. This question evolves into what parameters should the network have to do this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*0WGMxP9kLdg2UHDTy6Ut5g.png" /><figcaption>These are the grey scale values of the First Layer.</figcaption></figure><p>Think of this as: what sort of added effect can we create to best detect an edge in that region? Imagine a Neurons Activation is very high but this pixel is somewhere outside the zone we are currently looking for, we would assign a heavy <em>negative</em> <em>weight</em> to negate this value, since it’s not relevant to our current parameters for this specific Neuron.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*fq6BGV3eO7QaXD66IxS_Cw.png" /><figcaption>In this case w5 is giving us a high value but maybe its not an important Neuron; we need to negate its effect on our system.</figcaption></figure><p>Summing all the values of the first image with all the weights of the second we get something that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*r2ZFae7hyBafy39IFHU36A.png" /><figcaption>Warning: Calculus incoming.</figcaption></figure><p>Next, lets represent the newly computed sums of each of these values as a color on a grid; green being positive, and red negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*Y_UsixmtGLEAjaftVp-Umg.png" /><figcaption>That’s a lot of noise, we’re only interested in the small section on the right.</figcaption></figure><p>Now, if we take all the weighted sums of almost all the pixels to be zero <em>except </em>for the positive weights in area that we are interested in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*iJUn9yAy9d7xmeq8Essk8Q.png" /><figcaption>This Neurons only job is to get really good at detecting long, top edges. Thus, all weights are set equal to 0, except for the area were interested in.</figcaption></figure><p>Next, to better aid in edge detection we could have some negative weights associated with the surrounding pixels. Then the sum is largest when the inner pixels are bright <em>and</em> the surrounding pixels are darker. As opposed to <em>just </em>having bright inner pixels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*mVESoM8oUWwkUi7iIPpMwg.png" /><figcaption>An example 7, our Neuron should fire for this!</figcaption></figure><p>Now, we simply calculate the weighted sum of all these values. This value could be any number but we want our values to be confined to values ranging from zero to one. In order to do this we’ll need to find a function that approaches zero very quickly for negative values and approaches 1 for larger positive numbers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*Vzoc99v2bvUF9Rjeyjxd2g.png" /><figcaption>This sum can be any number on the real number line.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*gl0uO8PE48qdk32iYSDDvg.png" /><figcaption>We need a function that will help us map the real number line to values between 0 and 1.</figcaption></figure><p>Luckily, there are several such functions that exist. One of which is called the Sigmoid function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*Mi7Kz0t34ai0WZYpvPsaVQ.png" /><figcaption>Negative numbers approach 0, Positive numbers approach 1 and numbers between 0 and 1 steadily increase.</figcaption></figure><p>Now we simply map our resulted sum through our Sigmoid function to receive a number that is valid for our Neuron — between 0 and 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*rxhLr4KupG3lSHVr_0xlwA.png" /><figcaption>What if we only want this to be Activated when we’re fairly certain there is an edge and not just for any positive number?</figcaption></figure><p>In order to increase selectivity and reduce false positives we can introduce a Bias and add this to our function to act as a penalty for inactivity. Meaning, only values that exceed this threshold will register as positive and thus lead to activation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*H6_EHxZ4zQd-HHQAOiNHmw.png" /><figcaption>Even computers are bias. Note: all Neurons receive a bias of some sort.</figcaption></figure><p>The bias tells the system how high the weighted sum needs to be before the Neuron becomes meaningfully active. Note, the bias is in effect <em>prior </em>to the Sigmoid function’s ‘squishification’.</p><p>Now lets zoom out briefly and recount that this is simply <em>one </em>Neuron; there are processes like this happening for <em>all</em> our Neurons in the hidden layers. One can begin to imagine how powerful more complicated versions of these systems can become, especially when given time to learn from copious amounts of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*Cwq14qLq19salzFs15m-JQ.png" /><figcaption>More than 13,000 knobs and dials that need to be fine-tuned for the task at hand.</figcaption></figure><p>Now that we have a slightly better grasp of just how a Neural Network can learn, lets familiarize ourselves with the common notation, the same we might expect to see if we chose to read up on the topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*6Jq2Q6QfsEuG4WpfSQa_ng.png" /><figcaption>This has an effect of multiplying all the final matrix values.</figcaption></figure><p>Firstly, lets take all the weights leading up to one single Neuron and multiply that by that Neurons respective value and finish off by adding a bias. This step is done for <em>every </em>Neuron. Conveniently, this can be represented by the matrix multiplication above. Moreover, this further reduces into a simple equation as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*4gtGzBdp3YvCUhlACkvoiA.png" /><figcaption>Much easier to read! How would this look in code?</figcaption></figure><p>How would we represent something like this in code? The language below is Python which is known to optimize matrix multiplication immensely, greatly aiding in creating and refining such systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*6n98jRKt6JKHbYhLXb-pnQ.png" /><figcaption>Can you get a grasp for what the above code is saying?</figcaption></figure><p>There are many more things I would like to cover but can’t encompass in this short blog post: how does the system learn? what are some shortcomings of such systems? How accurate can these systems become? etc.</p><p>The topic of Machine Learning and AI is vast and ever expanding. Some believe it will be the last frontier and our inevitable demise. Others believe its the only way of protecting us and this earth from ourselves. Regardless of your ideological position, the fact remains clear: this technology will impact the lives of every single human, not only today and in our lifetimes, but <em>forever</em> into the future. It falls on the shoulders of the pioneers exploring this new territory to anticipate, gauge and respect the unfamiliar terrain.</p><p>Fortunately for us up and coming programmers, unlike professions such as medicine or law, we don’t need fancy degrees to hope to be part of such an adventure, we need only a process of learning, not dissimilar to the one we are forging here at Flatiron. I hope this blog instills some confidence in your ability to understand the topic of Machine Learning. I <em>highly </em>recommend the YouTube series: 3Blue1Brown, but there are many resources for free on the topic online. Thank you for your time!</p><p>P.s.</p><p>The actual middle layers look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*niJL1lORqi0-eg89QlTXog.png" /><figcaption>What are some weird things this might lead to?</figcaption></figure><p>This probably doesn’t make much sense to us, and it shouldn’t. Unlike most synthetic designs, when it comes to machine learning we are merely the initialization of the thing; the beauty only comes after the system has been left alone and we revert to being observers.</p><p>Also, some weird behaviour:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*ROIh1VQZvHkobic69CQM3w.png" /><figcaption>If our system was ‘smart’ it wouldn’t really be sure what this is, since it doesn’t resemble a number.</figcaption></figure><p>We would expect our system to maybe have equally random values for 0–9 since the image we passed in doesn’t resemble any number whatsoever.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*LyYLRcpQDy8Oh-Zkoticpg.png" /><figcaption>-_-</figcaption></figure><p>Yet, our system is <em>confident</em> that that jumbled assortment of pixels is a “5”. Clearly, we have a little more coding to do.</p><p>Resources:</p><p>3Blue1Brown- <a href="https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw">https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw</a></p><p><a href="http://pages.cs.wisc.edu/~bolo/shipyard/neural/local.html">A Basic Introduction To Neural Networks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e856e2d4a50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Cool Methods for Your Ever-Expanding Ruby Toolbox]]></title>
            <link>https://medium.com/@ryaboug/3-cool-methods-for-your-ever-expanding-ruby-toolbox-2d74871a3054?source=rss-31f03d9a5d0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d74871a3054</guid>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Ryan Ghaida]]></dc:creator>
            <pubDate>Thu, 10 May 2018 16:41:23 GMT</pubDate>
            <atom:updated>2018-05-10T16:41:25.844Z</atom:updated>
            <content:encoded><![CDATA[<p>As an aspiring Software Engineer it has become increasingly evident that there are many, <em>many</em> tools to be acquired and added to our array - or hash, depending on …never mind. Since most humans are averse to discomfort and tend to aggregate towards what they feel most familiar with, it is easy to end up relying on common methods and waiting for more difficult challenges to <em>force </em>us to adapt and learn other, more esoteric tools for problem solving; especially while first starting our expedition into the seemingly-ominous forest of coding.</p><p>And while it may feel like this at first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*TXYbduN14oIIeraZ.gif" /><figcaption>Week 1: Software Engineering Bootcamp</figcaption></figure><p>As we learn, adapt and grow both individually and together. We begin to familiarize ourselves with the terrain and traverse the seemingly infinite unknown with increasing confidence; even with a feeling of adventure and yearning at times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/0*1cXy4tnHVEy9xgYp.gif" /><figcaption>Week 3: After hacking our first API</figcaption></figure><p>While I can relate to this yearning for comfort, especially while I attend this Software Engineering Immersive Bootcamp -now thats a scary string of words- at Flatiron School, I feel that we ought to develop a habit early on in our careers to not be like the many and rely on life’s external circumstance to force our hand, but rather to take some<em> personal initiative</em> to expand our own horizons, regardless of how challenged we feel in the moment. Future you and all peoples you have future dealings with will thank you greatly.</p><p>So let us begin with just a few Ruby methods that I found while googling around this week, in no particular order.</p><h3>1. The #tap Method</h3><p>This is a useful method for when you want to create an object, manipulate or call some methods on said object and eventually want to return that same object at the very end to use again.</p><p>For example, conventionally:</p><pre>Honda = Motorcycle.new<br>Honda.name = &quot;Honda Vroom Vroom&quot;</pre><p>The person lucky enough to be reading our beautiful code would have to read all three lines before realizing we are just creating an instance of some class called Motorcycle.</p><p>With Tap this is clear in the very first line :</p><pre>Honda = Motorcylce.new.tap {|bike| bike.name = &quot;Honda Vroom Vroom&quot;}</pre><p>Although this may seem like “more work” its actually more concise for an experienced programmer to read.</p><p>Another useful usage would be when assigning a single attribute and returning the new object.</p><p>Conventionally:</p><pre>object <strong>=</strong> SomeClass.<strong>new</strong><br>object.<strong>key</strong> <strong>=</strong> &#39;value&#39;<br>object</pre><p>After we Tap dat... method:</p><pre>obj <strong>=</strong> SomeClass.<strong>new</strong>.<strong>tap</strong> { <strong>|</strong>obj<strong>|</strong> obj.<strong>key</strong> <strong>=</strong> &#39;value&#39; }</pre><p>This returns the object we just created as desired but without having to write superfluous code.</p><p>Lastly, this is useful when wanting to call a single method on an object and keep working with the object afterwards:</p><p>Traditional :<br>object <strong>=</strong> Model.<strong>new</strong><br>object.<strong>save!</strong><br>object</p><p>Tapped: <br>object <strong>=</strong> Model.<strong>new</strong>.<strong>tap</strong> <strong>do</strong> <strong>|</strong>model<strong>|</strong><br> model.<strong>save!</strong><br><strong>end</strong></p><p>Condensed :<br>object <strong>=</strong> Model.<strong>new</strong>.<strong>tap</strong>(<strong>&amp;</strong>:save!)</p><h3>2. The ||= operator</h3><p>I remember when I first learned how to use this operator and taught it to a friend, they were blown away by the eloquence of what it did, as was I. I think it was the first time I began to understand just how much better, better code could be and the lines of explicit code it could save.</p><p>This is <em>extremely </em>useful for populating a Hash with keys and values when the keys might be the same for multiple values.</p><p>For example, lets say we want to create a hash with keys of “Grade” and values of “Students”. Many students could be in the same grade. First, lets see how a poor old soul would think of going about this without our cool trick, and the trouble they could face in attempting to solve this problem while still new to coding.</p><p>Assuming we have some structure like:</p><pre>class School</pre><pre>  attr_accessor :roster<br>  attr_reader :school_name <br>  <br>  def initialize(school_name)<br>    <a href="http://twitter.com/school_name">@school_name</a> = school_name <br>    <a href="http://twitter.com/roster">@roster</a> = {} <br>  end <br>  <br>end</pre><pre>school = School.new(&quot;Rutgers&quot;)<br>  =&gt; #&lt;School:0x0000560191950e28 <a href="http://twitter.com/school_name">@school_name</a>=&quot;Rutgers&quot;, <a href="http://twitter.com/roster">@roster</a>={}&gt;<br>  </pre><p>And try to add two students to the roster.</p><pre>def add_student(name, grade)</pre><pre><a href="http://twitter.com/roster">@roster</a>[grade] = []<br><a href="http://twitter.com/roster">@roster</a>[grade] &lt;&lt; name<br> <br>end</pre><pre>add_students(&quot;Ryan&quot;, 12)<br>add_students(&quot;Ghinwah&quot;, 12)</pre><p>Now when we check to see if we have both students added we see that, sadly, Ryan never made it.</p><pre>roster <br>  =&gt; {12=&gt;[&quot;Ghinwah&quot;]}</pre><p>It seems that we are actually re-creating an empty array every time we call the add_students method.</p><p>We need a way of<em> first </em>checking if a value already exists for a certain key namely, grade 12.</p><p>Then, if it is already populated, we simply want to push the new value to that same key.</p><p>Instead of going through a series of if and else statements , let’s see our new tool at work.</p><pre>def add_student(name, grade)</pre><pre><a href="http://twitter.com/roster">@roster</a>[grade] ||= []<br><a href="http://twitter.com/roster">@roster</a>[grade] &lt;&lt; name</pre><pre>end</pre><p>Here the ||= accomplishes this for us. The ||= executes only when the left assignment returns falsey i.e. nil or false.</p><p>Meaning if <a href="http://twitter.com/roster">@roster</a>[grade] doesn’t exist yet, this will give back a nil value thus, telling our ||= to execute and go ahead and set up our key value structure i.e. *hash[key] = “value”*</p><p>But, incase the <a href="http://twitter.com/roster">@roster</a>[grade] <em>does</em> exist like in our above example with grade 12 already being populated after the first student is added the left assignment will be truthy and ||= will not execute on that line. This leaves only the next line which simply shovels in our new name value.</p><p>This gives us our desired output.</p><pre>roster<br>=&gt; {12=&gt;[&quot;Ryan&quot;, &quot;Ghinwah&quot;]}</pre><h3>3. Array #reject</h3><p>Rejection isn’t a fun topic for most people and it’s not even fun when it comes to coding but, like your breakups, it can be useful going forward if we take the time to learn.</p><p>Reject is the opposite of the more familiar #select method; instead of selecting exactly what we want, sometimes it’s easier to simply cut out what we don’t want and leave what we do, kind of like your shallow dating app filters.</p><p>The return value is an array with all values that pass your shallow filters.</p><p>For example:</p><pre>first_job_salaries = [60000, 55000, 75000, 120000, 250000] </pre><pre>first_job_salaries.reject {|pay| pay &lt; 1000000} </pre><pre># =&gt; [120000,250000] </pre><p>This returns only the jobs we should consider as new programmers with a few months experience, namely the ones that pay 6 figures.</p><p>All joking aside, as with any new skill that we attempt to gain mastery in, progress is slow and arduous but we should remind ourselves that it is also inevitable when we remain steadfast on the path.</p><p>I hope some of these tools are new to those reading this and if not, hopefully you at least enjoyed the read!</p><p>“A step towards what you fear is a mile towards mastering it.” <br>― <a href="https://www.goodreads.com/author/show/7978664.Matshona_Dhliwayo"><strong>Matshona Dhliwayo</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d74871a3054" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>