<?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 Ramit Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Ramit Agarwal on Medium]]></description>
        <link>https://medium.com/@ramitphi?source=rss-880a1272149b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*COUoc_HBWjNMvNIG1W6E4Q.jpeg</url>
            <title>Stories by Ramit Agarwal on Medium</title>
            <link>https://medium.com/@ramitphi?source=rss-880a1272149b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:29:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramitphi/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[What Referrals Taught Me About Building Incentives]]></title>
            <link>https://medium.com/@ramitphi/what-referrals-taught-me-about-building-incentives-bc8e118b2d93?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc8e118b2d93</guid>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[rewards]]></category>
            <category><![CDATA[referrals]]></category>
            <category><![CDATA[product-management]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Tue, 30 Jun 2026 22:55:57 GMT</pubDate>
            <atom:updated>2026-06-30T23:17:07.031Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A product lesson on why referral rewards did not drive participation, and how we redesigned incentives around meaningful activity.</blockquote><p>There was a time when we launched a product similar to Clubhouse for people in the Web3 and blockchain social network space. Like most early products, our first problem was traction. We wanted more people to come in, try the product, and create enough activity for the network to feel alive.</p><p>So we started with referrals. We gave referral links to specific users and attached rewards to them. The thinking was simple: if someone referred more people, they would earn more.</p><p>In our heads, the incentive felt aligned. Bring people in, grow the network, earn rewards. We also assumed that the top users of the product would naturally be the ones referring more people, but that is not what happened.</p><h3>Referrals did not map to participation</h3><p>Over time, we noticed that the users with the highest referrals were not necessarily the most active users inside the product. Some people were good at bringing users in, but they were not hosting rooms, spending time in conversations, or creating much activity inside the product.</p><p>This created a subtle but important problem. The people who were actually active, the ones spending time in rooms and helping the product feel alive, started feeling that they were not being incentivized fairly.</p><p>And they were not wrong.</p><p>We were rewarding acquisition, but what the product actually needed was participation.</p><p>That was the first big learning for me:</p><blockquote><em>A metric can look right from a growth lens and still feel wrong inside the product.</em></blockquote><h3>Redesigning the incentive</h3><p>In the next season, we tried to redesign the incentive system around participation. The obvious metric was minutes spent. If people were spending more time in the product, that probably meant the product was getting more useful.</p><p>But rewarding minutes directly would have been too naive. People could stay online without adding value, or create low-quality activity just to increase time spent.</p><p>At the same time, we did not want to ignore the value of bringing valuable people into the system. The original referral idea had one useful instinct: distribution matters. But it needed to be connected to actual participation.</p><p>So instead of rewarding referrals directly, and instead of rewarding minutes blindly, we made the room the main unit of reward.</p><h3>The mechanism</h3><p>Each room got a score based on the sum of each participant’s contribution:</p><pre>sum of (minutes spent by a participant × that participant&#39;s social score)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*0UVWKXon7_2j8_x-UmxKog.gif" /><figcaption>How rewards flow from room-level participation to hosts and listeners.</figcaption></figure><p>Every participant already had a social score assigned by the network we were building on. So the score of a room depended on who spent time in it, how much time they spent, and the social score of each participant.</p><p>A room where high-social-score participants spent meaningful time would get a higher score. A room with low participation would not get much reward just because it existed. And simply bringing someone into the product was not enough unless that person actually participated.</p><p>Once every room had a score, we normalized room scores across all rooms. From the total reward pool, each room received rewards proportionate to its contribution.</p><p>Then, inside each room, we split the reward into two parts. If a room earned reward X:</p><ul><li>30% went to the host</li><li>70% went to the listeners</li></ul><p>The listener rewards were also not split equally. A listener’s share depended on their own contribution to that room’s score, which came from their time spent and their social score.</p><p>This made the incentive more aligned. Hosts were rewarded for creating rooms where valuable participation happened. Listeners were rewarded for actually spending time in those rooms. And bringing high-value users into the product mattered only if they actually showed up and participated.</p><h3>What changed</h3><p>After this change:</p><ul><li>new users increased by 15%</li><li>minutes spent increased by 34%</li><li>avg DAU remained the same</li></ul><p>The interesting part was not just that the numbers moved. It was how they moved. DAU staying the same meant we had not simply created a larger daily active base. Instead, the same daily active base was spending more time.</p><p>That made the incentive change feel more connected to depth of participation than just surface-level activity.</p><h3>The learning</h3><p>The biggest learning for me was that incentives shape behavior very directly. Users do not just respond to rewards. They also interpret what the product values through them.</p><p>If you reward referrals, people optimize for referrals. If you reward minutes blindly, people optimize for minutes. But if you want meaningful participation, the reward system has to be built around how value is actually created inside the product.</p><p>Earlier, I thought referrals would naturally map to contribution. They did not.</p><p>Now when I think about incentives, I try to think from the bottom up:</p><ul><li>Who is creating value?</li><li>How is that value being created?</li><li>If users optimize perfectly for this reward system, will the product become better or worse?</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc8e118b2d93" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Dune Analytics to analyze any smart contract]]></title>
            <link>https://medium.com/@ramitphi/how-to-use-dune-analytics-to-analyze-any-smart-contract-5b8669fabaa6?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b8669fabaa6</guid>
            <category><![CDATA[dune-analytics]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[dashboard]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Mon, 29 Jun 2026 00:44:04 GMT</pubDate>
            <atom:updated>2026-06-29T00:44:04.344Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A practical, end-to-end walkthrough: fetch the ABI, find the right decoded tables, write Dune SQL, and turn it into a live smart contract dashboard. We cover the same workflow our tool automates, so you can either build it yourself or skip ahead.</blockquote><p>Shortcut <br>Skip the SQL: generate a dashboard automatically,<strong> t</strong><a href="https://onchainwizard.ai/"><strong>ry it here</strong></a></p><h3>What is Dune Analytics?</h3><p>Dune Analytics is a blockchain data platform that indexes raw and decoded data from major EVM chains — Ethereum, Polygon, Arbitrum, Optimism, Base, BNB Chain, Avalanche, and more. Instead of running your own node, you query the chain with SQL (DuneSQL, a Trino dialect) and turn the results into charts and dashboards. It is the de facto tool for on-chain analysts, DeFi teams, and protocol researchers.</p><h3>Step 1 — Get the contract address and ABI</h3><p>Every analysis starts with two inputs: the contract address and its ABI (Application Binary Interface). The ABI describes every function and event the contract exposes — without it, raw logs are opaque hex blobs.</p><ul><li>Open the contract on a block explorer (Etherscan, Polygonscan, BaseScan, etc.).</li><li>Confirm the contract is <em>verified: </em>verified contracts publish their source and ABI.</li><li>Copy the ABI JSON from the explorer’s <em>Contract</em> tab.</li></ul><h3>Step 2 — Find decoded tables on Dune</h3><p>Dune decodes verified contracts into per-event and per-call tables. The naming pattern is project_chain.contract_evt_EventName for events and project_chain.contract_call_FunctionName for calls. If the contract is not yet decoded you can fall back to ethereum.logs and decode topics manually, but decoded tables are far easier to work with.</p><h3>Step 3 — Write Dune SQL for contract events</h3><p>Here is a typical Dune SQL query: daily count of Transfer events on an ERC-20 contract for the last 365 days.</p><pre>SELECT<br>  date_trunc(&#39;day&#39;, evt_block_time) AS day,<br>  COUNT(*)                          AS transfers,<br>  COUNT(DISTINCT &quot;from&quot;)            AS unique_senders<br>FROM erc20_ethereum.evt_Transfer<br>WHERE contract_address = 0xYourContractAddressHere<br>  AND evt_block_time &gt;= NOW() - INTERVAL &#39;365&#39; DAY<br>GROUP BY 1<br>ORDER BY 1</pre><p>A few practical tips that save credits and time:</p><ul><li>Always filter on block_time as Dune partitions by time, so unfiltered queries scan years of data.</li><li>Cast addresses with the 0x… literal directly; do not wrap them in quotes.</li><li>Use date_trunc for timeseries, never bucket in the client.</li><li>Prefer decoded tables over raw logs when available.</li></ul><h3>Step 4 — Build a dashboard</h3><p>Once a query runs, Dune lets you attach a visualization like line chart for timeseries, bar chart for distributions, a big-number tile for KPIs. Pin those charts to a dashboard, share the URL, and you have a live view of the contract that refreshes on a schedule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DK2Zs9XcSl3T42C_t8wxg.png" /></figure><h3>Common queries to start with</h3><ul><li>Daily active users (distinct tx_from on calls).</li><li>Top 10 functions called, by count and by gas spent.</li><li>Cumulative event volume over time.</li><li>Wallet cohorts — new vs. returning users per week.</li><li>Notional volume by event amount × token price (joining prices.usd).</li></ul><h3>Or skip the SQL entirely</h3><p>Writing this by hand for every contract takes hours. On-chain Wizard automates the full pipeline — paste an address, pick a chain, and we fetch the ABI, identify decoded tables, generate the Dune SQL with an LLM, execute it, and render the dashboard. Free, no signup.</p><p><a href="https://onchainwizard.ai/"><strong>Generate a dashboard</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b8669fabaa6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Bigram Language Model From Scratch]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@ramitphi/building-a-bigram-language-model-from-scratch-87d8d35de96e?source=rss-880a1272149b------2"><img src="https://cdn-images-1.medium.com/max/1256/1*fZDnkCRclIzFxcTgbw0oyA.png" width="1256"></a></p><p class="medium-feed-snippet">Understanding probabilities, negative log-likelihood, and a tiny neural network by generating new names</p><p class="medium-feed-link"><a href="https://medium.com/@ramitphi/building-a-bigram-language-model-from-scratch-87d8d35de96e?source=rss-880a1272149b------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ramitphi/building-a-bigram-language-model-from-scratch-87d8d35de96e?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/87d8d35de96e</guid>
            <category><![CDATA[makemore]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Thu, 25 Jun 2026 12:07:59 GMT</pubDate>
            <atom:updated>2026-06-27T21:26:28.721Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Object Localization and Object Detection]]></title>
            <link>https://medium.com/@ramitphi/object-localization-and-object-detection-b936c7dff8ce?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b936c7dff8ce</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[object-localization]]></category>
            <category><![CDATA[yolo]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Sun, 19 Jul 2020 12:03:16 GMT</pubDate>
            <atom:updated>2020-07-19T12:03:16.618Z</atom:updated>
            <content:encoded><![CDATA[<p>So you will be thinking about what is the difference between Image Classification, Image Localization, and Detection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tHjG8PPvYgnbvhb-" /></figure><p>Classification: Classifying the image based on the whole input image.</p><p>Localization: It means to draw a bounding box around the specific object we are interested in and also classifying the image based on that object.</p><p>Detection: When there are multiple objects present in the image and we want to individually identify them with the help of a bounding box.</p><h3>Classification with Localization</h3><p>For performing the task of object localization we will feed our input image in a <strong><em>convNET </em></strong>and in the last layer we will output a vector comprising of the class probabilities(p_c) and the bx, by,bw,bh which will help us to draw the bounding box around the identified object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TiLQloZpI-1deou9" /></figure><p>So how our output y exactly looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AZTSTxKxJ47FwFIl" /></figure><p>The image can have these 4 possible classes but for this explanation, we have only considered only the top three class i.e. <strong>pedestrian</strong>, <strong>car, </strong>and <strong>motorcycle</strong>.</p><p>Y is a vector with the first element ‘<strong>p_c<em>’</em></strong> representing the probability that the object is present in the image.</p><p><strong>bx, by,bw,bh</strong> gives the information about the bounding box</p><p>The last three-element, represent the classes among which one will be equal to 1 based on the object identified</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-lRSYmw2OaJ0DCTf" /></figure><p>In the first image, a car is present and our network has been able to detect <em>an object </em>so it gives the <strong>p_c </strong>value equal to 1, and depending on the position of the object it will output the values of <strong>bx, by,bw,bh.</strong></p><p>In the second image, no object is present there so the <strong>p_c </strong>value has I equal to zero and all other values have been ignored because if the object is not present there then we don&#39;t need them.</p><h3>Object Detection</h3><h4>Sliding window technique</h4><p>In this technique we will have a sliding window that will be traversing the image and the image overlapped by that window will be feed to the neural net and it will generate an output vector like the same we discussed above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZxYsRQpL8wFHUC0L" /></figure><p>We can perform a sliding window with several different window size but this method involves high computational course so this is not that much feasible to use this can decrease a bit if are able to choose an optimal sliding window but that not works all time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PBNehm-0AmYiX7MT" /></figure><p>To reduce the computational cost we can use the convolutional layer instead of the fully connected layer at the end of our neural network</p><p>Generally, the fully connected layer gives activation value and that value is used to feed to sigmoid layer to get the class probability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YescfoSCsf-mInp_" /></figure><p>But now, we will be using the convolutions at last layer and using that we will get a 3d matrix of shape “2 x 2 x 4” so it will be computing the result of sliding values for 4 cells parallelly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IZlkRxLP83Q9K002" /></figure><p>Another method that gives us a more accurate result is YOLO Algorithm.</p><h3>YOLO Algorithm</h3><p>In this algorithm, we divide the images into grid of some size</p><p>For this explanation, we have divided the image into a “3 x 3” grid though in the original paper a “19 x 19” grid was used.</p><p>In this algorithm, we will apply the concept of object classification and localization on each of the grid to detect whether an object is present or not</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yZvHKtsDb9bbSycg" /></figure><p>For each grid, there is a vector associated with it which give us the information about that grid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tQ5h02iYF3MI1v0R" /></figure><p>We will feed each grid to the convNET for identifying whether there is an object present or not present in that grid</p><p>If the image is not present then the output vector will have<strong> p_c =0</strong> and all other values do not hold any value</p><p>If the object is present in the grid then the output vector will be having p_c value equal to <strong>1 </strong>and bx, by,bh, bw will be given according to the position of the object in that grid and that particular class value is set to 1.</p><p>If the object appears in different grids then the object is assigned to that grid which contains the midpoint of that object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EUgs6flsyCwEPPvF" /></figure><h4>Specifying the Bounding Boxes</h4><p>bx, by : These are the coordinates of the midpoint of the detected object it is defined with respect to the grid which is assigned to that particular object, they can only have a value between 0 and 1</p><p>bh,bw: It specifies the height and width of the object it is also with respect to the grid which is assigned to that object and it can have values greater than 0 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lm1YLIoSOiPgEVyH" /></figure><p>This implementation of object detection and classification works fine until only one object is specified to a grid if multiple objects are present in the grid then we have to look for other methods</p><h3>How well we have performed</h3><p>We need to evaluate how well we have been able to perform the tasks of object localization for this purpose, we will be using the concept of the “Intersection over Union”</p><p>The<em> red box</em> depicts the perfect bounding box that should be predicted by the neural net</p><p>The <em>purple box </em>depicts the bounding box that has been predicted by the neural net</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2rzIoMjcIF4WHUiF" /></figure><p>We will be computing the ratio of the “intersected area” and the “total union area” to get an idea of how well we have been able to predict the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dmUOxvQW7M5QvQ92" /></figure><p>The area with “<em>yellow shade” </em>represents the common area and the area in “<em>green </em>shade” represents the total union area so the ratio of both gives us the IoU.</p><p>An IoU greater than 0.5 is considered to be good.</p><h3>Non-Max Suppression</h3><p>As we divide the image in multiple grids practically it may be possible that the more than one grids get assigned the same object, so in that case, multiple bounding boxes will be drawn so to avoid this situation we will use the method called “non-max suppression”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eHEt-bz3OJpspMSY" /></figure><p>It will start looking like this then different grids will output different bounding boxes with different values of p_c</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PM2D_UZ9_OfpPQ_k" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mARcHBaPWKCUcHQp" /></figure><p>We will consider all the prediction given by the grids respectively with positive p_c value then afterward we will discard all those bounding boxes whose p_c value is less than 0.6 this will eliminate most of the less accurate bounding boxes</p><p>After performing the above task it may be possible that we have left with some boxes so to eliminate them</p><p>First, we will select a box with highest p_c value and output it as a prediction</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RGhEy-WH4rRc7ODw" /></figure><p>Then we will calculate its IOU with all other remaining boxes whose p_c are less than our chosen box and the boxes having IOU higher than 0.5 will be eliminated</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7pU1KcKaP7tKKqWU" /></figure><p>This way we will be able to delete all the redundant boxes</p><p>Another problem we can face is that two different objects are assigned to the same grid so to deal with it we will use the concept of anchor box</p><h3>Anchor Box</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SUzAML7vr2oicf81" /></figure><p>In the above image, we can see that the man and the car both have midpoints lying in the same grid</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qvjeN_j369DskTJ6" /></figure><p>Typical output vector of a grid looks like this but in case of two objects assigned to the same grid this approach fails so we have to look for another approach</p><p>We can use the concept of anchor boxes We can define different anchor boxes such that each one covers and different image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ic2QfY4YMHpkdaJV" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b936c7dff8ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Of Neural Style Transfer]]></title>
            <link>https://medium.com/@ramitphi/basic-of-neural-style-transfer-7475d752e7f5?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7475d752e7f5</guid>
            <category><![CDATA[deeplearningai]]></category>
            <category><![CDATA[neural-style-transfer]]></category>
            <category><![CDATA[convolutional-neural-net]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 17:19:47 GMT</pubDate>
            <atom:updated>2020-06-01T17:19:47.968Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this blog, we have discussed basic concepts of the Neural Style Transfer and initiation and motivation has been taken from deeplearning.ai specialization course on deep learning</blockquote><h3>What is Neural Style Transfer?</h3><p>Neural style transfer is an optimization technique used to take two images — a <em>content</em> image and a <em>style reference</em> image and combine them so the output image looks like the content image, but “painted” in the style of the style reference image.</p><p>This is implemented by optimizing the output image to match the content statistics of the content image and the style statistics of the style reference image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/0*0yaVqp4s1g7KWRM1" /></figure><p>The image on which we want to <em>apply the style</em> we will call that <strong>Content(C) </strong>and the image from which we will <em>take the style</em> we will call that image <strong>Style(S)</strong> and finally the obtained image after applying the style to the content image we will call that image <strong>Generated image(G)</strong></p><p>We will be using <em>convNET </em>for the implementation of neural style transfer</p><p>Now you will be thinking how <em>convNET </em>will be helpful for such problems so here is the explanation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u5qJQEwVXErBJXp7" /></figure><p>In <em>convNET</em>, each layer captures unique feature from the given input image so considering the middle layer of a deep <em>convNET </em>we can get the idea of the style present in that image which can be used to create a new image from the content image</p><h3>Defining the loss</h3><p>To measure how well we have been able to combine content and style we will be needing a loss function which will tell us how much our generated image is different or similar to the content and style image</p><p>We will be defining the loss for our model so we can update the parameter based on the optimization of that loss</p><p><strong>J(G):</strong> Total loss</p><p><strong>J_content(C, G):</strong> Content loss (Measures the difference between generated image and content image)</p><p><strong>J_style(S, G)</strong>: Style loss (Measures the difference between generated image and style image)</p><p>We will first initiate a randomly <strong>generated image(G) </strong>and then we will update the pixels such that the total loss minimizes</p><blockquote><strong>J(G) = J_content(C,G) + J_style(S,G)</strong></blockquote><h4>Defining Content Loss</h4><p>We will choose the activation values of layer l of content image and generator image respectively</p><p>Let <strong>al_c </strong>and <strong>al_g </strong>be the activation of the respective layer</p><p>If both images are same then the difference between the two images would be less</p><h4>Calculating the loss</h4><p>So we will define loss as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/0*xMYHnreMYxMN-Vxc" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*9IStu_Pjl4p5U4fXt2w9Nw.png" /></figure><h4>Defining Style loss</h4><p>First, of we will understand how we can interpret the style of image, for interpreting the style of the image we will select a layer “ <strong>l ” </strong>from our deep CONVnet and then we will calculate the correlation between the activation across the channel</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XymE_wl-nJrKtyYCOpO96w.png" /></figure><p>Now you may be thinking how it gonna tell us about the style of image</p><p>We can say that each channel of the layer captures some of the styles present in an image.</p><p>Considering the two encircled grid shown in the screenshot below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p8EEGDU3ajTJO_qQ" /></figure><p>If two channels are highly correlated then if one style is present with some intensity then the other style will also be present with that same intensity as each channel tends to capture the different style</p><p>So the correlation matrix between the channels will give us a good idea about their style, a similar operation will also be done for the generated image</p><p>Then we will make the difference of the correlation matrix obtained from style image (S) and generated image(G) so we can assess how well we have been able to use the style in our generated image(G)</p><p>We will compute the correlation in the following way it is also called gram matrix</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JlCBOyzAMh7RYTrZ" /></figure><p>The matrix with superscript (S) represents the gram matrix of the style matrix and matrix with superscript (G ) represent the gram matrix of the generated image</p><h4>Calculating the loss</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eK1oHfJLOCnou1zw" /></figure><p>The layer whose activation values we have used is represented by “ l ”.</p><h3>Total Loss</h3><p>The total loss will be the summation of the content loss and style loss “<em>alpha” </em>and “<em>beta” </em>will act as hyperparameter</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/0*idNun8PEBZv3kd7p" /></figure><p>This we will be our total loss we will calculate the total loss then we will backpropagate to minimize the loss in a way to find the optimal parameters which will be minimizing the loss</p><p>PS- All the slide have been taken from deeplearning.ai course for a good explanation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7475d752e7f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performing Convolution On a Matrix]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@ramitphi/performing-convolution-on-a-matrix-4682fd364591?source=rss-880a1272149b------2"><img src="https://cdn-images-1.medium.com/max/1167/0*o1hzsn9r_wsVyqXz" width="1167"></a></p><p class="medium-feed-snippet">In this blog, we will be discussing about performing convolution on a 2D image matrix based on the intution from the deeplearning.ai CNN&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@ramitphi/performing-convolution-on-a-matrix-4682fd364591?source=rss-880a1272149b------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@ramitphi/performing-convolution-on-a-matrix-4682fd364591?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4682fd364591</guid>
            <category><![CDATA[deeplearningai]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Fri, 29 May 2020 17:26:22 GMT</pubDate>
            <atom:updated>2026-06-27T10:54:10.954Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Image Segmentation Using Fastai]]></title>
            <link>https://medium.com/@ramitphi/image-segmentation-using-fastai-32d01318605b?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/32d01318605b</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[image-segmentation]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[fastai]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Sun, 10 May 2020 14:40:12 GMT</pubDate>
            <atom:updated>2020-05-10T14:40:12.687Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>As I have been exploring the fastai course I came across image segmentation so I have tried to explain the code for image segmentation in this blog</blockquote><h3>Starting with….</h3><p>We have imported the required libraries using the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*voRz4y8hxo2iYSWXYm9itg.png" /></figure><p>To get the data we have used to untar_data method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3D8M65HHBJGk5Z0-zPTSCA.png" /></figure><p>URLs.CAMVID give us the dataset named “CAMVID” which can be used for image segmentation problems</p><p>The untar_data data function body is like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JE4_FwiIS_kKuScpTG83lw.png" /></figure><blockquote>In general, <a href="https://docs.fast.ai/datasets.html#untar_data"><em>untar_data</em></a> uses a <em>url</em> to download a <em>tgz</em> file</blockquote><p>untar_method has returned the path of the datasets which we have stored in a variable path</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*ZB1XVjszARHYrvJAMQXdMQ.png" /></figure><p>We will then make a variable that contains the path of labels and another variable that contains the path for images</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*7NZ9XnUl7Cx6wDERZ31rdA.png" /></figure><p>Now we will get the path to image files from path_img using the code below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M1Ou9K3Jijd7cFziCxos4A.png" /></figure><p>Similarly, we will get the path to label files from path_lbl using the code below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vnt3ZTACj5FmTlVVqj-pig.png" /></figure><p>The get_image_files fetch us the image files from the path we have specified</p><p>The get_image_file looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ci88OnJ6zwwxFd6BZvdEw.png" /></figure><p>There are segmented image available in the labels folder for each image present in the image folder</p><p>So for the image file with the following name</p><blockquote>PosixPath(‘/home/ubuntu/.fastai/data/camvid/images/0001TP_008160.png’)</blockquote><p>The path of the respective segmented image file will be</p><blockquote>PosixPath(‘/home/ubuntu/.fastai/data/camvid/images/0001TP_008160_P.png’)</blockquote><p>So till now, we have a path of <strong><em>image files</em></strong> stored in the variable named <strong><em>fname </em></strong>and path of the <strong><em>segmented image file</em></strong> stored in a variable named <strong><em>lbl_names</em></strong></p><p>Then we will use one image file’s path to open it and see an example of our dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*iqCc-2TFQH1R2xe40u2oeQ.png" /></figure><p>Now we will see an example respective segmented image</p><p>We have written a custom function to get the particular image from the pth_lbl which contains the segmented image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*xiKME5lhAsMZV9XhhBr4wA.png" /></figure><p>We have used the lambda expression for obtaining the respective file name of the segmented image</p><p>x.stem: gives the filename without the extension</p><p>x.suffix: gives the extension of the filename</p><p>More about x.stem and x.suffix can be read from <a href="https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.stem">here</a></p><p>Next, we will open the respective segmented image using the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*thbHxy6DU2YQPkMgXwfReA.png" /></figure><p>As you can observe we have use open_mask to open the image</p><p>open_mask: The open mask is used to open the segmented image the same way the open image is used to open an image.</p><p>More about open_mask can be read from <a href="https://docs.fast.ai/vision.image.html#open_mask">here</a></p><p>Now we will load all the “codes” of the different objects according to which they have been segmented</p><p>Our codes have been stored in the file named codes.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3MrZl8NzdPCENb_9eF7hw.png" /></figure><p>Now we need data to feed to our model so we will create a Segmentation item list as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*OTeMZ0NsOCjqLxg_XjjVGg.png" /></figure><p>Our images have been stored in the folder path_img so we will use from_folder</p><p>We will split some images of image dataset, to validation dataset based on the filenames of the images present in valid.txt</p><p>The segmented images will be the labels which are present in the <strong>pth_lbl</strong> with the help of the function we created, we will be able to map them with their respective original image</p><p>Finally, we will apply some transformations to the images</p><p>Now we will see our data batch</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*S9UCfSYEleE7OaVBvGcgeQ.png" /></figure><p>Now we will enumerate our codes of the objects</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*A0a7rtq6HmO1MnxyisJI5w.png" /></figure><p>This is done so we can asses our model based on our custom metrics for which our object classes need to be converted to numbers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*SN0HNjfW8ChgeZ2YXTUaUA.png" /></figure><p>Our custom metrics is as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*EdDRNhNALm2FxQrEA8jgMw.png" /></figure><p>Building a Model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TwHjrJRXTU-fCR1Bn-y5w.png" /></figure><p>We have used unet learner more about unet learner can be found <a href="http://deeplearning.net/tutorial/unet.html">here</a></p><p>data: data on which we want to fit model</p><p>models.resnet34: We used a pre-trained resnet34 model</p><p>metrics: It is the metrics which evaluates the model we defined our custom metrics above</p><p>wd: It is the weight decay, it prevents the overfitting</p><p>Now to finetune our model we will calculate the losses for different learning rate and based on the plot obtained we will select our learning rate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*H1U96Jbs4cLf7-fzRahFxw.png" /></figure><p>We look for the range when there is a steep decrease in the graph as we can observe graph is steepest between 1e-04 and 1e-03 so we have chosen 3e-03 as the max learning rate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*1rden1g2vPt0spB74iGUew.png" /></figure><blockquote>Parameters</blockquote><p>10: It is the number of epochs</p><p>slice(lr): It is the learning rate</p><p>pct_strt: It represents how much of percentage of the one_cycle we want to give it to increasing lr</p><p>To learn more about fit_one_cycle , you can refer to <a href="https://iconof.com/1cycle-learning-rate-policy/">this</a></p><p>We can observe from results that we have achieved the accuracy of 90.1%</p><p>Let’s see the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*96NpoR5jTcgzMj8zGZnTCQ.png" /></figure><p>Results show that the people riding the bicycle has not been segmented properly</p><p>So we try to again fine-tune our model by changing the number of epochs, learning rate, and pct_start</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*C1suUoKzzdyKfes5C2ozYA.png" /></figure><p>Now the accuracy has increased to 92.1%</p><p>Let us now again see the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*h71mV7KfVO7zUaNAOnVyeQ.png" /></figure><p>Now the results look much satisfactory</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32d01318605b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Classification USing Fast.Ai Classifying “Dhaniya” or “Pudina”]]></title>
            <link>https://medium.com/@ramitphi/image-classification-using-fast-ai-classifying-dhaniya-or-pudina-89eab6fe1760?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/89eab6fe1760</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[fastai]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Thu, 30 Apr 2020 18:54:04 GMT</pubDate>
            <atom:updated>2020-04-30T19:01:10.237Z</atom:updated>
            <content:encoded><![CDATA[<h3>Image Classification Using Fastai: Classifying “Dhaniya” or “Pudina”</h3><blockquote>In this problem, I tried to classify between “dhaniya” and “pudina” which sometimes becomes a problem for a common people so I tried to solve it using fast.ai vision library</blockquote><h3>Importing libraries</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*GT8mp6h7O66lWUwRRLjqkA.png" /></figure><h3>Collecting Data</h3><p>We will be google images for our dataset</p><p>First, we will search for the terms “dhaniya” then going to the image section of that object we will press Ctrl+Shift+j and then enter the following code</p><pre>urls=Array.from(document.querySelectorAll(&#39;.rg_i&#39;)).map(el=&gt; el.hasAttribute(&#39;data-src&#39;)?el.getAttribute(&#39;data-src&#39;):el.getAttribute(&#39;data-iurl&#39;));</pre><pre>window.open(&#39;data:text/csv;charset=utf-8,&#39; + escape(urls.join(&#39;\n&#39;)));</pre><p>This will download a CSV containing the URLs for the google images.</p><p>We then have to repeat the same process for getting URLs of images of “pudina”.</p><p>After that, we will upload them in the data section of our collab notebook create a folder name data_folder, and under that create the folder for each class and then upload the CSV files downloaded in the respective folders.</p><p>Next to download the image from the respective CSV file containing the URLs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*V9Y7RCCCI63JX6h_s84w5Q.png" /></figure><p>Now the images have been downloaded in the respective folder of our target classes</p><p>We will now create the data bunch from the images we have present in their respective folders</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*RBXU4j2yfTn0AUerItwKRA.png" /></figure><p>Image data bunch has been used to create a data bunch of the images present in their respective folders</p><blockquote>Parameters</blockquote><p>from_folder: It is used as we will be giving the labels to images based on the folder in which they are present.</p><p>data_folder: It is the folder in which our image folders are present.</p><p>valid_pct: It is the percentage of the data we want to keep as validation data.</p><p>ds_tfms: It is the parameters in which we pass transformations we wish to apply on the dataset</p><p>get_transform(): It is the factory method that consists of some standard transformation.</p><p>Then finally we normalized the data based on the imagenet stats</p><p>We have to use the image net stats because it may be possible that our image dataset stats are different than the data used to train the imagenet which can cause problems, so we will use imagenet stats so the normalization remains compatible with imagenet</p><blockquote>Next Step</blockquote><p>After executing the above blocks of code it is advised to check the classes present in our data.</p><p>This can be achieved by the following code snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*4VR2vThrdx8K6K0VJe21XQ.png" /></figure><blockquote>Instantiating the model</blockquote><p>Now we will be instantiating a learner as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*F2QailA5mm2JEEpGjmIIAg.png" /></figure><blockquote>Parameters</blockquote><p>The first parameter represents the data that we will be going to feed to the learner.</p><p>The second parameter is the architecture which we want to use for our learner</p><p>The last one represents the evaluation metrics we are going to use to evaluate our model.</p><blockquote>Fitting the model</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*X1G8-_9d5c8XF56WXCAySQ.png" /></figure><p>fit_one_cycle is being called with the number of epochs as the parameters</p><blockquote>Fine-tuning our model</blockquote><p>For improving our model we will try to fine-tune the learning rate and number of epochs so we will unfreeze our model using the following code snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*OzM92EbpJif9_-4tKP6qCw.png" /></figure><p>First, we will find the losses for various learning rate using :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*hvZxib3LhPrkX3j3WbhEng.png" /></figure><p>learn.lr_find : It calculates the error for the various learning rate.</p><p>Next, we will plot the losses for various learning rate using the following code snippet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*iKDBqgAnxW3Wc7xWTTKiaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*sYqLuUfwbolStlCx" /></figure><p>Once we get the plot we will select the interval in which the downward steep of the graph is maximum</p><p>We can observe that the maximum downward steep is between the interval 3e-05 to 3e-04</p><p>So we will again fit_one_cycle but now with the learning rate in the range of 3e-05 to 3e-04</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*CSomw8Ue_9mDbAFApTIyqg.png" /></figure><p>Then we will save our model at this point with name stage-2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*SIvJEyhqnX46L3oGkY1drg.png" /></figure><p>If we want to again load the learner with these given parameters we can use</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*TwVKZwZioWjobUepvSbNZQ.png" /></figure><p>Similarly, we can use these steps to train our models for different parameters and can save with help of learning .save(‘name’) and we can load it once again using learn.load(‘name’)</p><p>So we have trained our model its time to predict the class from a given image.</p><blockquote>Predicting the Class</blockquote><p>Store the image in the folder and assign it to a variable which can be passed to the model using the following code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*J97Odr2M0WOl9E5DG2yXPw.png" /></figure><p>The image we chose to test is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*QLPz9nQQp5K0XP9-" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*ZwHBz58tTf_rhUAAaQy2DQ.png" /></figure><p>The output for the given image is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*G2Xb3C0XnHbTUIz4M2zbLA.png" /></figure><p>As you can see we correctly predicted the class.</p><p>The motivation to write this blog has been taken from the fast.ai course provided by:</p><ul><li><a href="https://www.fast.ai/about/#jeremy">Jeremy Howard</a></li><li><a href="https://www.fast.ai/about/#rachel">Rachel Thomas</a></li><li><a href="https://www.fast.ai/about/#sylvain">Sylvain Gugger</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89eab6fe1760" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Different Types of Activation Functions]]></title>
            <link>https://medium.com/@ramitphi/different-types-of-activation-functions-1c84a1c1bd18?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c84a1c1bd18</guid>
            <category><![CDATA[sigmoid]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[activation-functions]]></category>
            <category><![CDATA[relu]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Tue, 28 Apr 2020 16:28:53 GMT</pubDate>
            <atom:updated>2020-04-28T16:30:26.319Z</atom:updated>
            <content:encoded><![CDATA[<h3>Different Types of Activation Functions :Sigmoid, tanh, ReLu &amp; Leaky ReLu</h3><h3>Sigmoid</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/0*9UPK-RNQN34Q1MCU" /></figure><p>The sigmoid function range is [0,1]</p><blockquote><em>Advantages</em></blockquote><p>It is good to use for the problem of binary classification as it outputs a value between 0 and 1 (0&amp;1 inclusive).</p><blockquote>Drawbacks</blockquote><p>It is some times not used in hidden layers because as the value of the x becomes large the steepness of the graph decreases, the gradient values become very small, this can slow the learning of our model.</p><h3>tanh</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*HRRZ-zTDfC_LT6GE" /></figure><p>Tanh function range is [-1,1]</p><blockquote>Advantages</blockquote><p>This is better than the sigmoid function as it is steeper than the sigmoid for small values which make learning faster as the gradient is large.</p><blockquote>Drawbacks</blockquote><p>As it ranges between -1 and 1 it cannot be used as the activation function of the last layer for binary classification as we need the binary output.</p><p>Moreover, just like the sigmoid function, the gradient is very less for the large values which again makes the learning slow.</p><h3>ReLu</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*i0378MKtjWoskrtv" /></figure><blockquote>Advantages</blockquote><p>Nowadays, this activation is mostly used as the gradient is significant and also it remains the same for large values.</p><blockquote>Drawbacks</blockquote><p>For negative values, the gradient drops to 0 which can make learning significantly slow. So, this should be used when most of the input values for a given layer are positive.</p><h3>Leaky Relu</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*Eg4xPDTkXtpj5jDU" /></figure><blockquote>Advantages</blockquote><p>This is a modified version of the ReLu function.</p><p>In this function for negative values, there is some slight slope that ensures that the gradient does not drop to zero, and the learning of the model is not being much affected.</p><blockquote>Drawbacks</blockquote><p>This is not as such a major drawback but sometimes the slope of function in the negative region needs to be fine-tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c84a1c1bd18" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playing with basis]]></title>
            <link>https://medium.com/@ramitphi/playing-with-basis-d10d3cee0e84?source=rss-880a1272149b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10d3cee0e84</guid>
            <category><![CDATA[matrix]]></category>
            <category><![CDATA[vector-space]]></category>
            <category><![CDATA[base]]></category>
            <dc:creator><![CDATA[Ramit Agarwal]]></dc:creator>
            <pubDate>Sun, 26 Apr 2020 11:02:22 GMT</pubDate>
            <atom:updated>2020-04-26T11:11:13.632Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Starting with vectors</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*gCAuqW6vn0kf8KMy" /></figure><p>A <strong>vector</strong> is an object that has both a magnitude and a direction. We can picture a <strong>vector</strong> as a directed line segment, whose length is the magnitude of the <strong>vector</strong> and arrow representing the direction</p><p><strong>Projection of vectors</strong></p><figure><img alt="The projection of vector s on r is scosø
 Where theta is the angle between vectors s and r" src="https://cdn-images-1.medium.com/max/385/0*SffRaG8sDwvbXVKD" /></figure><p>The projection of vector <strong>s </strong>on <strong>r </strong>is scosø</p><p>Where ø is the angle between vectors <strong>s</strong> and <strong>r</strong></p><h3>Basis</h3><p>The basis is a set of linearly independent vectors which spans the whole space and if there are n-linearly independent vectors in the basis then space is called n-dimensional space</p><h3><strong>Change of basis</strong></h3><blockquote><strong>When the new basis is orthogonal</strong></blockquote><p>If we have two basis vectors <strong>e1 </strong>and <strong>e2 </strong>and a vector <strong>p </strong>is represented in that basis and we want to to write wrt to other basis containing vectors r1 and r2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/0*7U7VqvBzu3KbnOm9" /></figure><p>We could use the projection of vectors for this purpose but this method is only applicable if b1 and b2 are orthogonal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*3NxYceJmWjaVI2tu" /></figure><p>This will give us a projection of <strong>p </strong>on <strong>r1 </strong>and the result of this calculation will act as one of the components of vector <strong>p</strong> in basis containing vector <strong>r1 </strong>and <strong>r2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*P9t2JIjBfNeaEygF" /></figure><p>This will give us a projection of <strong>p </strong>on <strong>r2 </strong>and the result of this calculation will act as another component of vector <strong>p</strong> in basis containing vectors <strong>r1 </strong>and <strong>r2</strong></p><blockquote><strong>What if the basis vectors are not orthogonal?</strong></blockquote><p>In this case, we will have to take help of matrix transformation</p><p>Suppose the O represents the other frame in which we want to express our vector p</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*ZBqVoa8tRrGJwDmo" /></figure><p>Let the above two vectors form the basis of space O.</p><p>These are the basis of other frames O according to the standard coordinate system M(our normally x,y plane) and p be the point in space represented as following in O’s frame</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*Adu65D8wYsufM6kc" /></figure><p>This is representing the layout of the space</p><p>Suppose a vector <strong>p </strong>is been written w.r.t to other frame O and <strong>O </strong>be the basis matrix of O</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/0*zLcx-V3IZ53IUeB4" /></figure><p>So to write this point <strong>p </strong>in our frame M we will have to perform the following operation</p><p>We will be multiplying <strong>O </strong>with the vector p represented w.r.t the frame of O</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/0*h1L5jsk45bg1QKdH" /></figure><p>The resultant vector represents <strong>p </strong>in frame M</p><p>If we wish to transform vector <strong>p </strong>from frame M to frame O then we would have to do the following operation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*aUcV2_f8D1j-YAE8" /></figure><p>One thing we can observe is that this time we multiplied the vector p w.r.t M’s frame with the inverse of <strong>O</strong></p><p>As we can observe we have been able to successfully transform the basis of vector <strong>p</strong> and verify it</p><blockquote>The question may arise why we actually need this</blockquote><p>This could be helpful when we want to apply some transformation to vector represented w.r.t another frame O. In that case, we might have no idea how the transformation works in a new coordinate system O so we will first convert that vector in our standard frame M by performing matrix multiplication of <strong>O </strong>with vector <strong>p</strong></p><p>This will give us the resultant vector representing <strong>p </strong>in our frame then we will apply the desired transformation by multiplying transformation matrix T it with vector <strong>p </strong>represented w.r.t frame M, which will give us required transformation</p><p>Finally, after receiving the transformed vector, we will again change it to its original frame O by performing matrix multiplication of transformed vector with the inverse of <strong>O</strong></p><p>This way it will be helpful for us to apply the transform to the vector which being w.r.t another basis</p><p>In, next part we will be talking about how we can furthermore simplify this process.</p><p>Ps- This is my first blog on medium feedback would be much appreciated</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10d3cee0e84" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>