<?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 Amresh Venugopal on Medium]]></title>
        <description><![CDATA[Stories by Amresh Venugopal on Medium]]></description>
        <link>https://medium.com/@amresh.venugopal?source=rss-87c330ad8f82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jRAL-6E2dPmtEnaA.</url>
            <title>Stories by Amresh Venugopal on Medium</title>
            <link>https://medium.com/@amresh.venugopal?source=rss-87c330ad8f82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 02:47:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amresh.venugopal/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[Implementing Deep Deterministic Policy Gradient with Unity’s ML-Agents]]></title>
            <link>https://medium.com/vernacular-ai/implementing-deep-deterministic-policy-gradient-with-unitys-ml-agents-1e55bea8ea40?source=rss-87c330ad8f82------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e55bea8ea40</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Amresh Venugopal]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 20:21:04 GMT</pubDate>
            <atom:updated>2020-02-27T10:10:54.021Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*8-NXPwKsxg5QYfzaRqKeYg.gif" /><figcaption>Multiple arms trying to maintain contact with the green target</figcaption></figure><h3>Environment</h3><p>In this environment, a double-jointed arm can move to target locations. A reward of +0.1 is provided for each step that the agent’s hand is in the goal location. Thus, the goal of the agent is to maintain its position at the target location for as many time steps as possible. The environment provides the state as a vector of 33 elements, in which an arm can perform 4 actions, with continuous values between 1 and -1.</p><p>I selected only one arm as my home machine was too slow when the time came to train 20 arms, I could barely see any learning in over 500 episodes.</p><h3>Deep Deterministic Policy Gradient</h3><p>DDPG was published with the title <em>“</em><a href="https://arxiv.org/pdf/1509.02971.pdf"><em>CONTINUOUS CONTROL WITH DEEP REINFORCEMENT LEARNING</em></a><em>”</em> at ICLR 2016. This paper pointed out that while Deep Q Networks are good at solving problems with high-dimensional observation spaces, they could only handle low-dimensional and discrete action spaces.</p><p>As an analogy, a DQN can teach which action to pick from North, South, East and West. But it would struggle if it also needed to answer <em>how many meters? </em>at <em>how many mph?</em></p><p>The authors also comment on why a DQN would struggle, which goes as:</p><blockquote>It is not possible to straightforwardly apply Q-learning to continuous action spaces, because in continuous spaces finding the greedy policy requires an optimization of action at time step t at every timestep; this is too slow to be practical with large, unconstrained<strong> function approximators</strong> and nontrivial action spaces. Instead, here we used an actor-critic approach based on the DPG algorithm (Silver et al., 2014)</blockquote><p>If the state space is large, say M and we want to find the best action from say N available actions where the action value is a real number. This problem is no longer about finding the largest element in a row of a matrix (best action corresponding to the state), it also requires the value of the said action. To visualize the degree of this problem, lets run a small snippet</p><pre>import timeit<br>import numpy as np</pre><pre>def randmatrix():<br>    return np.random.rand(100, 100)</pre><pre>timeit.timeit(randmatrix)</pre><p>To cut it short, these are the values:</p><pre>+-----------+--------------------+---------------+<br>|   state   |       action       |     time(s)   |<br>+-----------+--------------------+---------------+<br>|    100    |         100        |      0.11     |<br>|    1000   |         1000       |      11       |<br>|    10,000 |         10,000     |      ???      |<br>+-----------+--------------------+---------------+</pre><pre>(These numbers may vary with respect to the machine used)</pre><p>A single episode contains <em>t </em>time steps, imagine the training time for any real world use case where a large number of episodes are required to train an agent.</p><h3>Algorithm and notations</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*IVuii2ZdF-5yAA9rv1YyFg.png" /><figcaption>DDPG Algorithm</figcaption></figure><h4>Notations</h4><ul><li>θµ: Weights of the network(Actor) that tries to predict the best action (deterministic)</li><li>θq: Weights of the network(Critic) that tries to predict the value of the state, action for the given best action.</li><li>Q(s, a|θq): Q value for state action pair given that the network weights are θq.</li><li>µ(s|θµ): The best action for the given state s, given that the network weights are θµ.</li><li>M: Maximum number of episodes.</li><li>T: Maximum time steps in a single episode.</li><li><em>N</em>: An implementation of Ornstein-Uhlenbeck process was used for action exploration.</li><li>s: State of the environment at time step t.</li><li>a: Action taken at time step t.</li><li>r: Reward at time step t.</li><li>γ: Discount factor for future rewards</li></ul><p>Remember the <strong><em>function approximators</em></strong><em> </em>from the quote on the paper? Neural networks are used as <strong><em>function approximators.</em></strong></p><h3>Network architecture</h3><p>I used Pytorch for implementing the networks, with the following architecture, you can find the full code <a href="https://github.com/AmreshVenugopal/drlnd_continous_control">here</a>.</p><h4>Actor</h4><pre>(<br>  (fc1): Linear(in_features=33, out_features=256, bias=True)<br>  (bn1): BatchNorm1d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>  (d1): Dropout(p=0.1)<br>  (fc2): Linear(in_features=256, out_features=256, bias=True)<br>  (d2): Dropout(p=0.1)<br>  (fc3): Linear(in_features=256, out_features=4, bias=True)<br>)</pre><h4>Critic</h4><pre>(<br>  (fcs1): Linear(in_features=33, out_features=256, bias=True)<br>  (bn1): BatchNorm1d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>  (d1): Dropout(p=0.1)<br>  (fc2): Linear(in_features=260, out_features=256, bias=True)<br>  (d2): Dropout(p=0.1)<br>  (fc3): Linear(in_features=256, out_features=1, bias=True)<br>)</pre><h4>Hyper-parameters</h4><pre>1. BUFFER_SIZE      = int(1e5)  # replay buffer size<br>2. BATCH_SIZE       = 128       # minibatch size<br>3. GAMMA            = 0.99      # discount factor<br>4. TAU              = 1e-3      # for soft update of target parameters<br>5. ACTOR_LR         = 1e-4      # learning rate of the actor<br>6. CRITIC_LR        = 1e-4      # learning rate of the critic<br>8. FC1_UNITS        = 256       # Number of Neurons in the first hidden layer of both the actor and critic networks<br>9. FC2_UNITS        = 256       # Number of Neurons in the second hidden layer of both the actor and critic networks <br>10. TIME_STEPS      = 5000      # Number of time-steps in an episode</pre><h3>Experience</h3><p>DDPG Algorithms need a lot of episodes to solve environments<br>which means slow convergence of neural networks is a huge bottleneck.<br>The model trained in this example took ~6 hours to hit 30+ points <br>averaged over 300 episodes. <br><br>Previous attempts without batch-normalization had even poor <br>convergence results with over 500 episodes fed, a reward of 1 was <br>hard to maintain for the network.</p><p>Here are the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*M50R9Zkpzhp3ndE4px_q2Q.png" /></figure><p>Thanks for reading</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e55bea8ea40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vernacular-ai/implementing-deep-deterministic-policy-gradient-with-unitys-ml-agents-1e55bea8ea40">Implementing Deep Deterministic Policy Gradient with Unity’s ML-Agents</a> was originally published in <a href="https://medium.com/vernacular-ai">Skit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Navigating through Unity’s ML Agent’s environment using DQN]]></title>
            <link>https://medium.com/vernacular-ai/navigating-through-unitys-ml-agent-s-environment-using-dqn-2d8124b5df2e?source=rss-87c330ad8f82------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d8124b5df2e</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[Amresh Venugopal]]></dc:creator>
            <pubDate>Sun, 28 Oct 2018 17:56:30 GMT</pubDate>
            <atom:updated>2018-10-28T17:56:30.213Z</atom:updated>
            <content:encoded><![CDATA[<p>Unity recently released v0.5 of its <a href="https://github.com/Unity-Technologies/ml-agents">ML-Agents toolkit</a>, and I am really excited for using them for learning and research.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rf8vA8PZ5O-cVaDX9w5c_Q.png" /></figure><p>The toolkit provides open-ai gym like environments which can be <a href="https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Getting-Started-with-Balance-Ball.md">configured to a degree</a> and built for your experiment needs.</p><p>The environment I used for training an agent using DQN is a Banana Collector environment, where an agent moves around an area attempting to collect as many rewarding bananas (yellow) as possible while avoiding the blue bananas that penalize the agent for stepping over.</p><h3>Untrained agent</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*LF_5zZ0JtkL2v17InDkxnw.gif" /><figcaption>To have a perspective of the difficulty of the problem</figcaption></figure><p>Here the agent is trying random actions, it is allowed to move:</p><ol><li>Forward</li><li>Backward</li><li>Left</li><li>Right</li></ol><p>The agent perceives this environment as a state of 37 dimensions, which includes the agent’s velocity and a ray based perception of the objects around it. It shouldn’t take more than 1000 episodes to solve this environment, this particular project stated a reward of 13 points averaged over a 100 episodes will be considered solved. Here is how I fared:<a href="https://github.com/AmreshVenugopal/DRLND_Navigation_Project"> (Github link)</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*Zk4Aaw-6ayr24esg68Harw.png" /><figcaption>432: because the average of 13 rewards was taken over a 100 episodes</figcaption></figure><p>So let’s take a look at the difference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jtrdksa3eHfLRJ2eKoRhRA.gif" /><figcaption>The agent learns to choose yellow bananas and avoids the blue bananas like plague!</figcaption></figure><h3>Lessons</h3><p>While it was fun to have the agent trained the difficult part was gaining an intuition of why this works and the inner workings. I had heard many times that Deep Reinforcement Learning algorithms are <em>unstable, </em><a href="https://himanshusahni.github.io/2018/02/23/reinforcement-learning-never-worked.html">while</a> that <a href="https://stats.stackexchange.com/questions/265964/why-is-deep-reinforcement-learning-unstable">may</a> be <a href="https://www.alexirpan.com/2018/02/14/rl-hard.html">true</a> or the fact that it is really difficult to get something of value accomplished with the technique it didn’t help knowing what it <strong>really meant</strong>.</p><h3>Unstable</h3><p>I consider myself lucky when I run into things that don’t work. As that gives more perspective to the amount of work that needs to be put into things to get them working reliably, and the challenges that would appear in their real world applications. Here is a glimpse</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*FEVp8P5YD2blDaeYs1GGiA.gif" /><figcaption>An agent stuck between the choices</figcaption></figure><p>I had programmed the agent to early-stop when the environment is solved (13 points) but this picture shows the value of work done in 432 episodes. To be honest this happened many times, 40% of the times I would have a scenario like this and It would make me think what went wrong.</p><h3>Challenges</h3><ol><li>In an environment where the exploration space is infinite, there will never be a scenario where the agent has sufficient experience to know the best outcome for all states.</li><li>Using neural networks as approximators compounds the difficulty by adding the challenges involved in training them.</li><li>An agent will see the environment change really slowly, of which not a lot helps the agent until it starts getting a reward. What’s worse is association of sequential states with actions where getting rewarded for doing the same action in similar environment would convince the agent that the action is superior, while the agent has learnt to exploit only a small section of the environment.</li><li>The agent has to estimate the value of an action in a given state, such that the value of the resulting state is optimal. These are two separate approximations that need to comply. It is easy to make a mistake while selecting a good action for current state, also the assumption that the perceived next sate is actually the optimal.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d8124b5df2e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vernacular-ai/navigating-through-unitys-ml-agent-s-environment-using-dqn-2d8124b5df2e">Navigating through Unity’s ML Agent’s environment using DQN</a> was originally published in <a href="https://medium.com/vernacular-ai">Skit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attempting Open-ai’s taxi-v2 using the SARSA-max algorithm]]></title>
            <link>https://medium.com/vernacular-ai/attempting-open-ais-taxi-v2-using-the-sarsa-max-algorithm-70a4de8c8c9c?source=rss-87c330ad8f82------2</link>
            <guid isPermaLink="false">https://medium.com/p/70a4de8c8c9c</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Amresh Venugopal]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 17:32:35 GMT</pubDate>
            <atom:updated>2020-02-13T11:04:28.697Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*_ErC2yAZoi0BhWmtFh47zA.gif" /><figcaption>The taxi agent tries to find the shortest path from passenger(BLUE) to the destination(PINK)</figcaption></figure><p><a href="https://gym.openai.com/">Open ai gym</a>, as it says on its <a href="https://gym.openai.com/docs/">documentation</a> is <em>“…a toolkit for developing and comparing Reinforcement learning algorithms”. </em>I selected the <a href="https://gym.openai.com/envs/Taxi-v2/">taxi-v2</a> environment to test out my understanding.</p><p>A very detailed description of the problem is covered in this <a href="https://arxiv.org/pdf/cs/9905014.pdf">research paper</a>, I will try to highlight the key points, just enough to solve the problem.</p><h3>The Environment</h3><pre>+---------+<br>|R: | : :G|   R, G, B, Y are locations on this map<br>| : : : : |   The pipe symbol (|) represent walls<br>| : : : : |   The colon symbol (:) represent open spaces<br>| | : | : |<br>|Y| : |B: |<br>+---------+ </pre><ol><li>The map is a 5x5 gridworld, leading to 25 locations.</li><li>The alphabets R, G, B, Y are 4 locations.</li><li>A passenger can be at any of the 4 locations.</li><li>A passenger’s destination can be any of the left 3 locations.</li><li>The pipe symbol | denotes a wall, which means, |Y|x: if you’re at position x you can’t get to position Y by going left.</li><li>The colon symbol : denotes a pass, which means, |B:a| if you’re at position a you can get to position B by going left.</li><li>The taxi can pass through : but not |</li><li>The environment rewards 20 points when a passenger is dropped to their destination.</li><li>The environment penalizes -10 points if pickup operation is performed on a cell where there is no passenger.</li><li>The environment penalizes -10 points if drop operation is performed if no passenger had boarded the taxi.</li><li>The environment penalizes -1 for every other action.</li><li>There are 500 states in this environment.</li></ol><p>Each state answers these questions:</p><ol><li>Where is the taxi right now (one out of the 25 cells).</li><li>Where is the passenger right now (one out of R,G,B,Y and the possibility of being inside the taxi).</li><li>Where does the passenger want to go (one out of R,G,B,Y)</li></ol><p>Hence, 25 x 5 x 4 states.</p><h3>Initial conditions</h3><ol><li>At the start, the taxi will be at any of the 25 positions on the map.</li><li>A passenger will be at any of R, G, B, Y locations.</li><li>A destination will be at any of the R, G, B, Y locations.</li></ol><h3>Agent — Taxi</h3><p>Our agent is a taxi, which can perform <strong>6</strong> actions:</p><ol><li>South</li><li>North</li><li>West</li><li>East</li><li>Pickup</li><li>Dropoff</li></ol><h3>Expected behaviour</h3><ol><li>The taxi must find the passenger traveling the shortest path.</li><li>The taxi must pickup the passenger.</li><li>The taxi must find the shortest path to the passenger’s destination.</li><li>Drop the passenger at their destination traversing the shortest path</li></ol><h3>SARSA-max</h3><p>I used SARSA-max popularly known as <strong>Q-learning</strong> to train the taxi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*P6Kr96ukwULeN0ZL-9pL4Q.png" /><figcaption>Q-table update rule</figcaption></figure><p>When at time-step t, an agent in state s(t) performs an action a(t) the environment would respond to the agent with a reward of r(t+1) and a change of state s(t+1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*QlfOSW1euas9FpUs5_eP3Q.jpeg" /><figcaption>Personal notes: In the last block A1 is marked as “at t=1” was for me to understand this is what the agent does at t=1, even the R1 and S1 happen at t=1 just that they were returned by the environment.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vY1TK3JCfPTfGC_mQwZwzQ.jpeg" /><figcaption>Personal notes: Using the equation to populate the Q-table</figcaption></figure><p>A Q-table is a map of state and actions which help an agent to determine the most favourable action amongst all.</p><h3>Hyperparameters</h3><p>The hyper-parameters involved are:</p><pre>alpha=0.1<em><br></em>gamma=0.9<em><br></em>epsilon=1.0<br>epsilon_decay=0.9999,<br>epsilon_min=0.01</pre><ol><li>alpha is the learning rate, I have noticed that it affects the number of episodes required to get to grow beyond a certain value, lower alpha values made the training slow, but allowed higher rewards to be found.</li><li>gamma is the discount factor. In the problem at hand, the reward is provided only when a passenger is dropped to the destination, which means the agent should give importance to intermediate states, gamma should tend to 1 in such scenarios.</li><li>epsilon is the probability by which the agent will select an action of all the available actions at random. This facilitates exploration of better actions for a given state.</li><li>epsilon_decay the rate at which the epsilon value must reduce, we need high exploration in the beginning of any RL problem as there is no information about the environment, as the agent makes progress, it can exploit the Q-table to maximize its rewards. This would need a flexible epsilon granted by reducing it gradually by a factor of epsilon_decay . Increasing the precision i.e. epsilon_decay=0.9999999 would make the decay slow and it might affect the agent’s training.</li><li>epsilon_min is the minimum value of epsilon beyond which there will be no reduction. This is the minimum amount of exploration that is expected from the agent at all times.</li></ol><h3>Conclusion</h3><p>I trained the taxi agent for <strong>50k episodes. </strong>I managed to get rewards in the range of <strong>~9. </strong>During tests, I have seen that<strong> the agent takes the shortest paths</strong> towards the passenger and the destination <strong>but couldn’t manage to go beyond average reward of 9 within 100 episodes.</strong> You can find the full code <a href="https://github.com/CodeWingX/open-ai-gym-taxi-v2">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FQnBq13iILmI%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DQnBq13iILmI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FQnBq13iILmI%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/576c22e4a6e68c4aa90250422f915190/href">https://medium.com/media/576c22e4a6e68c4aa90250422f915190/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*QL0IgF9lHkLfbWTmw7suVQ.png" /><figcaption>The orange curve marks the best reward the agent has seen thus far</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*fWqX_gPzGVY_PvsJHCSSAQ.png" /><figcaption>The agent learns how to navigate with increasing number of episodes</figcaption></figure><p>Although I may be far from the <a href="https://gym.openai.com/envs/Taxi-v1/">qualifying mark set by open ai </a>which is “a<em>s getting average reward of 9.7 over 100 consecutive trials.” </em>The exercise leaves me more curious and motivated to explore RL and I can’t wait before I can start training on games.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70a4de8c8c9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vernacular-ai/attempting-open-ais-taxi-v2-using-the-sarsa-max-algorithm-70a4de8c8c9c">Attempting Open-ai’s taxi-v2 using the SARSA-max algorithm</a> was originally published in <a href="https://medium.com/vernacular-ai">Skit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seeing the world in three dimensions]]></title>
            <link>https://medium.com/vernacular-ai/seeing-the-world-in-three-dimensions-60bcbc75e93b?source=rss-87c330ad8f82------2</link>
            <guid isPermaLink="false">https://medium.com/p/60bcbc75e93b</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Amresh Venugopal]]></dc:creator>
            <pubDate>Sat, 22 Sep 2018 06:18:54 GMT</pubDate>
            <atom:updated>2018-09-22T07:16:14.814Z</atom:updated>
            <content:encoded><![CDATA[<p>A chemical explosion left a child blind at the age of three, this child became a successful businessman and a championship paralympic skier. The man <a href="https://en.wikipedia.org/wiki/Mike_May_(skier)">Mike May</a>, after forty years of blindness, learned about a treatment that could restore his vision.</p><p>The cameras were ready in position to document the scene, waiting for the bandages to come off. Mike describes the event as <em>“There’s this whoosh of light and bombarding of images on to my eye. All of a sudden you turn on this flood of visual information. It’s overwhelming.” </em>While Mike’s corneas could focus as they should, his brain had a hard time trying to make sense out of the information.</p><h3>Stereopsis</h3><p>The above excerpt is from <a href="https://www.amazon.in/Brain-Story-You-David-Eagleman/dp/1101870532">“<em>The Brain, the story of you</em>” by David Eagleman</a> which covers a lot of interesting aspects of the human mind and how we perceive the world, given that our brain is lives safely in a dark, closed, bony shell. It covers many topics that we consider <em>easy </em>as an<em> illusion of easy.</em></p><p>I got hooked onto this book and the current topic of focus <a href="https://en.wikipedia.org/wiki/Stereopsis">stereopsis</a><strong>, </strong>thanks to the rapid advancements in the field of self driving cars, computer vision, deep neural networks, deep reinforcement learning (If I add blockchain it will summarize all the buzzwords of 2018). It was intriguing to think, Why do I know without measuring how far things are from me? Why can’t a camera do the same? There is <a href="https://www.youtube.com/watch?v=lawxhnRhmeY">interesting work</a> regarding this in the <a href="https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html">computer vision department</a>.</p><p>The amazing thing about stereopsis is, we don’t realize that we have it! How would you know that not everyone sees the world the way you do? Our left eye and right eye form different images. Try keeping a hand close, in the middle of your eyes and close each eye alternatively, notice the little shifty difference? Our brain does the job of merging them into one with information of depth and<strong> </strong>stereopsis is our perception of depth and mostly the animals with eyes towards their front possess this ability. A cow doesn’t see the world the way your cat does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*c5Oa5-jmMNPuOOQJv-bHeA.jpeg" /><figcaption>Image taken from <a href="http://www.vision3d.com/">http://www.vision3d.com</a></figcaption></figure><p>The interesting part is, <a href="https://youtu.be/bnefTJx2sCo?t=202">Mike May wasn’t able to, when his vision got restored</a>!</p><blockquote>Mike set his eyes on the cars, buildings, and people whizzing by, trying unsuccessfully to understand what he was seeing. On the freeway, he recoiled when it looked like they were going to smash into a large rectangle in front of them. It turned out to be a highway sign, which they passed under. He had no sense of what objects were, or an idea of their depth. In fact, post surgery, Mike found skiing more difficult than he had as a blind man, because his depth perception difficulties, he had a hard time telling the difference between people, trees, shadows, and holes. They all appeared to him simply like dark things against the white snow.</blockquote><blockquote>— <a href="https://www.amazon.in/Brain-Story-You-David-Eagleman/dp/1101870532"><em>The Brain, the story of you” by David Eagleman</em></a></blockquote><p>Stereopsis appears to be a highly evolved trait in the vertebrates and there are only three groups of vertebrates with truly forward-facing eyes: primates, carnivorous mammals, and birds of prey. In other words, most animals that hunt would have both eyes facing front, although not always. This provided a benefit as knowing where the prey is; helps when the means of hunting are pouncing, chasing, grabbing. While the prey animals (herd animals) have eyes on the opposite side of the head, this gives them a greater field of view. Since they feed by plucking off from the ground directly beneath them there is no need for position specific information, whilst a giraffe, or an elephant pluck food from heights and hence need to know where to do the plucking from, developed eyes to the front.</p><p>Neuroscientist Bela Julesz invented the first kind of stereogram, a random dot stereogram. While it may sound like a hard to digest word, it is something that all 90s kids would remember:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*tcVm9xSzFY-1t8_0uPNlLQ.jpeg" /><figcaption>Can you see the sailboat? <a href="https://www.flickr.com/photos/_robson_/12548983274">https://www.flickr.com/photos/_robson_/12548983274</a></figcaption></figure><p>If you are interested in creating one of these, Ben Simonds has a nice <a href="https://bensimonds.com/2013/06/07/magic-eye-pictures-with-processing-and-blender/">guide</a>. Bela Julesz generated an image with randomly distributed dots. He selected an area in the image and shifted it slightly in a second image. An assuming viewer would perceive that there is a circle floating above the background <a href="http://mentalfloss.com/article/29648/how-do-magic-eye-pictures-work">read more here</a>. This supported the idea that depth perception happened in the brain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*x8QpTGL5p_5jw0OPD86NxA.png" /><figcaption>From Wikipedia: <a href="https://en.wikipedia.org/wiki/Autostereogram">https://en.wikipedia.org/wiki/Autostereogram</a></figcaption></figure><p>If you have made it so far, I have a treat for you.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2AKtp3XHn38%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2AKtp3XHn38&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2AKtp3XHn38%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/d4c858f93633a08ae6d24644000e0da1/href">https://medium.com/media/d4c858f93633a08ae6d24644000e0da1/href</a></iframe><p>If you knew what an autostereogram is and it is the first time viewing it in a video, have fun you would find it easier than others who are first time viewers. Those who are having a first time experience with autostereogram your experience could range from annoying to whoa!. I had shared this with all my friends and I have gathered that it helps to view your reflection in beginning when the screen is dark, thanks <a href="https://medium.com/u/9b7daa33f4d7">Akshay Deshraj</a> for the tip! If you manage to get the illusion of three white dots (the false dot appearing right in the middle of other two) good luck! you’re in for some fun! If you have known this video please share it with your friends, the reaction this brings on their faces is priceless,</p><blockquote>…and as always thanks for watching.</blockquote><blockquote>— <a href="https://www.youtube.com/watch?v=L45Q1_psDqk">Michael Stevens</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60bcbc75e93b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vernacular-ai/seeing-the-world-in-three-dimensions-60bcbc75e93b">Seeing the world in three dimensions</a> was originally published in <a href="https://medium.com/vernacular-ai">Skit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reinforcement Learning: Train a bot to play tic-tac-toe.]]></title>
            <link>https://medium.com/vernacular-ai/reinforcement-learning-step-by-step-17cde7dbc56c?source=rss-87c330ad8f82------2</link>
            <guid isPermaLink="false">https://medium.com/p/17cde7dbc56c</guid>
            <category><![CDATA[artificial-neural-network]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <dc:creator><![CDATA[Amresh Venugopal]]></dc:creator>
            <pubDate>Sun, 09 Sep 2018 21:12:25 GMT</pubDate>
            <atom:updated>2020-01-16T15:52:33.815Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Reinforcement learning is learning what to do — how to map situations to actions — so as to maximize a reward.</em></blockquote><h3>Motivation</h3><p>I work as a software engineer at <a href="https://vernacular.ai/">vernacular.ai</a>. Building voice-first products pose many challenges, and if you have tried your hands-on machine learning problems, you would know how hard it is to get your hands on tagged real-world data. Attempting large scale data tagging activity incurs financial costs, but there is also a cost of accuracy. Do we employ X taggers and obtain results by doing some form of voting per data point and further the cost? Or compromise with accuracy over money?</p><p>In one of such discussions I had with my peers, there was a point raised, “why don’t we teach a model to learn the tagging process?”. You’d say, <em>“isn’t that the job of a trained model? predicting the tag of a new input based on historical evidence?”</em> The answer to that requires a bit of context.</p><p>We have an internal tool that allows us to tag raw audio/text and create different kinds of tagging jobs. Human taggers are employed to identify features of interest. There lies a limitation where it takes too long to get high-quality tagged data.</p><p>Coming back to the discussion, we thought about what if we could train a model that observes the interactions of the human taggers with our tool and learns to draw bounding boxes, identify essential parts of a given sentence, and clicks the submit button when it is done? If executed well, it could push down the budget needed to tag data, but the accuracy? That wouldn’t be an A-grade?</p><p>We thought of using agent tagged data to still go through the pipeline with human taggers to validate. It is far easier for a human to validate the work done than to hand-draw rectangles using a mouse or typing full sentences where a bit of correction would be enough.</p><p>This would not mean an exponential increase in the number of reliable taggers, but it would improve the reliability of the taggers and the volume of data that gets tagged per day.</p><p>There is a different and interesting class of ML algorithms that handle such problems: Reinforcement Learning.</p><p>While I am reading and running experiments to be in a state to create a prototype for the above problem, I thought of putting up a primer for personal reference and I hope it helps someone else too.</p><p>Let’s get introduced to some terminologies to get started.</p><ol><li><strong>Agent</strong>: The problem solver, can perform some actions in an environment.</li><li><strong>Environment</strong>: The residence of an agent. An environment provides responses to an agent based on the actions it performs.</li><li><strong>Reward</strong>: When an agent performs an action in an environment, there is an associated reward; rewards can be positive, negative(punishment) or zero.</li><li><strong>State</strong>: An agent’s action may cause it to enter a state which you can assume to be a snapshot (partial or whole) of the environment. (Like checkmate <strong>(state)</strong> on a chess board <strong>(environment)</strong>)</li><li><strong>Policy</strong>: Defines an agent’s behavior, can answer questions like <em>what action should be performed in this state?</em></li><li><strong>Value</strong>: Tracks the long-term impact of the action. Provides a portion of reward to intermediate states that led to a final positive state.</li></ol><h3>Exploration vs Exploitation</h3><p>Imagine the first time you visited a place, maybe to meet a friend or to find a particular store in the crowd. How easy was this? (thank god for those google maps!) It might have taken some wandering around to get to the destination finally, but is that the case every time? The more frequently you visit a place, the more likely it is that you take the shortest path to it.</p><p>Time is precious and time saved is a reward. Finding a shorter path leads to more time saved.</p><p>Another example: If you<strong> (agent) </strong>had an important test ahead and given that reading <strong>(action) </strong>every page of a book would ensure that you score well<strong> (desirable state)</strong>, you would either waste no time and start preparations <strong>(exploitation), </strong>or you could say <em>“That’s too much work, there’s got to be an easier way!”</em> and try different things, maybe taking help from a mentor, searching for a different book, check out previous exam papers <strong>(exploration)</strong> and so on.</p><p>Or, you could invite your friends <strong>(action)</strong> over for a party <strong>(desirable state)</strong>, you also know that you will fail <strong>(undesired state)</strong> if you do so instead of preparing for the exam.</p><p>Sometimes things turn out to be a disaster, in which case you are not going to try them out again. But if it worked? You will surely be tempted to try it out once more, and each time it works, you will be assured that it’s not risky at all. (Don’t drive two-wheelers without helmets!)</p><p>If this made sense, you now know what <a href="https://en.wikipedia.org/wiki/Multi-armed_bandit">epsilon-greedy</a> means.</p><h3>How to train?</h3><p>Training an agent to solve problems using reinforcement learning, requires us to learn more about the agent, environment, policy function, reward function, value function and so on. I highly recommend the book<a href="https://web.stanford.edu/class/psych209/Readings/SuttonBartoIPRLBook2ndEd.pdf"> Reinforcement Learning — An Introduction</a> if you’re looking for a deep dive.</p><h3>Show me the code</h3><p>Let’s get to the topic of this post, an experiment that should yield an agent with the ability to play tic-tac-toe. The full code can be found <a href="https://github.com/CodeWingX/tic_tac_toe"><em>here</em></a>.</p><p>The agent doesn’t <em>understand</em> the game, but it performs actions that leads to victory. An agent will learn poorly if it plays against someone too lenient or too strict. Like us, how we get lazy when there are no repercussions to it. But, unlike us, it doesn’t understand that the game is symmetric. Although, you may see after letting it play many games that the rewards for symmetric cells tend to approach similar values.</p><p>So how do we train this thing?</p><p>If you know about supervised learning methods, you’d know that training a model involves:</p><pre>model.fit(X, y)</pre><p>Where X represents the features and y represents the output expected from the model.</p><p>Here, we let the agent play with another agent. Playing against an agent will produce different events as both start with random moves, but soon they will start teaching each other as either of them would start winning leading to the other to get punished preventing past mistakes.</p><h3>Results</h3><p>After running it a couple of times:</p><pre> # Initialize board</pre><pre>               |   |  <br>            -----------<br>               |   |  <br>            -----------<br>               |   |</pre><pre># Turn 1: Agent<br>chooses to : exploit<br>State rewards<br>[[-1.34420291e-06 -1.93552449e-05 -1.63751124e-06]<br> [-9.27061411e-05  6.02074321e-06 -4.91809311e-05]<br> [ 2.75046039e-07 -1.20282720e-05 -4.48041757e-05]]<br>(1, 1)<br><br>               |   |  <br>            -----------<br>               | O |  <br>            -----------<br>               |   |</pre><p>The state_rewards matrix is a reflection of the agent’s past, all the games it has played, the most valuable state happened to be the centre of the board. I’d say I’d make the same move if I had got the first turn.</p><pre># Turn 2: Human<br>             X |   |  <br>            -----------<br>               | O |  <br>            -----------<br>               |   |</pre><pre># Turn 3: Agent</pre><pre>exploit<br>State rewards<br>[[-2.81220399e-05 -1.22350403e-05 -1.27381596e-05]<br> [-4.93718481e-05 -4.96256312e-05 -4.98737672e-07]<br> [-1.17387500e-03  8.97600032e-03 -4.99975063e-03]]</pre><pre>             X |   |  <br>            -----------<br>               | O |  <br>            -----------<br>               | O |</pre><p>Once again the agent has chosen the action that led to highest rewards in the past.</p><pre># Turn 4: Human<br>             X | X |  <br>            -----------<br>               | O |  <br>            -----------<br>               | O |</pre><pre># Turn 5: Bot</pre><pre>exploit<br>State rewards<br>[[-2.34611639e-05  0.00000000e+00  0.00000000e+00]<br> [-4.98750000e-05  0.00000000e+00 -1.00000000e+00]<br> [ 0.00000000e+00  0.00000000e+00  0.00000000e+00]]<br>(0, 2)<br><br>             X | X | O<br>            -----------<br>               | O |  <br>            -----------<br>               | O |  </pre><p>Looks like our agent never came across this particular setup (look at the state_rewards) with the other agent; there are plenty of empty state values. The bot would choose from any of the cells that are 0 since they are the better than the other cells, with more games played, the bot will know that there are cells which result in higher reward.</p><p>Some more instances of this test. (The agent marks <strong>O’</strong>s)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhMCUuecixXzQVMdOo2c6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EjEbeYXEeWS9blIYH_Iwlw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJEbmWyroYpIaKaefjPVqw.png" /><figcaption>Agent can capitalize on a player’s mistakes</figcaption></figure><p>Have criticism, suggestions? please post them in the comments, and I’ll get to it. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17cde7dbc56c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vernacular-ai/reinforcement-learning-step-by-step-17cde7dbc56c">Reinforcement Learning: Train a bot to play tic-tac-toe.</a> was originally published in <a href="https://medium.com/vernacular-ai">Skit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>