<?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 Shubham Jayawant on Medium]]></title>
        <description><![CDATA[Stories by Shubham Jayawant on Medium]]></description>
        <link>https://medium.com/@srjdbest?source=rss-15bee550a754------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q70tQsg0S_3oQ0J8tkvucA.jpeg</url>
            <title>Stories by Shubham Jayawant on Medium</title>
            <link>https://medium.com/@srjdbest?source=rss-15bee550a754------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 21:45:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srjdbest/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[How to make a chess engine]]></title>
            <link>https://medium.com/quartifex/how-to-make-a-chess-engine-f89ec88b4e85?source=rss-15bee550a754------2</link>
            <guid isPermaLink="false">https://medium.com/p/f89ec88b4e85</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[chess]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Shubham Jayawant]]></dc:creator>
            <pubDate>Wed, 05 Apr 2017 10:59:11 GMT</pubDate>
            <atom:updated>2017-04-07T06:07:07.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Du9_Skz7Fk1cOBiXMrl5Q.jpeg" /></figure><p>Last blog post was about <a href="https://medium.com/quartifex/introduction-to-machine-learning-b2903ca088cc"><em>introduction to machine learning</em></a>. We also came across various applications of it. This one is going to be about the basic concepts of machine learning. We’ll be going through fundamentals of ML and making a chess engine by implementing them.</p><p>Before starting with any of these let me mention the person who has inspired the theme of this post. He is truly a winning machine when it comes to playing the game of chess and he has set a number of records which seem impossible to achieve to most of us. His name is, <em>Magnus Carlsen</em> (Go see his incredible stats over <a href="https://ratings.fide.com/card.phtml?event=1503014"><em>here</em></a>).</p><p>Let’s say, you want to be a world champion chess player like <em>Magnus</em>. Then you will have to start with the basics of chess and keep learning new things until you become the world champion. But we know that it won’t be this straightforward. Because, in the game of chess there are numerous possibilities. Therefore, memorizing a list of moves won’t be helpful. Also, just by playing a couple of games against your roommate won’t win you a world championship. You will have to put in efforts over a prolonged period of time to become a world champion.</p><p>Good news is, your computer can learn to play the game of chess, get really good at and that too in a considerably small time. It is because, computers have big non-volatile memory storage and they can carry out arithmetic operations swiftly. So, why not make an engine using the concepts of machine learning which will play chess and will get better at it after every game?</p><p>We’ll begin by getting some basics clear. Machine learning is a field which solves problems which are logically or computationally impossible to solve just by making use of normal rule defined programming. Therefore, any machine learning problem can be identified by checking these really simple situations. First of all check whether you’re able to come up with specific programmable rules to solve the given problem. If not, then check whether it is small enough to be solved by human efforts. If not, then it is a machine learning problem.</p><p>After deciding that certain problem is machine learning worthy, we move on to solve it.</p><h3>How to solve a machine learning problem?</h3><h4>Step I) Define the problem</h4><p>The parameters used for effectively defining all aspects of any problem are as follows,</p><p><strong>Task</strong>: Operation to be performed</p><p><strong>Experience</strong>: Learning experience required to carry out the intended task.</p><p><strong>Performance</strong>: Measuring how well the algorithm performs</p><p>Therefore, the problem of chess engine can be described as,</p><p><strong>Task</strong>: To play chess</p><p><strong>Experience</strong>: Number of games played against itself</p><p><strong>Performance</strong>: % of games won against opponents by playing fair</p><p>Defining a problem completely is an important step in solving it, since this is referred by the later stages to determine the accuracy of the results.</p><h4>Step II) Decide its target function</h4><p>Target function decides what type of knowledge will be learned by the algorithm. The more appropriate the target function is, the more correctly the learning will occur and more accurate results will be produced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*MvuagXRCYzx5WfFis-ytCA.gif" /><figcaption>This GIF shows what a bad selection of target function looks like</figcaption></figure><p>In case of a chess engine, a well-trained engine would choose the best move among all the legal moves. The easiest way of creating such function which I can think of is to assign numerical values to each and every board state (state of board achieved after playing one of the legal moves) and choose the one with highest numerical value.</p><p>We will denote the target function as <em>V</em>. Therefore, <em>V(b)</em> will be the target value for an arbitrary board state <em>b</em>. Let us define the target value <em>V(b)</em> for different board states.</p><p>a) <em>V(b)</em> = 1.00, given that b is a concluding board state that is won</p><p>b) <em>V(b)</em> = -1.00, given that b is a concluding board state that is lost</p><p>c) <em>V(b)</em> = 0, given that b is a concluding board state that is drawn</p><p>d) <em>V(b)</em> =<em> V(b’)</em>, given that <em>b</em> is not a concluding board state and <em>b’</em> is the best concluding board state that can be achieved starting from <em>b</em> and playing optimally until the end of the game.</p><p>Evaluating the target value in case d) is a challenge for our chess engine since this case requires searching ahead for optimal play till the end of the game. In fact, it is practically impossible for us to design a target function for this case. Therefore, we’ll make our learning algorithm to acquire only approximation to the target function. We will use the symbol <em>V’</em> to refer to the function that is actually learned by our program, to distinguish it from the ideal target function <em>V</em>.</p><h4>III) Approximate the target function</h4><p>Before approximating any target function we should take into consideration these very important points.</p><ul><li>If the degree of approximation is very high, then it will cause many of the cases to be ignored by the algorithm, resulting into a less intelligent program.</li><li>If the degree of approximation is very low, then the algorithm will go through all the cases despite many being redundant, resulting into high memory and time consumption.</li></ul><p>Therefore, our approximation should be something in between these two extremes, making a respectably intelligent program which would eventually operate within time and memory constraints.</p><p>To keep the approximation simple, let us represent <em>V’ </em>as a linear combination of different board features. Consider the following board features,</p><p><em>x</em>₁: No. of white pieces on board</p><p><em>x</em>₂: No. of black pieces on board</p><p><em>x</em>₃: No. of squares attacked by white pieces</p><p><em>x</em>₄: No. of squares attacked by black pieces</p><p><em>x</em>₅: Has white castled?</p><p><em>x</em>₆: Has black castled?</p><p>Thus, our approximated target function will look like,</p><p><em>V’(b)</em> = <em>w</em>₁<em>x</em>₁ + <em>w</em>₂<em>x</em>₂ + <em>w</em>₃<em>x</em>₃ + <em>w</em>₄<em>x</em>₄ + <em>w</em>₅<em>x</em>₅ + <em>w</em>₆<em>x</em>₆</p><p>Where <em>w</em>₁<em> </em>through <em>w</em>₆<em> </em>are weights to be adjusted by the learning algorithm. These weights will determine the importance of their corresponding board feature.</p><p>The weights are adjusted during every iteration, reducing the error in the system and thereby making the engine more intelligent. For adjusting weights there are several algorithms available out there. The one which we are going to use is known as least mean squares or LMS weight update rule. It is given as,</p><p><em>w</em>ᵢ<em> </em>= <em>w</em>ᵢ + <em>η</em> * (expected_output(<em>b</em>) − actual_output(<em>b</em>)) * <em>x</em>ᵢ</p><p>Here, expected_output(<em>b</em>) is the output which should be produced by the algorithm for given board state <em>b, </em>actual_output(<em>b</em>) is the output which is actually produced by the algorithm and <em>η</em> is a learning constant.</p><p>The higher the value of <em>η</em>, faster the values of weights will change. Therefore, in order to have effective learning, the value of <em>η </em>shouldn’t be too high (which will update the weights with less precision) or too low (which will cause weights to take a lot of time to get updated).</p><p>Let us write down code for all the things we’ve learnt so far.</p><pre>def get_target_value(weights, board_feat):<br> target_value = 0<br> for index,weight in enumerate(weights):<br>  target_value = target_value + (weight * board_feat[index])<br> return target_value</pre><pre>def update_weights(weights, eta, exp_op, act_op, board_feat):<br> for index,weight in enumerate(weights):<br>  weight = weight + eta * (exp_op - act_op) * board_feat[index]   <br> return weights</pre><p>This is it. By attaching this engine to a GUI which feeds all the required board features to our chess engine at every move will get this engine into action. You can add more board features, change the number of iterations of training and adjust the value of learning constant in order to make a chess engine which can think about more number of possibilities during a chess game.</p><p>(Complete code of this chess engine along with an integrated GUI can be found <a href="https://github.com/shubhamjayawant/chess_engine"><em>here</em></a>)</p><p>The entire design of any learning problem can be summed up in a simple form. It’s called the final design of a learning problem. It gives information about the problem being solved, how the problem is being solved, training examples being used and examples to test our algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*9e03_ZdxZgFUVJp0h0uamA.gif" /></figure><p>This GIF shows the final design of the chess engine problem. It can be seen that performance system, critic, generalizer and experiment generator form a closed loop, iterating through which the learning problem gets solved with more precision.</p><p>That’s it for this blog post. If you liked it, you can recommend it to others and follow me to get notified whenever I post anything.</p><p>Next post is going to be about neural networks in which we’ll see what exactly these amazing things are and how they work. I’ll also teach you to draw pictures worth millions of dollars despite being terrible at drawing. So don’t forget to check out my next post once it is out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f89ec88b4e85" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quartifex/how-to-make-a-chess-engine-f89ec88b4e85">How to make a chess engine</a> was originally published in <a href="https://medium.com/quartifex">Quartifex</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to machine learning]]></title>
            <link>https://medium.com/quartifex/introduction-to-machine-learning-b2903ca088cc?source=rss-15bee550a754------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2903ca088cc</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Shubham Jayawant]]></dc:creator>
            <pubDate>Sat, 25 Feb 2017 05:04:12 GMT</pubDate>
            <atom:updated>2017-04-05T11:01:08.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*d9qWS4CSegbPQXRvo05EyQ.jpeg" /></figure><p>Computers. Exceptional devices, aren’t they? Who would have thought that just a simple assembly of plastic and silicon components can do mind boggling things. Whether it is driving cars, flying airplanes, analyzing satellite captured images or even checking up patients, they can do it all!</p><p>Ever since computers were invented it has been every researcher’s dream to make them smart and intelligent. And why shouldn’t it be, wouldn’t it be cool if your computer tells you what to wear on your first date? Or comes up with witty responses during the conversation? Or tells you topics to talk about with your date?</p><p>I’m pretty sure after coming to know about these applications of intelligent computers, creating one would have become one of your dreams as well. The field in computer science which deals with these kinds of crackerjack things (not dating in particular) is, Machine Learning.</p><h3>So, what exactly is Machine Learning?</h3><p>The way I understand it is that, it’s a phenomenon which enables computers to yield accurate results or make wise decisions by themselves without requiring to be explicitly programmed for the same.</p><p>You might be wondering how they do it, since they do cool stuff without being hard-coded for doing so. The concept used is pretty simple. Rather than feeding computers with programs, they’re fed with number of examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*P8XU--Wjo24TafWjqTZkCg.gif" /></figure><p>The set of these examples is called as ‘training set’. Using the examples from training set, computers adjust certain parameters also referred as ‘weights’ in order to reduce error in the output. This procedure of accessing each example from training set and adjusting weights accordingly is carried out for all the examples present in the training set.</p><p>Once the entire training set is traversed, one iteration is said to have been completed. To achieve highly accurate results, your training set should be sufficiently large (varies from application to application) and number of iterations carried out over the training set should be adequate (we’ll discuss in the coming blog posts how much this ‘adequate’ actually is).</p><p>That’s how majority of the ML algorithms work. During the training period they work on minimizing the error in the system and during the testing period they make use of their earned knowledge base to solve given problem. Depending upon the nature of these algorithms, they can be divided into 2 types.</p><p>a. Supervised learning algorithms</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8vMRMiwPXpehl9rfiqlZaA.gif" /></figure><p>To understand this type of algorithms, read this little story. Imagine yourself to be a student who is really weak at mathematics. So, in order to get better at it, every day you go visit your mathematics professor, who knows answers to all the math problems in your textbook.</p><p>After you solve any problem, the professor checks your final answer and tells you whether it is correct or wrong. If you get it wrong, you ask for the problem’s solution. After going through the solution you make sure that you don’t repeat the same mistake again. This improves your problem solving ability. As a result of which you become able to solve math problems which do not belong to your textbook and answers of which are not known to your professor as well.</p><p>This is how supervised learning algorithms work, during the training period, for every input from the training set, they calculate the difference between the expected output and the one produced by them. Then they try to minimize that difference by adjusting weights. This enables them to process inputs which do not belong to their training set.</p><p>b. Unsupervised learning algorithms</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Nsnahc-yIHs82yr72juWzA.gif" /></figure><p>In case of unsupervised learning algorithms, the supervisor who tells the algorithm about the expected output for any given input is not present. The algorithm learns things by itself. It is free to carry out any kind of operation over the input set. After going through the input data it can identify special patterns, come up with certain conclusions or even make various predictions.</p><p>The GIF above demonstrates a good example of unsupervised learning where the bot learns things on its own and comes up with a conclusion.</p><p>Since this is an introductory blog post I won’t take you through any more theoretical stuff, instead, we’ll do a fun thing.</p><p>Have you guys ever thought of competing against AI programs? Well, I thought of doing so and did it as well. And for the competition I chose a thing I am really good at. Coloring! I really like coloring things and I’m pretty sure many of you guys love it as well. So, I decided to put AI coloring engine to the test and then compared our results. Here’s how the competition went.</p><h3>Me vs. AI</h3><p>So the rules of this competition were pretty simple. We were supposed to fill colors in an image. And it was not a normal image, it was a ‘grayscale’ (or ‘black and white’ as many people like to refer them) image. And the winner was going to be the one whose color filled copy of the grayscale image looked more realistic to human eyes.</p><p>Have a look at the results yourselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NAhI6go_5xzDkxV6wek1Bg.png" /></figure><p>Well, what can say, at least I tried.</p><p>Surprisingly, AI engines are really good at this. In fact, this little game which I played against the AI engine is known as ‘colorization of grayscale images’ and nowadays it has become a real hot topic for research in the field of deep learning.</p><p>These engines require to be trained over number of grayscale images with the corresponding colored versions of these images being expected outputs. Once they’re properly trained they can even colorize ancient grayscale photographs. Now that’s really cool considering the fact that they’re doing certain thing which is practically impossible for humans.</p><p>(The link of the website of the colorizing engine I used is <a href="http://demos.algorithmia.com/colorize-photos/">here</a>. The algorithm being used here for colorizing the images is different than the conventional techniques and its results are promising. For more information regarding image colorization you can visit the aforementioned website. You can even colorize your old photos there.)</p><p>So that’s it for this blog post. In the coming blog posts I’ll be taking you guys through various deep level concepts of machine learning, in a fun way of course. We’ll be coding for stuff which you thought only your nerd cousin could code for.</p><p>The <a href="https://medium.com/quartifex/how-to-make-a-chess-engine-f89ec88b4e85">next post</a> is going to be about basic concepts of machine learning in which we’ll make an AI chess engine. So don’t forget to check that out once it is out.</p><p>If you have any queries you can put those in the response section below. If you liked this post you can share it and follow my publication in order to get notified whenever I post anything.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2903ca088cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quartifex/introduction-to-machine-learning-b2903ca088cc">Introduction to machine learning</a> was originally published in <a href="https://medium.com/quartifex">Quartifex</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>