<?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 Meher Ranjan on Medium]]></title>
        <description><![CDATA[Stories by Meher Ranjan on Medium]]></description>
        <link>https://medium.com/@meherranjan?source=rss-d91b30350860------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bbdtis18Uqg6jzC8L12zRA@2x.jpeg</url>
            <title>Stories by Meher Ranjan on Medium</title>
            <link>https://medium.com/@meherranjan?source=rss-d91b30350860------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 15 May 2026 16:10:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meherranjan/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[Neural Network in JavaScript — Part 1]]></title>
            <link>https://medium.com/@meherranjan/neural-network-in-javascript-part-1-d86328048017?source=rss-d91b30350860------2</link>
            <guid isPermaLink="false">https://medium.com/p/d86328048017</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Meher Ranjan]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 05:17:34 GMT</pubDate>
            <atom:updated>2019-03-30T04:17:31.630Z</atom:updated>
            <content:encoded><![CDATA[<h3>Neural Network in JavaScript — Part 1</h3><h4>A gentle introduction to a neural network. Starting with the essential, thought experiment.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3BtJTlHKnx3152UKoTgYg.jpeg" /><figcaption>Neuron by <a href="https://unsplash.com/@halgatewood">@halgatewood</a> on Unsplash</figcaption></figure><p>A Neuron or Perceptron is a simplified mathematical model of a biological neuron. The perceptron algorithm was invented in 1957 at the <a href="https://en.wikipedia.org/wiki/Cornell_Aeronautical_Laboratory">Cornell Aeronautical Laboratory</a> by <a href="https://en.wikipedia.org/wiki/Frank_Rosenblatt">Frank Rosenblatt</a>. Initially and strangely it was intended to be a machine, rather than a program. It was reckoned to be used for image recognition.</p><p>We have myriads of libraries in our toolkit, some popular ones like TensorFlow — SciKit, that we practically would never want to worry about how the fundamental unit of a neural network works.</p><p>Nevertheless, for me, it has always been imperative to learn how the inner functioning of a system works. Or simply, how does any system work. Whether or not I can build the system is another story. Knowing how several elements of a system interact with each other, how a simple data as input comes out as a fine prediction without any hard-coded logic. Self-driven. How does a neural network do that and what does a single neuron contribute to the network? These were some questions that kept me curious for a long time.</p><p>It turns out that a neuron isn’t as complex as we imagine it to be. And it isn’t that straightforward and simple either. 😁</p><blockquote>So now is the time we grab a cup of coffee. ☕️</blockquote><p>We will start with a simple game and down the line, slightly far ahead, we will wrestle our way out of calculus(next part of the series). But believe me, it wouldn’t be so daunting as it sounds. And I really hope by the end of the post, you will feel more inquisitive and enthusiastic about machine learning rather than believing it to be a mind-bending piece of a subject. Let’s start…</p><h3>Enter Game — Hi-Lo</h3><p>The aim of the game is to <strong>improve our guess</strong> and end up with an accurate score. Simple enough! Also, I know the answer and at every guess, I will let you know if your guess is low or high.</p><p>Let’s say I ask you how many kilograms make a pound? I am sure you know the answer already.</p><p>For a moment, let’s forget that we know the magical figure and act like we are 5. So what’s your guess? 1.8? <strong>Okay.. we have to start somewhere and 1.8 is good enough start.</strong></p><p>Okay, before proceeding, we should also remind ourselves that the relationship between <em>kilogram </em>and <em>pounds</em> is linear. That means if we double the <em>kilogram</em> or half it, the same effect is proportional in <em>pounds</em>. And, can we agree upon a relationship, which can be expressed as…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AIsHdZ4NjCYqU2gNPIw4CA.jpeg" /></figure><p>Now, at this moment we know what M is! That’s right, it’s your guess! Let plug the value of M= 1.8 and let’s find out how many pounds is 80 kg.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2EsjPlbFZGv7kd6J5EMWqg.jpeg" /></figure><p>Great! Now, I pull my card out and it says <strong>Low. </strong>Time to bump the guess.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJidqz4wAJT6zAwqnUcJxg.jpeg" /></figure><p>Awesome! Now, I pull my card out again and it’s <strong>Low. </strong>Time to refine further…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2BVLeoZtvdeeaA5wqIdIsA.jpeg" /></figure><p>Fantastic! But this time the guess is <strong>High.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGvvk2xQ0KvqBm8sF_oEIw.jpeg" /></figure><p>Bravo! 2.2 is a pretty reasonable guess. And this process can be replicated for the decimal part for accuracy. But for now, let us focus on the essence of prediction and correction.</p><p>If you followed closely, we updated our <strong><em>guess(M)</em></strong> at every step. We were making a judgment to either, increase/decrease a certain value of/from <strong><em>M</em></strong>, based on whether our guess was low or high.</p><p>Is there a way we can represent this mathematically? And more importantly, what can we do with the <strong>error</strong><em>(the difference in the actual output and the prediction) </em>in prediction to improve our <strong>guess(M)</strong>. Let us see how can we correlate <strong><em>error</em></strong> and <strong>guess</strong>?</p><h3>The Equation of a Line</h3><p>Let’s visualize our relationship for <em>lbs &amp; kg</em> in a generic way. It can be expressed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S-mA6jtLrKoYlEHyCIhqfw.jpeg" /></figure><p>Can you make a guess what is the significance of this equation? It is an equation of a line. You can see below the graph of this equation when <strong>m is 2.2. The line coincides at 0,0 which is good and at 10lbs the value for kg is 4.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WHc_BPbUDuHVNYJSMdji2g.jpeg" /></figure><p>However, the complete equation of line involves an additional term which is denoted by letter <strong>b</strong>, the y-intercept of the line. The updated equation becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cc3kxjebsEm638K5U5jSNg.jpeg" /></figure><p>Our earlier equation was simpler because when kilogram is 0 even the pounds is 0.</p><p>An example where we can consume “<strong>b”</strong> is with the relationship between Celsius-Fahrenheit because, at 0<strong>° </strong>C, Fahrenheit is 32<strong>°</strong>. So even when the product of <strong>m * x</strong> is <strong>0</strong>, y-term has a value of 32.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e1SgUkyN-bPiQycc7bBG7w.jpeg" /></figure><p>The following graph can give a good picture of what the b term signifies. You can see that X and Y do not coincide at 0, which is because of the addition of b. You also notice that at roughly 32<strong>° </strong>F, Celsius is 0, which is about right and at 41<strong>° </strong>F, Celsius is 5. So I hope b-term is slightly clear now.</p><p>We will soon utilize the equation of a line in the next part of this series. For now, let’s take a step back.</p><h3>Mathematizing Hi-Lo</h3><p>Our guesses were logical &amp; smart. But how could we formulate a process? Before we move further let’s just come on the same page with the following terminology:</p><ul><li><strong>Target</strong> is the actual answer/value</li><li><strong>Prediction</strong> is what the guess was</li><li><strong>The Error</strong> is the difference between Target &amp; Prediction.</li></ul><p><strong><em>We also need a name for the value that we either added or removed at every step. </em></strong><em>Delta is also used commonly to denote change</em><strong><em>. </em></strong><em>Let’s call it Δ</em><strong><em>m. </em></strong>So now our equation for finding our target value becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9HqEIPuThhzMx13ab8_WKw.jpeg" /></figure><p>In every step, we either increased or decreased the value of <strong>m. Which implies that these 2 entities must be combined together. Hence, we add</strong> <strong>Δm</strong> and <strong>m</strong>. When <strong>Δm</strong> is negative the total value of the equation would reduce and when <strong>Δm</strong> is positive it would increase. So our initial equation started with just m, with the next step it changed to <strong>m</strong> + <strong>Δm</strong>. Moving on…</p><h3>In our case…</h3><h4>What is Target?</h4><p>› For the right value of <strong>∆m</strong>, <strong>(m + ∆m) * x</strong>, should give us the correct value.</p><h4>What is Guess?</h4><p>› We knew this from our initial steps and it’s <strong>m * x</strong></p><h4>What is Error?</h4><p>› We know it already and after substituting the above individual terms, we get…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XOAxj4iBZiNyp9vdJ3jGVQ.jpeg" /></figure><p>And that my friend, is the correlation between the error and our change. Let’s rewrite this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*evCqECbtyEoFrc_wDdhppw.jpeg" /></figure><p>So now we have come with a result that will help us write a program which will arrive at accurate answers. Let’s test this out…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWZE7pm_zG4OIGgvNP0npw.jpeg" /></figure><p>This is insane, isn’t it? 💥</p><p>In a single step, we arrived at an accurate answer. This works well because we had an accurate answer to our conversion problem. Many a time, accurate answers are not available. For example, we cannot know the answer for a classifier problem beforehand, we could only guess whether the dividing line for our data-set is good or bad. This will get crystal clear when we explore the next part of this series.</p><p>We will build upon the relationship, <strong>∆m= E / x, </strong>further to solve intriguing problems like a classifier.</p><p>Lastly, in our human approach to the guess, we couldn’t arrive at the prediction in a single step. Similarly, we would want our program to approach the right answer gradually. And the reason we want to do that is to avoid overshooting the target. Overshooting the target becomes extremely evident when we apply the relationship for a classifier. We want our network to make small adjustments to improve the prediction holistically. Or in other words, we want our program to <strong>converge</strong> to a reasonable value. And essentially this is what most of the machine learning algorithms do, predict — improvise — predict.</p><p>This brings us to the end of the first part of the series. In the next part, we will learn about learning rate, summation function &amp; activation function. We will use JavaScript &amp; a bit of React(for canvas rendering only) that will eventually turn out to be a classifier.</p><blockquote>If you enjoyed this article, please 👏 this article to share it!</blockquote><blockquote>Follow me (<a href="https://medium.com/u/d91b30350860">Meher Ranjan</a>) on Medium to stay connected for the next part of this series. 👍</blockquote><blockquote>Cheers 🍻</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d86328048017" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>