<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Kushal Vajrala</title><description>Kushal Vajrala&apos;s Blog</description><link>https://kushalvajrala.com/</link><item><title>Robot Crawler with Reinforcement Learning In-Progress Notes</title><link>https://kushalvajrala.com/posts/robot-crawler-with-reinforcement-learning-in-progress-notes/robot-crawler-with-reinforcement-learning-in-progress-notes/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/robot-crawler-with-reinforcement-learning-in-progress-notes/robot-crawler-with-reinforcement-learning-in-progress-notes/</guid><description>or, a beginner&apos;s fumblings and consequent learnings.</description><pubDate>Wed, 26 Aug 2026 16:40:38 GMT</pubDate><content:encoded>&lt;p&gt;After a long and difficult conversation with myself, I decided to go down the career path that would bring me the most satisfaction. Part of that is building in public and doing the things that would signal that I actually know what I&apos;m talking about. It&apos;s too easy to outsource our thinking and ability to AI so I want to ensure that doesn&apos;t happen here.&lt;/p&gt;
&lt;p&gt;Reinforcement learning and Robotics are two fields that have always fascinated me but I hadn&apos;t taken agency over my professional career to pursue a living in them. I no longer have to separate interests and my career!&lt;/p&gt;
&lt;p&gt;The goal of this project is to teach a robot with legs how to walk. Maybe I can extend it to navigating an obstacle course but for now we&apos;ll leave it here.&lt;/p&gt;
&lt;p&gt;The following is a list of notes that I am taking while I learn the necessary prerequisites. It&apos;s not meant to be comprehensive or helpful to anyone but myself, but I want to make this public to let people offer any feedback or anything else.&lt;/p&gt;
&lt;p&gt;If you don&apos;t see much notes, that&apos;s fine, I&apos;m probably just busy actually writing them and they&apos;ll be pushed soon.&lt;/p&gt;
&lt;h3&gt;RL Notes:&lt;/h3&gt;
&lt;h3&gt;Robotics Notes:&lt;/h3&gt;
</content:encoded><category>Notes</category><category>Reinforcement Learning</category><category>Robotics</category><author>Kushal Vajrala</author></item><item><title>The Watcher</title><link>https://kushalvajrala.com/posts/the-watcher/the-watcher/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/the-watcher/the-watcher/</guid><description>or, a short story featuring a character you might not have been expecting.</description><pubDate>Mon, 04 Aug 2025 04:56:22 GMT</pubDate><content:encoded>&lt;p&gt;“No you don’t understand, I’m being &lt;em&gt;watched&lt;/em&gt;.”&lt;/p&gt;
&lt;p&gt;The man I was sitting next to on the bench outside my favorite shawarma place shifted slightly in his seat, but he made no further interruptions. The river across from us murmured, curious as to our conversation. Joggers ran by. A singular boat bobbed up and down right across from the bench. My eyes caught the fraying of the cardboard sign he held, a testament to its age. “Will listen to your problems if you pay me.” Glancing back through his matted beard and hair, I felt a strange sense of security and curiosity emanating from his eyes.&lt;/p&gt;
&lt;p&gt;“I’m telling you, this kid looks too much like me. I dug through old childhood photos and I swear it’s a doppelgänger.”&lt;/p&gt;
&lt;p&gt;I motioned to pull my phone out, attempting to provide some semblance of proof for my ridiculous claims. The stranger waved his hand, dismissing it.&lt;/p&gt;
&lt;p&gt;“I believe you. Carry on, why does he bother you?”&lt;/p&gt;
&lt;p&gt;Relieved that finally someone didn’t doubt it, I took a deep breath in and proceeded in my story. “Do you mind?” I asked, pulling out my Marlboros. After a small shake of his head, I took a puff and snapped my lighter closed.&lt;/p&gt;
&lt;p&gt;“I first noticed him on the anniversary of my ex and I a couple months ago. Then, I was more concerned than anything, a baby crawling around on the grass outside wherever I was. I thought I was just seeing things, but he seemed to age at an accelerated speed.”&lt;/p&gt;
&lt;p&gt;I took a break for another drag. I offered a cig to the man, but he kindly and politely refused.&lt;/p&gt;
&lt;p&gt;“So initially, I went out to try and get him to his parents. But every time I left the building I was in, he would disappear! Poof, vanish, like he wasn’t even there. As I walked back inside, though, I could &lt;em&gt;feel&lt;/em&gt; him materialize. His eyes, dripping with innocent malevolence, locking back onto the back of my neck. Watching my every move. Staying outdoors or maintaining eye contact are the only ways I’m able to stay sane.”&lt;/p&gt;
&lt;p&gt;I felt a phantom sensation tingle down my spine, and I paused to scratch my neck. I envied the crowds passing by. None of them had to care about anything other than their own problems. My eyes felt heavier than usual from the lack of sleep.&lt;/p&gt;
&lt;p&gt;“He doesn’t let me sleep. I know he’s out there, staring, watching. Am I being punished? I don’t know.”&lt;/p&gt;
&lt;p&gt;“Hm. What would you be punished for?”&lt;/p&gt;
&lt;p&gt;I stubbed my cigarette against the bench’s arm without thinking, and I winced apologetically. He probably slept here, and doesn’t appreciate the bit of mess I’m making. I debate whether I let out my regrets or not. Fuck it. I’m already at this point.&lt;/p&gt;
&lt;p&gt;“My ex and I actually broke up after she got pregnant.”&lt;/p&gt;
&lt;p&gt;“Oh? Usually that’s cause for celebration, I thought.”&lt;/p&gt;
&lt;p&gt;“Yes, but I wasn’t ready. I’m not sure how to explain it. She was more of a filler in my life. Just a vessel to keep me feeling loved while I looked for someone I actually loved. I couldn’t raise a kid with her.”&lt;/p&gt;
&lt;p&gt;“Ouch, man. You never thought about someone treating you like this too?”&lt;/p&gt;
&lt;p&gt;“At the time, no. I was on top of the world, just received a promotion, and I didn’t envision myself actually settling down with her. Someone to keep me confident, keep me feeling desirable.&lt;/p&gt;
&lt;p&gt;“She wanted to keep it, but I refused to participate and kept encouraging her to get rid of it. I didn’t care that it’d been 6 years of us together. I was just focused on myself. I’d come home and start arguments almost daily, and the last few months of our relationship were often spent away from each other.”&lt;/p&gt;
&lt;p&gt;I felt the shame creeping up in my cheeks, and the tears slightly welling up as well. Family and friends were supportive about me not wanting to have kids yet, but I knew that what I did was wrong. I didn’t have the right to cry about it now. I refused the tissue I was offered and sniffled a bit.&lt;/p&gt;
&lt;p&gt;“But anyways, about a year ago, she miscarried. Probably from the stress of it all. And I’ve never heard from her since. Is this it? Is this what I’m being punished for?”&lt;/p&gt;
&lt;p&gt;“Fuck man. You’ve been through shit and you’ve put others through shit, huh. Let me see a picture of the kid again.”&lt;/p&gt;
&lt;p&gt;“I’ll do you one better. He’s a poster I made, back when I thought it was just a neighborhood nuisance playing pranks on me.”&lt;/p&gt;
&lt;p&gt;I explained the strange situation: the kid was able to be photographed, but no one could see him but me. All of my family and close acquaintances thought it was a Snapchat filter or something of the sorts, just a part of my annual elaborate April Fool’s day prank. I gave up trying to convince them after a week.&lt;/p&gt;
&lt;p&gt;“Anyways, the kid is growing older and looking more like me. It’s scary. I’m not sure I like it. Why me? What am I being punished for? I feel needles on me at all times. I’m exhausted from being vigilant all the time. I’ve resorted to dragging my bed to the window so I can watch him and fall asleep from the temporary reprieve in exhaustion I’m blessed with.&lt;/p&gt;
&lt;p&gt;“I can’t exactly stay outdoors all the time or look at him. I’ve asked for work from home for my job, and I’ve found a cafe with outdoor seating even in this cold to work from. But I’m tired. I want to stay in the warm indoors without being obligated to look at this kid. I can’t eat or go to the bathroom without multi tasking. I can’t do anything. I hate this. I hate this so much.&lt;/p&gt;
&lt;p&gt;“Is this because I threw my friend under the bus when we both got caught cheating in college? Is this because I took all the credit and got a promotion instead of my coworker who deserved it?”&lt;/p&gt;
&lt;p&gt;I buried my head in my hands and continued confessing my sins, each one being pulled out like intensely dense pieces of mucus in my sinuses. Felt better while I talked about it, but still left a bit of a hole inside me.&lt;/p&gt;
&lt;p&gt;I kept going. Then, I chose a moment to stop and look up. My fried nervous system couldn’t be bothered to get shocked. There he was, standing right in front of me. Eyes burnt black like coal. My cheekbones and ears. Nicole’s nose and smile. A man. I reached out a hand, and the apparition crumbled into dust in front of me.&lt;/p&gt;
&lt;p&gt;I looked to my side and watched the man stand insouciantly, brushing the resulting black dust off his pants.&lt;/p&gt;
&lt;p&gt;“Was that… my son? My child?”&lt;/p&gt;
&lt;p&gt;“Yes. What could have been.”&lt;/p&gt;
&lt;p&gt;“Ah. Then just a punishment, for my sin?”&lt;/p&gt;
&lt;p&gt;“You’ve committed a great many. That was just the start.”&lt;/p&gt;
&lt;p&gt;I also stood up, dusting off the remnants of the cigarette off his bench. He grunted an appreciative sound.&lt;/p&gt;
&lt;p&gt;Without a word, I followed the man to his boat. He got in effortlessly, but held out a hand to stop me from getting in.&lt;/p&gt;
&lt;p&gt;“Where’s my money?”&lt;/p&gt;
&lt;p&gt;“Oh. Yes, of course. Thanks for listening.”&lt;/p&gt;
&lt;p&gt;I almost held out the money, but a doubt stopped me.&lt;/p&gt;
&lt;p&gt;“What’s your name, if I can ask? I’m Will.”&lt;/p&gt;
&lt;p&gt;“Charon. Like ‘care’ and ‘on’ together.”&lt;/p&gt;
&lt;p&gt;“I see. Why is it two dollars? I thought it was only one coin?”&lt;/p&gt;
&lt;p&gt;“Even us deities are not free from inflation.”&lt;/p&gt;
&lt;p&gt;I laughed and held out the money, which he gracefully accepted. Compared to the past few months, I suppose death is preferable to this.&lt;/p&gt;
&lt;p&gt;I clambered into the boat, and we rowed off into the distance.&lt;/p&gt;
</content:encoded><category>Short-Story</category><author>Kushal Vajrala</author></item><item><title>Hiatus</title><link>https://kushalvajrala.com/posts/hiatus/hiatus/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/hiatus/hiatus/</guid><description>or, a dusting of my little corner of the internet, and what the future beholds.</description><pubDate>Mon, 04 Aug 2025 02:37:23 GMT</pubDate><content:encoded>&lt;p&gt;or, a dusting of my little corner of the internet, and what the future beholds.&lt;/p&gt;
&lt;h2&gt;A Recap&lt;/h2&gt;
&lt;p&gt;Hello. It&apos;s been a while since I&apos;ve last written a post for my blog. It was, at this point, more than a year ago when I was so passionate about expanding my knowledge, working on new projects, and making a bit of a name for myself. Lots of things have happened since then. Let&apos;s do a quick recap.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I used to not have a chair for my desk. I found that standing helped the creative juices flow better. It wasn&apos;t until I realized I stood for 10 hours in a row trying to fix a problem with my custom ChessGPT that I realized my feet did not appreciate the sacrifice on their part to let me continue to work and write at the pace I wanted.&lt;/li&gt;
&lt;li&gt;A few short stories have been written since then, the one I am most proud of saved on my notes app on my phone. Perhaps I&apos;ll share here one day.&lt;/li&gt;
&lt;li&gt;Many friends made, some friends lost, and existing connections grew stronger.&lt;/li&gt;
&lt;li&gt;A promotion at work! Lots more responsibility and lots more stakes assigned to me. I&apos;ve learned a lot.&lt;/li&gt;
&lt;li&gt;I got my wisdom teeth out! The procedure kicked my ass, but I&apos;m glad to have recovered from it.&lt;/li&gt;
&lt;li&gt;So so much more. If you&apos;d like to know more or want to chat, please, shoot me a text or email and I&apos;ll reach back out to you.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;The Future&lt;/h2&gt;
&lt;p&gt;I was urged by a friend (whom I started writing blogs with, you should definitely &lt;a href=&quot;https://yfralam.github.io/&quot;&gt;check him out&lt;/a&gt;. Be warned, some of it is a bit dense if you are not a Physics graduate student) to start writing blogs again. Having accountability is usually the most efficient when it is intrinsic, of course, but I greatly appreciate the external source, especially when it comes from a friend.&lt;/p&gt;
&lt;p&gt;I have come to the realization that I spend far too much time consuming and not enough time creating. I am grateful and privileged enough to live in a time period where I have both the technological means and the living conditions that allow me the opportunity to create. It seems a waste to not contribute whatever insights I have, original or not, back to the world through my corner of the internet. At the very least, if I am only helping my future self (re-setting up this blog post again was pretty easy because of what I had &lt;a href=&quot;https://vajralakushal.github.io/posts/first-blog-post/first-blog-post/&quot;&gt;written earlier&lt;/a&gt;), I will be satisfied.&lt;/p&gt;
&lt;p&gt;I want to learn. I want to grow. And, finally, I want to teach and pass on what I have learned to anyone else. I might incorporate my sports commentary or creative writing on here as well. That&apos;s okay too. I just want to get back into putting the pen to the paper (or rather, my fingertips to the keys) at a regular basis so that I am able to leave something that will be of use to anyone.&lt;/p&gt;
&lt;p&gt;Thanks for reading. I will be writing much more. Till next time.&lt;/p&gt;
</content:encoded><category>Life</category><author>Kushal Vajrala</author></item><item><title>Kanji to Hiragana</title><link>https://kushalvajrala.com/posts/kanji-to-hiragana/kanji-to-hiragana/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/kanji-to-hiragana/kanji-to-hiragana/</guid><description>or, a first timer&apos;s journey messing with chrome extensions.</description><pubDate>Thu, 25 Jul 2024 02:37:23 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;src/content/posts/kanji-to-hiragana/img/icon128.png&quot; alt=&quot;logo&quot; /&gt;
or, a first timer&apos;s journey messing with chrome extensions.&lt;/p&gt;
&lt;h2&gt;Item Summary&lt;/h2&gt;
&lt;p&gt;With this, the 日本語 learner can switch between Kanji and Hiragana seamlessly, allowing for an uninterrupted reading experience.&lt;/p&gt;
&lt;h2&gt;Item Description&lt;/h2&gt;
&lt;p&gt;When reading Japanese as a new learner, the amount of new, unknown Kanji can become overwhelming, and can make people feel frustrated with having to go away from the screen to look up words. With this extension, learners can easily switch between Kanji and Hiragana to ensure an uninterrupted reading experience. They can also toggle specific words to switch back and forth for Hiragana/Kanji. They can also simply press the button again to switch back between the two.&lt;/p&gt;
&lt;h3&gt;Usage&lt;/h3&gt;
&lt;p&gt;Let&apos;s take a page from the Aozora Bunko, for example. You can notice all of the various kanji on the screen that a new learner might not know: &lt;img src=&quot;./img/initial-screen.png&quot; alt=&quot;Initial screen before conversion&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Now, clicking on the extension will give us an option to switch between kanji and hiragana:
&lt;img src=&quot;./img/before-conversion.png&quot; alt=&quot;Extension shown before conversion&quot; /&gt;&lt;/p&gt;
&lt;p&gt;After clicking on the extension, we can see that all of the kanji have been transformed to hiragana, and the kanji that have been transformed are underlined so the user knows which hiragana belong to which word:&lt;img src=&quot;./img/converted-hira.png&quot; alt=&quot;Extension shown after conversion&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Let&apos;s click back on the very first word, to see what its original kanji was! You&apos;ll be able to click on this multiple times to switch back and forth: &lt;img src=&quot;./img/kumo.png&quot; alt=&quot;Extension shown after conversion and clicking a word&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Awesome! We can see that 蜘蛛 is くも in hiragana! Using some reading in context, maybe you could have found out that it means spider. Now, what if we want to change it back? Clicking the extension resets everything to how it was: &lt;img src=&quot;./img/reset.png&quot; alt=&quot;Extension shown after resetd&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Motivation&lt;/h2&gt;
&lt;p&gt;I didn&apos;t like having my reading experience interrupted, so I built this chrome extension. I hope you like the extension! Let me know your thoughts!&lt;/p&gt;
</content:encoded><category>SWE</category><category>日本語</category><author>Kushal Vajrala</author></item><item><title>Cart Pole</title><link>https://kushalvajrala.com/posts/basic-rl/cart-pole/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/basic-rl/cart-pole/</guid><description>or, a first timer&apos;s journey messing with reinforcement learning.</description><pubDate>Wed, 24 Jul 2024 20:35:01 GMT</pubDate><content:encoded>&lt;p&gt;or, how my love for video games and AI/ML brought me to an intersection of them with &lt;em&gt;reinforcement learning&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The information in this post is not intended to be a thorough mathematical primer on the topic. Rather, it is simply to showcase and explain a cool concept I&apos;ve learned and implemented myself, and to explain it to a layman. I will be discussing some math here and there, but I recommend the Reinforcement Learning book by Sutton and Barto if you&apos;re &lt;strong&gt;really&lt;/strong&gt; looking to get your hands dirty.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;A common prank my friends and I like to conduct is to bring people to a game of &lt;a href=&quot;https://www.instructables.com/Mao-Card-Game/&quot;&gt;Mao&lt;/a&gt;. Essentially, the uninitiated are not allowed to know the rules of this card game. They must figure it out by watching other people, and they usually end up suffering in-game penalties frequently as a result.&lt;/p&gt;
&lt;p&gt;How would you approach this game (or, for the initiated, how did you first approach this game)? I bet that when starting the game, you would do a random move and see where that gets you. You would observe when you get penalized for something, and try to associate that pattern so that you try not to let it happen again. You might guess wrong, and then try a slightly tweaked version of your move to see if it happens again. Similarly with video games, I do the same thing: see what works, see what doesn&apos;t, and try to keep doing what works and what doesn&apos;t work. Lord knows how many times that I, someone who&apos;s never played DnD before, tried to adjust my &lt;a href=&quot;https://baldursgate3.game/&quot;&gt;Baldur&apos;s Gate 3&lt;/a&gt; classes, actions, and story paths to get the most satisfying one across multiple playthroughs.&lt;/p&gt;
&lt;h3&gt;Definition&lt;/h3&gt;
&lt;p&gt;This, my friends, is the essence of &lt;a href=&quot;https://en.wikipedia.org/wiki/Reinforcement_learning&quot;&gt;reinforcement learning&lt;/a&gt;: how an &lt;em&gt;agent&lt;/em&gt; conducts &lt;em&gt;actions&lt;/em&gt; in an &lt;em&gt;environment&lt;/em&gt; to maximize its overall &lt;em&gt;reward&lt;/em&gt;. We&apos;ll get into what these terms mean in a second.&lt;/p&gt;
&lt;p&gt;A very common image that gets utilized when describing RL is as follows:
&lt;img src=&quot;./img/RL-flow.png&quot; alt=&quot;By Megajuice - Own work, CC0, https://commons.wikimedia.org/w/index.php?curid=57895741&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If you recognize what shape this takes, you are correct in assuming that this is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Markov_decision_process&quot;&gt;Markov decision process&lt;/a&gt;. If you don&apos;t, no worries.&lt;/p&gt;
&lt;p&gt;Let&apos;s break this picture down piece by piece. You have an agent (a model, a piece of code, etc.) that takes an action and interacts with its environment. Then, the agent is given two pieces of input from the interpreter (a fancy way of saying something that translates the outcomes of the action to the environment). The &lt;em&gt;state&lt;/em&gt;, which you can think of a snapshot of the environment after the action, and the reward, which is an incentive to the model. For an RL algo trading stocks, the reward in simple terms could be its profits. For checkers, the number of pieces captured. In the case of Mao, the reward would be... well. Wouldn&apos;t you like to know? We then loop this process, and keep learning.&lt;/p&gt;
&lt;p&gt;Note: the results of the prior action does not impact the probability of choosing the current action. Just a bit of a disclaimer before we move forward.&lt;/p&gt;
&lt;p&gt;By this point, I&apos;m sure you&apos;ve been understanding everything I&apos;ve said; however, one question probably still remains. &quot;How?&quot; And that, my friends, is what the next section is for. We&apos;ll discuss an algorithm that I implemented!&lt;/p&gt;
&lt;h2&gt;Q-Learning&lt;/h2&gt;
&lt;p&gt;Lots of people I know feel like this whenever they encounter/encountered a math test:
&lt;img src=&quot;src/content/posts/Basic-RL//img/jojo-gun.gif&quot; alt=&quot;LOL jojo gun&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;The Algo&lt;/h3&gt;
&lt;p&gt;Don&apos;t worry! I will do my best to walk you through the math. (If you weren&apos;t worrying at all, then that&apos;s good) Here&apos;s the equation for the algorithm we&apos;re going to cover today, Q-learning:&lt;/p&gt;
&lt;p&gt;$$Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha \left[ R_{t+1} + \gamma \max_a Q(S_{t+1}, a) - Q(S_t, A_t) \right]$$&lt;/p&gt;
&lt;p&gt;You see the $Q(S_t, A_t)$. The $Q$ is a function that we call a &lt;em&gt;Q table&lt;/em&gt;. This is defined as follows:
$$Q(s, a) = \mathbb{E}[R_t \mid S_t = s, A_t = a]$$&lt;/p&gt;
&lt;p&gt;where the inputs to the Q table are the state &lt;em&gt;s&lt;/em&gt; and action &lt;em&gt;a&lt;/em&gt; that the agent takes. The $\mathbb{E}$ refers to the expected value, $R_t$ refers to the total reward up to the timestep (basically, what point of time we are in) &lt;em&gt;t&lt;/em&gt;, and $S_t$ and $A_t$ are the state and action at timestep &lt;em&gt;t&lt;/em&gt;. What does this mean? Basically: the Q table is keeping track of the cumulative reward up to time &lt;em&gt;t&lt;/em&gt; for every (state, action) pair. Think about it: it&apos;s basically what you do in a game you don&apos;t know, right? You try something (action) in a certain situation (state) and see what that does for you (reward/no reward/sometimes negative reward). The Q table is a convenient way of keeping track of this.&lt;/p&gt;
&lt;p&gt;Now, you&apos;ll probably have seen already that the original Q learning algorithm updates itself. That&apos;s cool, right? That&apos;s how this model learns. Now that you have an understanding of the Q table, let&apos;s go into the rest of the equation.&lt;/p&gt;
&lt;p&gt;As we already covered, $Q(S_t, A_t)$ is basically the &lt;em&gt;current estimate&lt;/em&gt; of the reward for the (state, action) pair at time &lt;em&gt;t&lt;/em&gt;. What about the $\left[R_{t+1} + \gamma \max_a Q(S_{t+1}, a) - Q(S_t, A_t) \right]$? $R_{t+1}$ is essentially the reward after the action was done at timestep &lt;em&gt;t&lt;/em&gt;, and the $\gamma$ is the discount factor (we will get into this in a bit). The $\max_a Q(S_{t+1}, a)$ is giving us the maximum possible reward for the next state at timestep &lt;em&gt;t+1&lt;/em&gt; after the corresponding action was done at time &lt;em&gt;t&lt;/em&gt;; I know that was a mouthful, but basically, we&apos;re figuring out which action &lt;em&gt;a&lt;/em&gt; at timestep &lt;em&gt;t&lt;/em&gt; gives us the best reward for the next state, and we&apos;re rolling with that. The sum of these two terms is the target value. Our reward at this spot, plus the discounted future reward given that we take that action.&lt;/p&gt;
&lt;p&gt;If you&apos;ve taken a finance class before, you&apos;ve probably learned about the &lt;a href=&quot;https://www.investopedia.com/terms/t/timevalueofmoney.asp&quot;&gt;time value of money&lt;/a&gt;. Essentially, $100 today is worth more than $100 next year. Why? The simple answer is opportunity cost. However, if you aren&apos;t satisfied with that answer, or desire a more technical proof/explanation, feel free to look for one. We apply this opportunity cost with $\gamma$, our discount factor. We discount future rewards, since the present rewards are worth much more, hence the multiplication. As you can guess from the explanation, the discount factor is usually between 0 and 1, though closer to 1. We don&apos;t want to discount it TOO much.&lt;/p&gt;
&lt;p&gt;Subtracting the original $Q(S_t, A_t)$ gives us something called the *&lt;em&gt;temporal difference&lt;/em&gt; (TD) error. Basically, we&apos;re seeing how far away our current Q value in the table is to the &lt;em&gt;target value&lt;/em&gt; (which is the sum of the reward and the discounted max possible future reward that we discussed earlier).&lt;/p&gt;
&lt;p&gt;We then multiply this whole thing by the $\alpha$, the &lt;em&gt;learning rate&lt;/em&gt;. We don&apos;t want to immediately swap out our Q table values to this one! We want to gradually make our way there, because we have no idea if what we&apos;ve learned is exactly true or not. Similar to our Mao example: you don&apos;t know if the reason you didn&apos;t get penalized is completely due to you guessing the right rule. You might have gotten lucky! So you remember it, and keep an eye out for it next time, adjusting your expectations accordingly. You&apos;ve by now deduced that the learning rate is a value between 0 and 1, but closer to 0, since you don&apos;t want to update your values too quickly.&lt;/p&gt;
&lt;p&gt;Now, for the final part. You adjust the $Q(S_t, A_t)$ by adding what was in there previously with the learning rate times the TD error! This gives our Q value a little nudge in the right direction.&lt;/p&gt;
&lt;h3&gt;Implementation Explanation&lt;/h3&gt;
&lt;p&gt;But &quot;wait!&quot;, you might say. How do we even start? Looking at the diagram earlier, it looked like a never ending loop. When do we start, and when do we stop? How do we make Q values in the first place? Let&apos;s get into that too.&lt;/p&gt;
&lt;p&gt;Let&apos;s answer the easier questions first.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When we start this, we initialize our current state to 0s (or nulls, depdending on how you would like to implement this), and we initialize our Q table to have all 0s as well.&lt;/li&gt;
&lt;li&gt;Starting and stopping involves two things: number of &lt;em&gt;episodes&lt;/em&gt;, and the number of time steps per episode. What&apos;s happening here is that each episode is the number of times we let the agent explore the environment (or, more simply, play the game) and the number of time steps is essentially the total amount of time we give the agent per episode.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sure, that&apos;s all cool. But what happens if the Q table contains all zeroes? How do we even start populating it with values? That&apos;s a good question. We&apos;re going to get into something called an epsilon ($\epsilon$) greedy strategy.&lt;/p&gt;
&lt;h4&gt;$\epsilon$ Greedy Strategy&lt;/h4&gt;
&lt;p&gt;Let&apos;s go back to the initial discussion of the game of Mao. When you start playing the game, you don&apos;t know anything except what your options are, which are to essentially put a card from your hand down. That&apos;s all you know. From there, you randomly experiment and try to see what works and what doesn&apos;t work. After you&apos;ve gotten a hang of the game, however, you don&apos;t want to keep doing random stuff: you want to go ahead and try to use what you know to &lt;strong&gt;win&lt;/strong&gt;. This is known as &lt;em&gt;exploration/exploitation&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;When our agent first starts interacting with the environment, let&apos;s give it some freedom to just randomly &lt;em&gt;explore&lt;/em&gt; and try things and see what that gives it. However, as the agent gets a hang of things as it plays through a good number of episodes, we want it to &lt;em&gt;exploit&lt;/em&gt; what it has learned in its Q table for the max possible reward.&lt;/p&gt;
&lt;p&gt;This can be done through any sort of setup. It&apos;s really up to you regarding how you wish to set this up, as long as it achieves the goal of decreasing your $\epsilon$ (exploration/exploitation coefficient) over the episodes so the agent can first explore, then exploit. Here is my implementation:
$$\epsilon \leftarrow \epsilon_{\text{min}} + (\epsilon_{\text{max}} - \epsilon_{\text{min}}) \cdot e^{(-d\cdot p)}$$&lt;/p&gt;
&lt;p&gt;Where &lt;em&gt;p&lt;/em&gt; is the episode number, $\epsilon$ and $\epsilon_{\text{max}}$ start off initialized as 1, and $\epsilon_{\text{min}}$ and &lt;em&gt;d&lt;/em&gt; ($\epsilon$ decay: the rate at which the $\epsilon$ value decreases) are usually initialized to values that are between 0 and 1, but usually much closer to 0. You can probably intuit that as the episodes go on, the $\epsilon$ value decreases. But how do we use this? Simple, really.&lt;/p&gt;
&lt;p&gt;Every time step, we pick a random number between 0 and 1. If this number is greater than $\epsilon$, we just use whatever is in our Q table and make the decision from what we&apos;ve seen. However, if it&apos;s less than or equal to our $\epsilon$ value, then we just randomly pick an action and roll with it, and see what that gives us.&lt;/p&gt;
&lt;p&gt;Once again, you&apos;ll be able to intuit that the first case probably happens later on in the episodes, while the second case happens towards the beginning of the episodes. We&apos;re done with the theory!&lt;/p&gt;
&lt;h2&gt;Mess w/My Code!&lt;/h2&gt;
&lt;p&gt;You might not have a perfect grasp on the algorithm yet, especially if you haven&apos;t recently been studying or doing math. That&apos;s okay. Seeing it in code form will help you out there.&lt;/p&gt;
&lt;p&gt;We&apos;re going to be using &lt;a href=&quot;https://gymnasium.farama.org/&quot;&gt;Gymnasium&lt;/a&gt; to help us set up. We&apos;re going to be using their &lt;a href=&quot;https://gymnasium.farama.org/environments/classic_control/cart_pole/&quot;&gt;Cart-Pole&lt;/a&gt; game.
&lt;img src=&quot;./img/cart_pole.gif&quot; alt=&quot;https://gymnasium.farama.org/environments/classic_control/cart_pole/&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What&apos;s happening here, and why did I choose this environment to do Q learning in?&lt;/p&gt;
&lt;p&gt;Cart-pole is a famous intro for those who are dipping their feet into due to its simplicity. Basically, you are given a cart with a pendulum on top of it. The cart rolls on a frictionless surface. The action space (what all can the agent possibly do here?) is simple: push the cart left, and push the cart right. The objective is simple: keep the pendulum up for as long as possible. It&apos;s considered a &quot;fail&quot; if the pendulum falls below a certain angle.&lt;/p&gt;
&lt;p&gt;Here&apos;s my GitHub &lt;a href=&quot;https://github.com/vajralakushal/cart-pole/blob/main/cart-pole-q.py&quot;&gt;repo&lt;/a&gt; for my Q learning implementation of cart-pole. Read through the file, see if you can understand it and try to rewrite it yourself. I&apos;ve included some comments explaining stuff, as well as links to the documentation if you want to understand it more. Don&apos;t hesitate to leave a comment if there&apos;s anything you&apos;re confused about.&lt;/p&gt;
&lt;h3&gt;Installation/Prereqs&lt;/h3&gt;
&lt;p&gt;Last blog post was Hugo. This one is Python. Ensure that you have Python and pip installed, and then run the following commands. Note, this is assuming that you&apos;re not using conda.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;pip install gymnasium
pip install numpy
pip install matplotlib
git clone https://github.com/vajralakushal/cart-pole.git
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, cd into the directory of the cart-pole and run:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;python cart-pole-q.py
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&apos;ve given you the option to select some paramters. Once you do, the model takes some time to train, and then a pyplot window should show up, plotting the average reward of the agent across every thousand episodes. Can you come up with a set of parameters where the cart-pole survives the longest (i.e. where the graph has the highest points).&lt;/p&gt;
&lt;h2&gt;Sources&lt;/h2&gt;
&lt;p&gt;Huge shoutout to the videos in this &lt;a href=&quot;https://www.youtube.com/watch?v=my207WNoeyA&amp;amp;list=PLZbbT5o_s2xoWNVdDudn51XM8lOuZ_Njv&amp;amp;index=2&quot;&gt;playlist&lt;/a&gt;. Heavily inspired me to write my own intro to this topic. Everything else is linked accordingly.&lt;/p&gt;
&lt;h2&gt;Thanks!&lt;/h2&gt;
&lt;p&gt;Thanks for reading! Feel free to leave any comments if you have any!&lt;/p&gt;
</content:encoded><category>Reinforcement-Learning</category><category>AI/ML</category><author>Kushal Vajrala</author></item><item><title>Pilot</title><link>https://kushalvajrala.com/posts/first-blog-post/first-blog-post/</link><guid isPermaLink="true">https://kushalvajrala.com/posts/first-blog-post/first-blog-post/</guid><description>or, a first timer&apos;s journey messing with static sites.</description><pubDate>Thu, 18 Jul 2024 03:48:20 GMT</pubDate><content:encoded>&lt;p&gt;or, a first timer&apos;s journey messing with static sites.&lt;/p&gt;
&lt;h2&gt;What is Hugo?&lt;/h2&gt;
&lt;p&gt;I&apos;ll just &lt;a href=&quot;https://gohugo.io/&quot;&gt;link&lt;/a&gt; them for you and save you the trouble of having to read my own paraphrasing. I can&apos;t resist, however: it&apos;s essentially an open source service that helps you generate static websites. Documentation, blogs, portfolios, you name it. I was inspired by &lt;a href=&quot;https://zoriya.dev/&quot;&gt;Zoe&apos;s&lt;/a&gt; blog and wanted to create my own.&lt;/p&gt;
&lt;h2&gt;The Goal&lt;/h2&gt;
&lt;p&gt;This blog post is essentially a letter to my past self. If I had this blog post maybe a few hours earlier, I could&apos;ve saved myself a lot of headache.&lt;/p&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;Currently, I&apos;m working out of my Windows PC, so I&apos;ll go over this part assuming you are doing the same. If not, refer to this &lt;a href=&quot;https://gohugo.io/installation/&quot;&gt;site&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;[ ] Ensure that &lt;a href=&quot;https://chocolatey.org/&quot;&gt;Chocolatey&lt;/a&gt;, a windows package manager (similar to brew on MacOS or pacman on Arch. I do not use Arch btw). Same thing with &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/package-manager/winget/&quot;&gt;Winget&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[ ] Funnily enough, same thing with &lt;a href=&quot;https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4&quot;&gt;Powershell 7&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;[ ] Run this command, but in Powershell 7: &lt;code&gt;choco install hugo-extended&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Site Creation&lt;/h2&gt;
&lt;p&gt;Yay! Everything has been installed and is ready to go. I use VS code just because the files are not as numerous to where I would need to use neovim or anything, but use whatever you&apos;re comfortable with. Just make sure to use Powershell 7 as your shell here on out.&lt;/p&gt;
&lt;p&gt;Check to see if Hugo was installed correctly with &lt;code&gt;hugo version&lt;/code&gt;. At the time of this post, it should be around 0.129.0.&lt;/p&gt;
&lt;p&gt;Here comes the tricky part. To be fair, it was only tricky for me simply because I already had the makings of a barebones Next.js website, but I was tired of the learning curve. I&apos;ll definitely come back to it one day, but Hugo just provided an easier option.&lt;/p&gt;
&lt;p&gt;Create a repository on GitHub and name it &quot;username.github.io&quot;. (Does the period go inside the quotations or outside? It looks better inside but logically it feels better outside). Clone into this repo. Now, here&apos;s where the fun begins.&lt;/p&gt;
&lt;p&gt;Navigate into the repo you just cloned and run this line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;hugo new site example.com
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, we&apos;ll do a bit of configuring here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;mv \example.com\* .
mv \example.com\.* # should be redundant, but eh why not
rmdir \example.com\
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you look at your directory now, it should look like this&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;src/content/posts/first-blog-post/images/hugo-new-site.png&quot; alt=&quot;directory after Hugo new site&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Great! Now, we can set up your hugo.toml as you wish. Add a title param in your hugo.toml file (anywhere inside works, as long as it&apos;s not part of a param):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;title = Kushal Vajrala
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Explore the different configs you can use. From here on out, it&apos;s just a matter of finding out your favorite &lt;a href=&quot;https://themes.gohugo.io/&quot;&gt;theme&lt;/a&gt;: install and run for it!&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;very&lt;/em&gt; adventurous will probably stop reading here, and go tinker on their own now that things are set up somewhat. However, I&apos;m not totally sure that when I was working on this earlier. Let&apos;s use the theme that I&apos;m using for this tutorial, &lt;a href=&quot;https://themes.gohugo.io/themes/hugo-coder/&quot;&gt;hugo-coder&lt;/a&gt;. I was able to set up my stuff pretty fast with this clean, minimalist theme.&lt;/p&gt;
&lt;p&gt;I would really rather not rewrite the download instructions they&apos;ve so kindly given, so make sure you read and implement carefully. I recommend installing it as a git submodule.&lt;/p&gt;
&lt;h2&gt;Showing off your literary masterpieces&lt;/h2&gt;
&lt;p&gt;Now, here&apos;s where the fun (really, the writing) begins!&lt;/p&gt;
&lt;p&gt;Assuming that you followed their example config setup, let&apos;s go into making posts! Your content directory should have a posts directory within it. If it doesn&apos;t, go create that.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;src/content/posts/first-blog-post/images/yare-yare.gif&quot; alt=&quot;me disappointed that it doesn&apos;t&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Ensure that in your hugo.toml file, you have this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[[menu.main]]
  name = &quot;Blog&quot;
  weight = 1
  url  = &quot;posts/&quot;
[[menu.main]]
  name = &quot;About&quot;
  weight = 2
  url  = &quot;/about/&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I changed mine around a bit, because I just wanted one singular about page. For now, run the following lines:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;hugo new \content\posts\hello-world.md
hugo new \content\about.md
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You&apos;ll see that the files already come populated with some stuff in between some +++. These are essentially metadata that the theme utilizes to showcase and tag your posts. The prepopulated stuff can be found in the archetypes folder. Kudos to you if you explored a bit and found that out. It uses some regex to properly capitalize and figure out what to title your article. Fill the created files out to your desire.&lt;/p&gt;
&lt;p&gt;Now, run&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;hugo server
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and navigate to the localhost link that it gives you! Ta-da! Your website it almost done! If you want to deploy it with GitHub pages like I have, go through the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Push all of your changes and note which branch you used&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hugo version&lt;/code&gt; to see which version of hugo was installed&lt;/li&gt;
&lt;li&gt;Follow the instructions &lt;a href=&quot;https://gohugo.io/hosting-and-deployment/hosting-on-github/&quot;&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Navigate to your website, and there you go! It&apos;s all done.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;I hope this helped you out! If you have any questions, feel free to reach out to me!&lt;/p&gt;
</content:encoded><category>SWE</category><author>Kushal Vajrala</author></item></channel></rss>