<?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 Srinath Sridhar on Medium]]></title>
        <description><![CDATA[Stories by Srinath Sridhar on Medium]]></description>
        <link>https://medium.com/@srinathsridhar?source=rss-9ee11bd369b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IT-JfnYFpbHD5U5KKC3-yQ.png</url>
            <title>Stories by Srinath Sridhar on Medium</title>
            <link>https://medium.com/@srinathsridhar?source=rss-9ee11bd369b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 12:31:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srinathsridhar/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[Computer Simulations to Show the Impact of Social Distancing in Spreading the Coronavirus]]></title>
            <link>https://medium.com/@srinathsridhar/computer-simulations-to-show-the-impact-of-social-distancing-in-spreading-the-coronavirus-857f5a2f0045?source=rss-9ee11bd369b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/857f5a2f0045</guid>
            <dc:creator><![CDATA[Srinath Sridhar]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 23:21:37 GMT</pubDate>
            <atom:updated>2020-03-18T02:49:54.811Z</atom:updated>
            <content:encoded><![CDATA[<p>Computer Simulations to Show the Impact of Social Distancing in Spreading the Coronavirus</p><p>We create a model simulations on how diseases such as the corona virus can spread through communities. While the author does have a Ph.D., and studied modeling &amp; simulation, he is not a ‘real doctor’, a public health expert or an epidemiologist. The simulations are simplistic and needless to say does not model all real-world factors.</p><p>We wanted to setup a basic model purely out of our own curiosity and this was all hacked together in one evening of coding. Specifically we wanted to understand:</p><ol><li>Are we over-reacting to the corona virus since it sometimes sure feels that way. What would have happened if we just continued life as always?</li><li>What would be the impact of social distancing and is this really going to help?</li><li>What is the impact if we really were to cut out almost all social interactions outside of (possibly a large) family and room-mates?</li></ol><p>A user can play with it to begin to understand the impact of decisions on society. Feel free to change the parameters on the right and hit the “Run” button to re-run the simulation with changes. If you feel more ambitious, the entire source-code is included right there on the <a href="http://simulateanything.com/simulation?id=corona&amp;v=121"><strong><em>Simulate Anything</em></strong></a> website and you can modify, save a new version or even fork to start a new branch, add your own parameters etc. The results of running the simulation on a range of parameters and outcomes are included in the table at the bottom.</p><p>Once again here is the <a href="http://simulateanything.com/simulation?id=corona&amp;v=121"><strong><em>master simulation</em></strong></a> with all the source code and parameters. But read through this write-up below first since you will get a better grasp of what’s going on.</p><p><strong>Population Size.</strong> For simplicity and speed we start with a population size of 100K, roughly San Francisco scaled down by a factor of 10. San Francisco has about 40 cases of Coronavirus, and so we scaled it down to 4 as the default disease population. We realize this number could be much larger because of untested individuals and we will address that in a bit.</p><p><strong>Virulence or Resistance.</strong> We define a concept of resistance, informally and colloquially, as the average number of people you interact with who carry the disease and are contagious for it to spread to you. For example a resistance of 0.95 would mean that you need to interact with 20 contagious individuals on average before you contract the disease.</p><p><strong>Incubation, Disease.</strong> Incubation period is the number of days you are asymptomatic but contagious. Incubation period under current scientific studies are around 5 days for the COVID-19 [<a href="https://annals.org/aim/fullarticle/2762808/incubation-period-coronavirus-disease-2019-covid-19-from-publicly-reported">1</a>]. Disease period is the number of days you have the disease. By default we use 4 and 7 for these parameters which seems conservative.</p><p><strong>Quarantine.</strong> We have a quarantine if sick so they have no chance of spreading the disease after they experience symptoms. In reality COVID-19 has about a 30% chance of infected individuals who are asymptomatic and therefore do not quarantine themselves [<a href="https://www.sciencedirect.com/science/article/pii/S1201971220301399?fbclid=IwAR1bcY8mC-3BEvVbzgCTRFEePnlUdTCq6ZrP1mFauwHNCxyLrjn8xCo_ml4">2</a>]. While we set this factor to 1 by default (always quarantine if they display symptoms), we are being very conservative.</p><p><strong>Interaction Model.</strong> We have a “Global” or “Neighborhood” interaction model. A Global model means you meet random people such as a store associate, people in a movie theatre, in restaurants, conferences, schools etc. A neighborhood model is basically when people are at home and only interact with their immediate family. Specifically each person repeatedly interacts with a limited number <em>n</em> of people. The number of people interactions is the number of people one interacts with on a daily basis.</p><p>Here are some interesting scenarios that we were curious about. You can recreate these simulation results from the <a href="http://simulateanything.com/simulation?id=corona&amp;v=121">master simulation</a> by adjusting the parameters on the right and hitting “Run” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*69xGpg_AMbV_2enph-TZTA.png" /></figure><p><strong>Life As Always Scenario.</strong> Are we over-reacting? At times it certainly feels that way. So, first, we consider a conservative San Francisco day with no distancing. We use 100K population size, 4 individuals with the disease, 10 random interactions a day, 0.95 resistance, and even full quarantine when sick. The result? We basically have absolutely no chance of stopping the disease — it will hit the majority (80%) of the SF population very quickly. And if thats a model for the rest of the US, it will hit most of the US population spreading across cities independently and we pretty much have no chance whatsoever. To make matters worse, these outcomes are pretty robust to a lot of change in parameters which are already very conservative.</p><p><strong>Social Distancing.</strong> Second, we consider the setting where we are restricted to our homes for the most part. No meeting random people in conferences, schools, restaurants, movies etc. Now the results change dramatically. Try just updating Interaction Model from “Global” to “Neighborhood” while keeping the rest of the parameters the same. Firstly, you’ll notice that we dramatically cut down on the percent infected. Second, you’ll notice that we dramatically slow down the spread of the disease. Once again, this is in fact robust to even increasing the number of people you interact with as long as it is the same group of people.</p><p><strong>Stay At Home.</strong> Third, under the same “Neighborhood” model, just cut down the number of people interactions from 10 to 4, the size of a typical family. Now we will in fact quickly beat the disease and wipe it out completely. Even in cases when we do not wipe it out (from 4–10 interaction size or lower resistance) we have it totally under control. Once again, this is also robust for lower resistance levels and higher starting disease population levels that is more reflective of reality.</p><p><strong>Mixed or Restricted Global Interaction.</strong> Now, you may wonder what about a ‘mixed’ interaction model. The problem here is that even a little bit of global interaction (set to 4) and resistance of 0.9 (slightly lower than 0.95) is enough to let the disease out of control and infect 2/3rd of the population before dying out. If we reduce global interaction from 4 to 3, the disease infects about 1/3rd of the population. And if we did not quarantine sick, then in fact it spreads to nearly everyone reiterating that life as normal, even under very conservative restricted global interaction has little to no chance of beating the disease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QAwu4n-hau8D1Llj" /><figcaption>Results for the scenarios mentioned above</figcaption></figure><p><strong>Take Aways.</strong> So what do I make out of this?</p><p>Life as usual, seems largely impossible to work. You would have had to count on natural resistance, immunity, the weather or some external factors to slow down the rate. Or you have to accept that the majority of the population will get infected and that is okay. Outside of that, it certainly does not look like we are over-reacting. The response is in fact an absolute brutal necessity.</p><p>Given that San Francisco has nearly 1M people with only 40 cases, we have reason to be optimistic. It looks like we may still have enforced policies well within time. This largely requires people to limit random interactions. You can forget about school, conferences and music concerts. We are talking a handful of meaningful interactions a day with a random person is all that may be needed to let this get out of control. On the flip side, we still have timing on our side. If we reduce the number of random interactions to at most 2 (bare minimum), then it feels very real that we have this thing under total control, possibly even wiped out if we are extremely lucky and everyone plays a role. This would certainly at least easily delay to ease hospitals and get us time to fight it medically. But it really is that close when it comes to external random contact outside your immediate family.</p><p>Thanks to <a href="https://www.linkedin.com/in/jlevy/">Joshua Levy</a> for checking my code for bugs, providing valuable parameters and insights!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=857f5a2f0045" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving the Revenue Optimization Knapsack Problem in Practice]]></title>
            <link>https://medium.com/onera-engineering/solving-the-revenue-optimization-knapsack-problem-in-practice-d01abf7330de?source=rss-9ee11bd369b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d01abf7330de</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[knapsack-problem]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[retail-technology]]></category>
            <dc:creator><![CDATA[Srinath Sridhar]]></dc:creator>
            <pubDate>Thu, 20 Feb 2020 19:22:22 GMT</pubDate>
            <atom:updated>2020-02-20T19:22:22.959Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_nuKUSBbzagw95qCB12Kgw.png" /></figure><p>Recall that, as mentioned in the <a href="https://medium.com/onera-engineering/knapsack-problem-1bc5f58cd9e">previous post</a>, Onera can cast the problem of optimizing revenue without degrading customer experience as the following knapsack problem. Specifically, we have the following problem formulation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*sLKxqIBryZSanaH5E8nEig.png" /></figure><p>In the above formulation, the retailer sells a set of items <em>I. </em>Each item <em>i </em>in <em>I</em>, has value <em>v</em>(<em>i</em>) which is the expected revenue (or margin) that the retailer makes if they sell that item and corresponding to that there is <em>w</em>(<em>i</em>) which is the expected number of dissatisfied customers (the size of the item in the knapsack problem). The problem asks for us to maximize the total expected revenue while ensuring that the total customer dissatisfaction remains below threshold <em>W</em>.</p><p>The knapsack problem as stated above is expressed as an <a href="https://en.wikipedia.org/wiki/Integer_programming">integer linear program</a>. Specifically, note that the variables <em>x</em> can only take on a value of either a 0 or a 1. If we hypothetically assume that we can include an item into the knapsack fractionally (nonsensical in the real-world when filling a knapsack made of rigid items), then we obtain what is called as a <a href="https://en.wikipedia.org/wiki/Linear_programming_relaxation">linear programming relaxation</a> of the integer program. In the linear programming relaxation we just convert the variables <em>x</em> from being binary in {0, 1} to a real number in [0, 1]. The linear programming relaxation is a problem that is in <strong><em>P</em></strong> while the above integer linear program is a problem that is <strong><em>NP</em></strong><em>-complete</em> like mentioned <a href="https://medium.com/onera-engineering/knapsack-problem-1bc5f58cd9e">before</a>. This should make intuitive sense since if I can fit an item fractionally, then I should be able to fill the knapsack up fully and it makes the problem a whole lot easier.</p><p>Notice that there are <em>I</em> variables, <em>I</em> constraints that ensure that the variables are all binary (or 2<em>I</em> constraints in the relaxation enforcing that <em>x</em> is in [0, 1]) and a single constraint that enforces that the sum of the sizes of the items selected is at most <em>W</em>. We will call that single constraint as the <em>knapsack constraint</em> and the remaining 2<em>I</em> constraints as binary <em>boundary constraints</em>. In this problem, the<em> 2I + 1</em> constraints each are <em>I</em>-dimensional hyperplanes each of which enforce feasibility on one side. These constraints together, using their intersections, define an <em>I</em>-dimensional <a href="https://en.wikipedia.org/wiki/Polytope">polytope</a> within which lie all feasible solutions to the knapsack problem. The points outside the polytope are those that violate at least one of the above set of constraints.</p><p>In a classical work, it has been shown that all linear programs have an optimal solution that lies at an <a href="https://en.wikipedia.org/wiki/Extreme_point">extreme point</a>. Think of an extreme point as just a generalization of a vertex, for example a point at the intersection of a polygon, such as the three points of a triangle or 4 points of a square.</p><p>The solution at the extreme point is called as the basic feasible solution, which was the defining concept used in <a href="https://en.wikipedia.org/wiki/Simplex_algorithm">Simplex</a>, one of the big results in computer science history to solve linear programs fast in practice. It is fairly intuitive to see this if one can imagine any polygon and an objective function as a direction vector.</p><p>We now examine these extreme points of the knapsack polytope (again the linear relaxation) to find a beautiful structure that helps us solve them extremely fast. Note that an extreme point in this <em>I</em>-dimensional polytope is defined exactly as the intersection of <em>I</em>-linearly independent <em>I</em>-dimensional hyperplanes. Consider any such extreme point in the knapsack problem’s polytope. To get <em>I</em>-linearly independent hyperplanes, we need either <em>I</em> of the boundary constraints each of which corresponding to a unique variable or we have <em>I-</em>1 linearly independent boundary constraints each of which corresponding to a unique variable and the 1 knapsack constraint. In the former case, the extreme point would simply be defined by planes each of which enforce that the variable is binary (in {0, 1}) but not in between. In the latter case, we have <em>I-</em>1 variables set to 0 or 1 and possibly one variable, corresponding to the only variable that was not part of the <em>I</em> boundary constraints but part of the knapsack constraint have a fractional value in (0, 1).</p><p>This implies that when we solve the linear program relaxation of the integer program using Simplex, it will give us a solution where all the variables are binary with the exception of at most 1 variable.</p><p>This has huge significance in practice. Let us take an example where, as in the case of Onera’s systems, each variable corresponds to an item that the retailer might carry. Retailers typically carry and sell millions of products and so this program contains millions of variables. In one quick solve of the linear program relaxation, we get a solution where all but at most one variable is integral. Said another way, we actually have the optimal solution if you ignore only that single product in the entire catalog of products that the retailer carries. Indeed, the effect of that is so small that it only takes in practice a few more <a href="https://en.wikipedia.org/wiki/Branch_and_bound">branch-and-bound</a> relaxations to find the true optimality but even otherwise, the solution is incredibly close to optimal straight away by solving a problem in <strong>P</strong>. The chances are that if you have a million products you can argue that your solution will be instantly about 99.99% accurate by solving this relaxation. The 0.01% is definitely not going to be the problem in your models in practice.</p><p><strong>Take Aways.</strong> What does this all mean? Here are some simple, handy observations:</p><ol><li>When the problem you are solving can be modeled as a knapsack problem, do not immediately worry that it is <strong><em>NP</em></strong><em>-complete</em>. In fact, we can be happy that it is knapsack.</li><li>One can generalize the above statement beyond the knapsack of course. Specifically when constructing the integer linear programming model, see if it can be defined with just a few non-boundary constraints. The number of those constraints is an upper bound on the number of fractional variables in the linear programming relaxation. The fewer that those are, the faster and closer to optimal solution one can get.</li></ol><p>Side note: Although you can essentially always solve the knapsack very fast in practice, it is still very much <strong><em>NP</em></strong><em>-complete</em> and the ‘fast in practice’ does not translate to other <strong><em>NP</em></strong><em>-complete</em> problems like the k-clique or Steiner minimum tree which are not only <strong><em>NP</em></strong><em>-complete</em> but are also hard to solve in practice. These things also do not make a dent on complexity classes and so things like public key encryption remain unaffected.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d01abf7330de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/onera-engineering/solving-the-revenue-optimization-knapsack-problem-in-practice-d01abf7330de">Solving the Revenue Optimization Knapsack Problem in Practice</a> was originally published in <a href="https://medium.com/onera-engineering">Engineering @ Onera</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KISSing Algorithms: Graph Matching]]></title>
            <link>https://medium.com/@srinathsridhar/kissing-algorithms-graph-matching-37084901c11?source=rss-9ee11bd369b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/37084901c11</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[seo]]></category>
            <category><![CDATA[graph-matching]]></category>
            <dc:creator><![CDATA[Srinath Sridhar]]></dc:creator>
            <pubDate>Thu, 09 Aug 2018 17:49:59 GMT</pubDate>
            <atom:updated>2018-08-09T17:49:59.762Z</atom:updated>
            <content:encoded><![CDATA[<p>As a computer science freshman one of the first things you learn is to KISS. This is because software tends to get extremely complex incredibly quickly. Most engineers, especially those who build large systems know this and they KISS. Personally over the years the best products and designs that I have been involved in building have all obeyed the principle — KISS: Keep It Simple, Stupid.</p><p>Algorithms however tend to be immensely complicated even before you write a single line of code. For a decade and a half, what has interested me the most is how to keep algorithms simple, almost stupid, so that they can be implemented and maintained in production software while still having measurable theoretical guarantees.</p><p>This write-up talks about the story and some of the results of <a href="http://www.cs.cmu.edu/~srinath/fullpaper.pdf">our paper</a> that will be presented later this year at the WWW 2015 conference in Florence. The work was supported in part by BloomReach Inc, and the National Science Foundation.</p><p><strong>The Story:</strong> I wanted to write a set of <a href="http://bloomreach.com/puzzles/">programming puzzles</a> for BloomReach that were also related to the problems that we solved internally. The first puzzle (and the one that I expected will get the most submissions) is the following. There are <em>n</em> people who visit a winery and each of them write down <em>d</em> wines that they liked and would be happy to buy any <em>c &lt;= d</em> of them. The winery has one bottle of each of their <em>m</em> wines and would of course like to sell as many bottles as possible. Given the set of wines written down by each person, the puzzle asks to figure out the assignment of wines to people so that the number of wines sold can be maximized.</p><p>The problem formally is that of a fractional matching in a bipartite graph. Matching problems and its variations have a lot of applications. In the paper we talk about how it can be used to study websites with recommendations (such as YouTube, Quora, Netflix, any website really) from the angle of discoverability. For e.g, I can ask the following basic and related question — what fraction of YouTube videos (or Quora questions etc) do not have a single other YouTube video (Quora questions etc) recommending it? This is of course if we remove personalization. Its a simple question, yet one that likely no one would have an answer to. It is also the most basic measure that can be used to ensure that great content does not remain forever hidden.</p><p>Getting back to the puzzle though — we can convert the wine tasting problem into a graph with left and right partitions. The left partition represents people, the right the wines and the edges are the wines that they liked (<em>d</em> out-edges from each vertex on the left) and the output is a subgraph with <em>c</em> out-edges from each vertex on the left. The goal is to maximize the number of vertices on the right in the output subgraph with an indegree of at least 1. For those familiar with algorithms, note that this problem can be converted into the classic bipartite matching by ‘splitting’ each vertex on the left into <em>c</em> identical vertices.</p><p>There are several well-known algorithms to solve these matching problems. Two of the classics that every computer science undergrad learns is Ford-Fulkerson and Hopcroft-Karp. While the classic algorithms are not too complicated, they are not trivial either. They need super-linear runtime which isn’t scalable in practice, use significant memory overhead and are hard to implement on a distributed model. In the more general problem of graph matching, implementing Edmond’s Blossom is much more complex.</p><p><strong>Problems with Solutions:</strong> For the wine-tasting coding puzzle, I wanted to create sample instances that I can allow people submitting answers to test their code against. I did this by randomly sampling edges. I ran BloomReach’s internal implementation of the matching algorithm and it found solutions that were essentially ‘perfect.’ That is — there was a solution where every single person got <em>c</em> wines and the winery sold as many wines as they possibly could. I thought there was something wrong with the random graph generation but quickly realized that its too simple to have a bug. This meant that the production BloomReach code likely had a bug which was disturbing of course. But thankfully after a while I ruled that out as well.</p><p><strong>Eureka Moments:</strong> As a side-note you can watch one of my former collaborators talk about <a href="http://bigthink.com/embeds/video_idea/the-joy-of-fake-eureka-moments">eureka moments</a>. Often people don’t jump up with ‘eureka’ but much more often with ‘hmm, thats weird.’ This was one such instance. So I proceeded to work out the chance that this can happen and I did the following back-of-the-envelope calculation.</p><p><strong>The Combinatorics:</strong> Instead of running the classic algorithms, let’s say that we just randomly pick the <em>c</em> wines for each person. Again, if you are familiar with algorithms note that if <em>c=d</em> this algorithm’s performance and the question of an existence of a (near) perfect matching is the same. We can do this by computing the probability of selling a bottle for the sampling algorithm. To do that, it is easier to start with computing the probability that a specific wine was not sold. For this to happen, the wine must not be picked by anyone. The probability that it did not appear in a single pick by a single person is (1–1/<em>m</em>) since it is ‘competing’ against the other m wines. Pushing some details under the rug, the probability that it was not picked by anybody is (1–1/<em>m</em>)^<em>cn</em>. Therefore, the probability that it was in fact picked is 1 — (1–1/<em>m</em>)^<em>cn</em> = 1 — ((1–1/<em>m</em>)^<em>m</em>)^(<em>cn</em>/<em>m</em>) which a person with a graduate course in probability or algorithms would recognize as 1 — e^{-<em>cn</em>/<em>m</em>} for (even slightly) large values of <em>m</em>. If you want a proof, apply limit <em>m</em> -&gt; infinity, apply natural log and use L’ Hospital’s rule. It is also likely possible to prove this using some algebra on Taylor series of e^<em>x</em>, using squeeze lemma or Stirling’s approximation but maybe you can work it out. Therefore the expected number of wines that will be sold is <em>m </em>(1 — e^{-<em>cn</em>/<em>m</em>}).</p><p>Also, I realized that there are two trivial ‘perfect’ solutions that would make the winery ‘perfectly’ happy. One where every person is satisfied and therefore the winery sells <em>cn</em>wines. The other where every wine, <em>m</em>, that the winery has is sold. Intuitively, the first case happens when there are few very people and a lot of wines. The second when there are a lot of people and very few wines. Therefore it is impossible to do better than either and therefore the best solution is upper-bounded by min {<em>cn</em>, <em>m</em>}.</p><p>For visualizing, if we set <em>k</em> = <em>n</em>/<em>m</em>, then <em>m</em>(1 — e^{-<em>cn</em>/<em>m</em>}) / min{<em>cn</em>, <em>m</em>} = (1 — e^{-<em>ck</em>}) / min {<em>ck</em>, 1}. This is the performance guarantee for the simplest bipartite matching algorithm that will ever be devised.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*Ye3ONTeqQ7kbxm8J" /></figure><p>In the plot, <em>ck</em> &lt; 0.2 and <em>ck</em> &gt; 2.4, defines a quantitative measurement for the contention for the wines by the people and represent the ranges when the contention is too low or too high. Only when the contention is smack in between, there is any real distinction in the quality of the solutions between those sent in by people who wrote very simple code from those who implemented the classics. When the problem instances fall outside that range, it really does not matter much. Simultaneously, what this also showed is that only in between those ranges does the input graph not have a (near) perfect matching. Outside of those ranges, there is likely a solution that will make the winery ‘perfectly’ happy.</p><p>At this point, I called up a prior collaborator of mine, Ravi, and we started working with Arda Antikacioglou, a Ph.D. student and thanks to BloomReach’s support developed further results.</p><p><strong>Real-World Implications:</strong> So what does all of this mean in the real-world?</p><p><strong>(1) </strong>Lets say that you run a website that has recommendations. Nearly every website from Netflix, Quora, Amazon, YouTube have recommendations. You are looking at a video, a product or a question and they recommend a few related videos, products or questions on the right side or below the main content. Let us revisit the simple question. What is the fraction of videos (or products etc) that are there on your website that is not recommended from a single other video (or product)? You are thinking and hoping that it is a fraction of a percent since you want a random surfer to be able to navigate across your website. But for large websites that fraction could be incredibly high. This is just the most basic test on how well connected your website is and if you have a lot of content that no one has a chance of finding serendipitously. How do you mitigate this problem? Besides quality based metrics that you are using to find the say 3 best recommendations, you might want to retrieve and then randomly pick the 3 from them. What our results seem to indicate intuitively is that even throwing in a little bit of randomness might go a long way.</p><p><strong>(2)</strong> Lets say that you are trying to solve the fractional or simple bipartite matching problem. And there are a ton of different places where they show up. If you have a reason to believe that the underlying graph has edges that are selected close to uniformly at random, then check the above plot and perhaps all you need to do is select a set of edges randomly for each vertex. Even, if you do not know the underlying graph distribution just try the above simple (stupid, really) algorithm. If your solution is close to the theoretical upper bound of min{<em>cn</em>, <em>m</em>}, you are done. Your code will be completely trivial and super easy to maintain. If you wanted a better solution, then we show that you can do the above random process in ‘rounds.’ Select an edge at random in each round. Remove the vertices on the right that have an indegree of 1. Repeat for <em>c</em> rounds. We show that the above heuristic does incredibly well both in theory and practice.</p><p>There are a lot of fun extensions and more realistic models of these problems that you can find in <a href="http://www.cs.cmu.edu/~srinath/fullpaper.pdf">our paper</a> and a lot more that are yet to be explored. Overall, as always, don’t think too much, its not worth it. Just KISS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37084901c11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Weekend Hack: Lane Detection, Drift and Self Driving]]></title>
            <link>https://medium.com/@srinathsridhar/weekend-hack-lane-detection-drift-and-self-driving-e6ea06e52872?source=rss-9ee11bd369b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ea06e52872</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Srinath Sridhar]]></dc:creator>
            <pubDate>Sun, 22 Jul 2018 17:56:30 GMT</pubDate>
            <atom:updated>2018-07-22T17:56:30.263Z</atom:updated>
            <content:encoded><![CDATA[<p>Note: this was done in August 2015, way before the DIY self-driving efforts.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4LFQEuleYNE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4LFQEuleYNE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4LFQEuleYNE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c790e0976e41180424a641a0fdb51cd/href">https://medium.com/media/8c790e0976e41180424a641a0fdb51cd/href</a></iframe><p>I had the weekend to myself and so I decided to go back to being a kid and hack something that I would have done if I were a child today. I am really excited about Google self-driving cars in general and especially so now because they are so close to getting it in the hands of customers. So for a hack I was thinking what would be a self driving MVP?</p><p>Cruise control was probably the first MVP here. You didn’t need to maintain speed, your car’s computers did that. Then came adaptive or active cruise control. Now you don’t need to maintain distance, the computers could calculate the distance and accelerate or brake appropriately for you all the way to coming to a full stop. The next step was lane detection and drifting close or out of your lane.</p><p>If you had lane detection and active cruise control, then you essentially have an incredible product because you can self-drive the lane on the highway by letting the computer steer, accelerate and brake to drive great distances on the lane! I think this would already go a long way in terms of self driving capability. If you are driving 8 hours, most of the time is spent on the highways and maybe just 2 or 3 of them. So if your computer can just stick to a lane (maybe second from the leftmost, say), then there is mostly nothing that you need to do except merge and exit.</p><p>So I decided to write some code just for fun. I just wanted to hack for the sake of it. I have no interest in pursuing this as a product. Here are a few tools that I used and a video that I made on Sunday evening of it performing lane detection and alerting.</p><p>The entire work was no more than 200 lines of Java code a lot of which was code that I had to write to help me visualize what the computer was doing, i.e., debugging tools. The only investment that went in was a $30 webcam (see below) that I bought from Fry’s Saturday morning. I was initially thinking of using my iPhone of course, but for ease of development — I just used the webcam.</p><p>The primary piece of tool that I used was opencv/javacv which is one of the standards for computer vision. I played around with a few things: converting images to grayscale, threshold functions to smooth out black/white shades that were noisy, Canny edge detector to outline the resulting image and Hough transform to detect linear lines in the resulting image. The lines are in polar co-ordinates (because of some numerical instability during the transform), so I converted them to cartesian co-ordinates (the usual, rho cos(theta), rho sin(theta)) and had some restrictions on the slopes and intercepts that those lines can have. This is needed since I don’t want it to pick up adjacent lanes, the divider on the highway or even the horizon of the sky. Then I needed to check to see if the triangles induced by the lines are close to isosceles or if the intercept of the lines on the horizontal was out of range. Finally, there were some thresholds to ensure that the drift is real and does not happen all the time so that it does not beep constantly during city driving or even when switching lanes. See the image below for the steps on the transform on an ideal starting image. In reality the images are not even close to this perfect in color and so it is far more noisy. The video shows the drive, the alerts and also what the computer saw during the drive which was surprisingly accurate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QBBvxtrxEGO_T6-y" /></figure><p>The first three images are the original (a good Google image picture that shows the lanes clearly) then I converted it to grayscale and thresholded it. What the threshold helps us do is remove the black treadmarks, oil marks or even other black marks from the asphalt. We are not interested in those and the human brain doesn’t even recognize them as lines. And we want to computer to ignore them as well. By removing darker than the asphalt shade we can get rid of those. The thresholding functions supported by opencv did not seem adequate and what I wanted was to increase the pixel darkness for everything above a threshold but this does not seem possible natively. I could have written one but in a weekend hack, things like this can add up. So I just used the binary (white or black) threshold which works well here but is trickier in real drives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rzWKgrsuCnbzV7qK" /></figure><p>The next image is the result of Canny’s edge detection which does a fabulous job of finding the borders of the thresholded image. Lastly we have 6 Houghlines that are just straight lines passing through the most number of points. Again I had some conditions on slopes and intercepts for it to make sure that it was a reasonable candidate to be a lane.</p><p>The video above shows me driving from Castro street in Mountain View, merging onto I-85 South and taking the Fremont Avenue exit. I then show how the computer saw the entire drive as well with a solid single white line corresponding to what it detected as the lane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_gx3xMzIwrfRiiqz" /></figure><p><strong>Hope you enjoyed it. There has never been a better time to be a software engineer. Hack on!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ea06e52872" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Women Who Compete Against Men]]></title>
            <link>https://medium.com/@srinathsridhar/women-who-compete-against-men-3471537c0b54?source=rss-9ee11bd369b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3471537c0b54</guid>
            <category><![CDATA[chess]]></category>
            <dc:creator><![CDATA[Srinath Sridhar]]></dc:creator>
            <pubDate>Sun, 08 Jul 2018 18:09:12 GMT</pubDate>
            <atom:updated>2018-07-08T18:09:12.570Z</atom:updated>
            <content:encoded><![CDATA[<p>Note: This is an older write-up from October, 2014 and cross-sharing on medium in case of interest to a different, wider audience.</p><p>There are a lot of fields where women are underrepresented. For example, men outnumber women in Computer Science. I was personally stunned that in the Carnegie Mellon Computer Science Department’s Ph.D. program, class of 2004 had roughly 22 students and exactly 0 women. More importantly, after all these years, we just had the first female mathematician who won the fields medal. But have you ever thought about the women who literally compete against men at the highest level?</p><p>When you think of competition you think of sports. And so, can you name the women who compete against men directly at the highest levels in (popular) sports? If you are struggling to come up with names — that might be the sad reality. The only ones that come to my mind are Danica Patrick and just maybe lagging behind rather significantly, folks like Annika Sorenstam or Michelle Wie. I am sure there are a few more.</p><p><strong>Quick Intro:</strong> When one of my childhood heroes, Judit Polgar, announced her retirement from professional chess about a month back, I thought that I should write a quick tribute since most people do not know about her. Some of the stats about Judit are incredible. She was the first female chess player to be ranked among the top 100 players. She easily stayed in the top-100 for 25 consecutive years and was the only female there for all those years. At her peak, she was a top-10 player and was a world championship contender.</p><p><strong>Bias Against Women:</strong> Top chess players did not think of women very highly in the 80s. Here are a couple of quotes. Garry Kasparov, a world champion of 15+ years, and one of the strongest chess players of all-time said, “She has fantastic chess talent but she is, after all, a woman. It all comes down to the imperfections of the feminine psyche. No woman can sustain a prolonged battle” referring to a very young but rapidly rising Judit. Some of these opinions continue even today and so you can imagine the situation in the 80s. Here’s a quote from an interview of the world’s second strongest chess player. “Interviewer: Mr (Levon) Aronian, since the beginnings of the game, men have dominated chess. Why is that? Levon Aronian: Women cannot play chess.” Hard to get more concise than that.</p><p>But there would prove to be one major problem with the theory of women playing chess. Precisely one problem. Judit Polgar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*KPDEO_lc5_t-jE93" /></figure><p><strong>31st Chess Olympiads:</strong> Until 1990, Judit played in the women’s division. By 1992, Judit had put a considerable distance between herself and every other woman on the planet. But, if I am right, the international organization that ran tournaments would not let Judit play in the men’s division. After all (and this could be true for every sport that has a gender division) there are men’s and women’s divisions for a reason, right? At least that was their argument.</p><p>But 1994 would prove to be historic. Hungary decided to improve their chances of winning a medal by having their strongest chess player, in this case Judit, lead their ‘men’s’ team. Has this ever happened in any sport — that a country in serious contention of winning a medal chooses to strengthen its team by having a woman play (and lead) in what would otherwise be a men’s division? The 1994 chess Olympiads men’s/open division had hundreds of men and competing amongst them for the medals was one blonde teenaged girl. She has represented Hungary in the open/men’s division from that time onwards until her retirement just last month. Fittingly, the last tournament she played was the 2014 chess Olympiads.</p><p><strong>Breaking Social Archetypes:</strong> Although people around her thought that this was impossible, Judit, never flinched and started beating grandmasters in her pre-teens. Crushed super grandmasters in her teens. And then one by one — nearly every single former chess world champion fell — Karpov, Spassky, Anand, Carlsen just to name a few of the giants.</p><p><strong>Judit Polgar Vs Garry Kasparov:</strong> Kasparov was made to eat his words (see above). Polgar brought Kasparov to the brink of defeat in 1994. He literally had to cheat to avoid losing to a teenaged girl. Thankfully, a few years later, she went on to defeat him outright. That was the first and only time Kasparov (or any former world champion I think) lost to a woman in competitive play. Judit defeating Kasparov was also historic because it was the first and the only time when a woman defeated the current top ranked player in a head-to-head game in any sport. Ever.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qkO7dwMKZcOzZIPt" /></figure><p><strong>Her Chess:</strong> (Right click and view image to see the positions bigger). She was not just the greatest female chess player. She was one of the greatest chess players. A tribute to her would not be complete without looking at her chess. Her games had a couple of features that I can think of. First is her incredible attacks. She was ruthlessly aggressive. The positions at the bottom row illustrate some of her attacks.</p><p>Alexei Shirov, long time top rated player from Spain played the Keres attack with White. Arguably, the fastest opening attack on the Black king. Those who play the Sicilian Scheveningen with Black, will likely recall traumatic encounters of the Keres attack — first played by Paul Keres three quarters of a century back. Shirov just played Qf3 leading to the position below and knowing such positions what generally follows is a brutal attack by White that Black has to fend off. Judit of course would have none of that. She plays the hardly believable g5 followed by h5. The first reaction is simply ‘this cannot possibly work.’ But, it worked brilliantly and what ensued is not the typical White assault on the Black king but Black’s counter-attack on the White king. Just like how Keres’ attack has been studied as a classic, Polgar’s counter-attack will be studied for decades if not centuries to come.</p><p>Just to demonstrate her other attacks here are a couple of positions from her games against Anand and Mamedyarov. Both top-10 players at their peaks. She goes on to sacrifice two pieces in both the games and of course goes on to win. Her game against Anand is an incredibly complex game. The game against Mamedyarov is a beautiful thematic (to e4-e5 lines like Evan’s gambit/Guico Piano) knight sac.</p><p>A second quality of Polgar’s games is her sheer ability to out-calculate her opponents. It does not get more badass than that. She has an ability to get to complex positions, out-calculate and finally finish off her opponents in what would seem to be an out of a chess text-book puzzle position. Here are three positions spanning her career in the top row of the Figure. The first played by a 12-year-old Judit and an easy but elegant finish. Second, ten years later — Anand just played exf4. There is exactly one line that wins and forces an incredibly beautiful win that she finds. The last from her last tournament — aptly from the “men’s” Olympiad that she just played last month. Her opponent thought that he had fended off Judit’s assault. But no such luck as she finds a beautiful forced win.</p><p><strong>Heir to Judit:</strong> Its a pity that for the last 25 years she has had no equal among women. She has basically been the only (but undeniably solid) contradiction to anyone who thought that women cannot compete against men. But its been nearly three long decades. Where are the girls that she inspired? She can’t be an exception.</p><p>The very best chess players, essentially world champion material, are mostly prodigies. They don’t slowly improve their play over many decades. They burst into the scene as a prodigy and break many records along the way. Capablanca, Bobby Fischer, Kasparov, Anand and Carlsen are all great examples. No finer example than Judit Polgar herself who broke into top 100 among men, when she was just 12! Just think about that for a second.</p><p>For a while, quite a few chess followers including myself were hoping that Humpy would be her successor. Since she was just a few years younger to me, I had the privilege of playing a tournament with her and watching her game up close. Humpy was a prodigy who broke several of Judit’s records and firmly placed herself as the second highest rated female chess player. But then she plateaued and could not break into the top 100 or pose serious threats to the top men.</p><p>Judit’s decision to retire last month was I am sure in no small part due to the fact that for the very first time ever in chess we had two women in the top-100. And so as Judit retires, at least the top 100 players will continue to have 1 woman. We could wish that it were 10 girls out of the top 100 that she had inspired. But at least it is not 0 thanks to Yifan Hou, a prodigy who broke several of Judit’s and Humpy’s records on her way to the top.</p><p><strong>Thank You:</strong> Thank you Judit Polgar, for being an inspiring role-model and for fighting against prejudice so gracefully. And thank you for lighting the board on fire with three decades of mind-blowing chess.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3471537c0b54" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>