<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shriphani Palakodety</title>
	<atom:link href="http://shriphani.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://shriphani.com/blog</link>
	<description>In Pursuit Of Truth and Beauty</description>
	<lastBuildDate>Sat, 28 Aug 2010 23:54:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Fixing Schedule</title>
		<link>http://shriphani.com/blog/2010/08/28/fixing-schedule/</link>
		<comments>http://shriphani.com/blog/2010/08/28/fixing-schedule/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 23:54:01 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Daily life]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=658</guid>
		<description><![CDATA[So, my plan for semester #5 seems to be finalized. I did not do too well in the Physics test out &#8211; apparently they cover less in the summer iteration of the course than they test for in the test-out. This mean I will have to take Phys 272 in semester #6 (ah well, a [...]]]></description>
			<content:encoded><![CDATA[<p>So, my plan for semester #5 seems to be finalized. I did not do too well in the Physics test out &#8211; apparently they cover less in the summer iteration of the course than they test for in the test-out. This mean I will have to take Phys 272 in semester #6 (ah well, a GPA booster) with CS 497, a course on logic (where we get to program using prolog &#8211; this I am looking forward to) and of course another CS course (crypto maybe?).</p>
<p>So this semester I am really looking forward to my compilers class, the last portion of my numerical methods class and of course my CS 490 project with Dr. Kihara and of course I want to achieve my goal of being able to watch anime without having to read subtitles.</p>
<p>This would also be one of the only semesters where a book for which I paid $30 on amazon looks like it was printed by one of those shady book-vendors in the streets of Hyderabad. Seriously the book by Skeele is printed on paper that is coarse and it just doesn&#8217;t look like a decent textbook. I also do not agree with the style of the book and since I used LaTeX over the summer, the pictures and the text look like they have just been thrown together. It just doesn&#8217;t look right.</p>
<p>Anyway, I hope this semester goes well.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/08/28/fixing-schedule/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Summer and Fall 2010 + SURF 2010</title>
		<link>http://shriphani.com/blog/2010/08/26/summer-and-fall-2010-surf-2010/</link>
		<comments>http://shriphani.com/blog/2010/08/26/summer-and-fall-2010-surf-2010/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 05:03:07 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Daily life]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA["OpenGL"]]></category>
		<category><![CDATA["poster presentation"]]></category>
		<category><![CDATA["poster"]]></category>
		<category><![CDATA["schedule"]]></category>
		<category><![CDATA["semester"]]></category>
		<category><![CDATA["surf 2010"]]></category>
		<category><![CDATA["visual analytics"]]></category>
		<category><![CDATA[college]]></category>
		<category><![CDATA[SURF]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=649</guid>
		<description><![CDATA[So, 4 days into this semester I think I have decided my schedule. I am assuming I have a relatively light semester owing to some stupidity I engaged in (screw ups with the coursework). Anyway, here&#8217;s my coursework for this semester: CS 352 &#8211; Compilers (supposed to be hard) CS 314 &#8211; Numerical Methods (this [...]]]></description>
			<content:encoded><![CDATA[<p>So, 4 days into this semester I think I have decided my schedule. I am assuming I have a relatively light semester owing to some stupidity I engaged in (screw ups with the coursework). Anyway, here&#8217;s my coursework for this semester:</p>
<ul>
<li>CS 352 &#8211; Compilers (supposed to be hard)</li>
<li>CS 314 &#8211; Numerical Methods (this course looked very interesting).</li>
<li>MA 375 &#8211; Discrete Math (to consolidate my probability concepts and to study graphs deeply)</li>
<li>COM 217 &#8211; Had to take it sometime.</li>
<li>CS 490 &#8211; Bioinformatics independent study.</li>
</ul>
<p>So, I chickened out of ECE 270 since Compilers + Digital Systems would be suicide and since CS 497 is planned for semester #6, I am in a tight spot since one more CS course can cause my GPA in all courses to tank so I am stuck here with this stupid setup. Also, I took the Phy test out and I am not sure if that went very well so I will have to wait.</p>
<p>Anyway, enough about the current semester. Summer was the most eventful time of my 2 years here @ Purdue. First, I worked for Dr. David S. Ebert in his Visualization laboratory (<a href="http://cobweb.ecn.purdue.edu/purpl/">PURPL</a>) on an <a href="https://engineering.purdue.edu/PURVAC/proj_emergency.html">emergency response system</a> (the project screenshots shown there are still old. They probably won&#8217;t be updated in a while). It was extremely interesting since I got to work with OpenGL (I am not sure I will ever get a chance to work with it again) and got to learn about computer graphics. Here is a list of things we got done in the summer:</p>
<ul>
<li>A 3D picking algorithm (nothing too fancy. This took a while since I had to read OpenGL documentation about their coordinate systems).</li>
<li>A controllable camera (one you can turn, zoom in/out with using keystrokes)</li>
<li>A couple of camera angles (The high angle mode and the first person mode). Getting them to follow characters smoothly was a crazy issue.</li>
<li>Then we implemented a path based attribute visualization technique which became the topic for my poster.</li>
</ul>
<p>I stood with a poster @ the SURF symposium and I won &#8220;Top Poster&#8221; and my grad mentor, <a href="http://vrinside.net/inside/">S. Kim</a>, earned &#8220;Graduate Student Mentor of the Summer&#8221; so I would rate my SURF 2010 experience as one of the top 10 experiences of my life (the other 9 are yet to arrive).</p>
<p>Now, I might just go and join SIG-APP or something like that to spend spare time. Now, here are some goals I set for myself this semester:</p>
<ul>
<li>Prepare for the GRE (it sucks but it has to be done).</li>
<li>Learn how to speak Japanese reasonably well.</li>
<li>Consolidate my probability knowledge (I would really like to learn it well this time round).</li>
<li>Finish reading a book on NP Complete problems.</li>
</ul>
<p>Well, I just hope I don&#8217;t screw up anything this year since this is my last chance to build a great resume for grad school (and achieve some lofty goals which are too childish for even this blog) before applications season begins.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/08/26/summer-and-fall-2010-surf-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purdue HG Setup</title>
		<link>http://shriphani.com/blog/2010/08/17/purdue-hg-setup/</link>
		<comments>http://shriphani.com/blog/2010/08/17/purdue-hg-setup/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 03:11:32 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[College]]></category>
		<category><![CDATA[Computer Science]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=644</guid>
		<description><![CDATA[I was trying to set up a personal repo on Purdue&#8217;s machines using hg and of course I was confronted with the dreaded lines: remote: bash: hg: command not found abort: no suitable response from remote hg! Well, this is really irritating. The solution to this problem is that you must specify hg&#8217;s path in [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to set up a personal repo on Purdue&#8217;s machines using hg and of course I was confronted with the dreaded lines:</p>
<pre>
remote: bash: hg: command not found
abort: no suitable response from remote hg!
</pre>
<p>Well, this is really irritating. The solution to this problem is that you must specify hg&#8217;s path in your .bashrc file on lore.</p>
<p>So on lore, add the following to your $PATH variable:
<pre>/opt/csw/bin</pre>
<p>And you should be fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/08/17/purdue-hg-setup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Listener Gets Another VAD</title>
		<link>http://shriphani.com/blog/2010/08/09/listener-gets-another-vad/</link>
		<comments>http://shriphani.com/blog/2010/08/09/listener-gets-another-vad/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 23:46:49 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[DSP]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA["voice activity detection"]]></category>
		<category><![CDATA["voice"]]></category>
		<category><![CDATA[Listener]]></category>
		<category><![CDATA[VAD]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=631</guid>
		<description><![CDATA[A list of additions to Listener. The additions include a new Voice Activity Detection algorithm.]]></description>
			<content:encoded><![CDATA[<p>Over this summer, I wanted to make <a href="http://shriphani.com/blog/Listener" target="_blank">Listener</a> Python only (there was a ton of needless applescript) and since my work @ VACCINE [<a href="http://www.purdue.edu/discoverypark/vaccine/" target="_blank">VACCINE homepage</a>] (more on this in a new post) didn&#8217;t leave much time for tinkering with things, I had to push this back as much as I could. I also added another voice activity detection algorithm which I believe works a lot better than what I had previously. And I also moved my project over to GITHUB.</p>
<p>The additions to Listener:</p>
<ul>
<li>A new Voice Activity Detection algorithm <a href="http://www.eurasip.org/proceedings/eusipco/eusipco2009/contents/papers/1569192958.pdf" target="_blank">[ link to pdf by Moattar and Homayounpour]</a>.</li>
<li>Skype4Py is still buggy on OS X with Python2.5 and it takes a nice solid dump (segfault) with Python2.6 so I am sure if the Skype part of the code works.</li>
<li>Python only. I removed the applescript portion from my code.</li>
</ul>
<p>I have moved the entire code over to github: <a href="http://github.com/shriphani/Listener/">http://github.com/shriphani/Listener/</a> . The VAD algorithms can be seen in the file <a href="http://github.com/shriphani/Listener/blob/master/VAD.py" target="_blank">VAD.py</a>.</p>
<p>This VAD also works by starting off with a base threshold for energy, power and an attribute called Spectral Flatness Measure. Luckily the paper had pseudocode so my DSP n00bishness wouldn&#8217;t get in the way of progress.</p>
<p>Anyway, to get this version of Listener running, download <a href="http://github.com/downloads/shriphani/Listener/Listener.tar" target="_blank">Listener.tar</a> , untar it and run:</p>
<pre>python2.5 audio_analysis.py</pre>
<p>And you should be all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/08/09/listener-gets-another-vad/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bipartite Matching And Max Flow &#8211; Tweaks And Other Observations</title>
		<link>http://shriphani.com/blog/2010/07/16/bipartite-matching-and-max-flow/</link>
		<comments>http://shriphani.com/blog/2010/07/16/bipartite-matching-and-max-flow/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 00:45:16 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[bipartite-matching]]></category>
		<category><![CDATA[flow]]></category>
		<category><![CDATA[matching]]></category>
		<category><![CDATA[max-flow]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=598</guid>
		<description><![CDATA[A look at the bipartite matching problem and some observations about solving them using max-flow.]]></description>
			<content:encoded><![CDATA[<p>When I was in Dr. Frederickson&#8217;s CS 381 class (if you go to Purdue CS and are wondering if you should sit in his CS 381, I would say YES), I learned how to solve a simple class of Matching problems, biparitite matching.</p>
<p>So, you have 2 sets of vertices and no 2 members of the same set are connected. Now, given a bipartite graph, we are supposed to find a maximum matching for it.</p>
<p>The simplest way to solve this problem would be to use integer valued flow. Here&#8217;s our sample graph:</p>
<p><a href="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite11.jpg"><img class="aligncenter size-medium wp-image-601" title="bipartite1" src="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite11-300x225.jpg" alt="" width="300" height="225" /> </a>Well, the obvious solution is to direct the edges from the set on the left (marked L in the pic below) to the set on the right (marked R in the pic below) and to make a source vertex and a sink vertex. Next, to apply integer valued flow algorithms on this network, set the capacity of each edge to 1.</p>
<p><a href="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite2.jpg"><img class="aligncenter size-medium wp-image-605" title="bipartite2" src="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite2-300x225.jpg" alt="" width="300" height="225" /></a>PS, I haven&#8217;t noted the capacities in the graph above because that would introduce too much clutter. But the capacities are indeed 1. When you run any method on this network that computes maximum integer valued flow (Choose between Ford-Fulkerson and Edmonds-Karp), you are going to have a flow of 0 or 1 on the edges in the graph. The edges that have flow = 1 on them are the ones that are included in the matching and those that are not in the matching have a flow value = 0. Here is one of the possible matchings:</p>
<p>The edges that are untouched have a flow value = 1 (also equal to the capacity of the edge) and those that look like they&#8217;ve been shot (i.e have holes in them, have a flow of 0 and hence are not in the matching).</p>
<p><a href="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite3.jpg"><img class="aligncenter size-medium wp-image-607" title="bipartite3" src="http://shriphani.com/blog/wp-content/uploads/2010/07/bipartite3-300x225.jpg" alt="" width="300" height="225" /></a>Well, everyone knows this stuff. Else you wouldn&#8217;t have approached this line is &lt; 10 seconds. Anyway, in one very productive office hour session with Dr. Frederickson, he pointed out the importance of using an approach to solve a problem. In this case, why do we set a capacity of 1 and compute max integer-valued flow? Well, considering I have a really low IQ, I had to look at this problem as if it were a communication network. Setting a capacity of 1 on each edge and then computing max flow would give us edges with a flow value of 1 or 0. That means we either use the edge to communicate or we don&#8217;t (this is why we set a capacity of 1).</p>
<p>So, extending this thinking to problems that bipartite matching can solve, let us consider the simple problem:</p>
<p><strong>B is a set of boys who need to be paired up with girls in set G. Any boy can be paired with any girl. </strong></p>
<p>So, the solution would involve what we just did.</p>
<p>Now, we can modify the problem so:</p>
<p><strong>B is a set of boys who need to be paired up with girls in set G for a performance at their community center. Each boy can appear at most thrice and each girl can appear at most 4 times and a pair can appear at most twice.</strong></p>
<p>Extending my &#8220;communication network&#8221; idea, this problem can also be solved by computing a max flow on this network. But we need to set the capacities on each edge correctly.</p>
<ul>
<li>We have an edge from a source <strong>S</strong> to every boy. Now, a boy can appear at most thrice. This essentially means, the boy can be picked once, twice, three times (or if he really sucks, he might not be picked at all). So, the capacity you set on this edge is <strong>3</strong>.</li>
<li>Now, we have an edge from every girl to a sink <strong>T</strong>. Remember a girl can be picked at most 4 times. So, the capacity of the edge from every girl to the sink is <strong>4</strong>.</li>
<li>Now, each pair can appear twice so every edge from set <strong>B</strong> to set <strong>G</strong> gets a capacity of 2.</li>
</ul>
<p>That&#8217;s it. Computing max flow on this should give us a decent matching!</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/07/16/bipartite-matching-and-max-flow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bellman-Ford Algorithm&#8217;s Applications &#8211; Triangular Arbitrage</title>
		<link>http://shriphani.com/blog/2010/07/02/bellman-ford-algorithms-applications-triangular-arbitrage/</link>
		<comments>http://shriphani.com/blog/2010/07/02/bellman-ford-algorithms-applications-triangular-arbitrage/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 01:30:57 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[arbitrage]]></category>
		<category><![CDATA[bellman-ford]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[shortest-path]]></category>
		<category><![CDATA[triangular-arbitrage]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=582</guid>
		<description><![CDATA[Using the Bellman-Ford Single Source Shortest Path algorithm to detect triangular arbitrage. ]]></description>
			<content:encoded><![CDATA[<p>A very interesting application of the bellman-ford algorithm is arbitrage, essentially, given a table of currencies and their exchange rates, one needs to be able to figure out if we can start with a certain amount of money in one currency, exchange this amount for other currencies and end up with more money than what we had at first.</p>
<p>Example: 1 USD gives us 0.8 Euro and 1 Euro gives us 0.8 GBP and 1 GBP gives us 1.7 USD. So if I start with 1 dollar, I can exchange it for 0.8 Euro which can then be exchanged for 0.64 GBP and if converted back to USD we have 1.088 dollars.</p>
<p>So if rate_i_j is used to represent the amount of currency_j which we can get for 1 unit of currency_i, we observe:</p>
<p>rate_i_j * rate_j_k * rate_k_l * &#8230;.. * rate_z_i &gt; 1</p>
<p>Invert this to get:</p>
<p>1/(rate_i_j * rate_j_k * rate_k_l * &#8230;.. * rate_z_i) &lt; 1</p>
<p>and take lg on both sides:</p>
<p>lg(1/rate_i_j) + lg(1/rate_j_k) + &#8230;.. + lg(1/rate_z_i) &lt; 0</p>
<p>So we observe that if we represent our table using a graph with lg(1/exchange_rate) as the weights, then the presence of a negative weight cycle is all that is needed to ensure we get more $$ than we started out with.</p>
<p>And of course, negative weight cycle detection is really easy with the bellman-ford single source shortest path algorithm.</p>
<p>This algorithm operates by the following dynamic programming equation:</p>
<p>distanceFromSource(v) = distanceFromSource(w) + weight(w, v)</p>
<p>When we set the distance of vertex &#8216;v&#8217; from the source, we look at the edge (w, v) and observe that if we can get to &#8216;v&#8217; by a shorter path through &#8216;w&#8217;, we discard the old distance and set distanceFromSource(w) + weight(w, v) as the new distance. This operation is called &#8220;Relaxing an edge&#8221;</p>
<p>Now, we only need to observe every edge a certain number of times. Precisely |V| &#8211; 1 times. Why? Well, consider a graph where the max out-degree is 1.</p>
<p>So, we have something like: v1 &#8212;-&gt; v2 &#8212;&#8211;&gt; v3 &#8212;&#8211;&gt; v4 &#8212;&#8212;&gt; &#8230;&#8230;.. &#8212;&#8212;&gt; v{n}. This is a directed graph with n vertices. If our source is v1, in the first of |V| &#8211; 1 iterations, we relax the first edge and fix the path to v2 (cannot get to v2 using a shorter path see?). In the second iteration, the path to v3 is fixed and continuing this we finish fixing the paths to the vertices |V| &#8211; 1 iterations (Remember, you relax <strong>every</strong> edge in each iteration).</p>
<p>To detect a negative weight cycle, finish relaxing all the edges |V| &#8211; 1 times. Now, carry the relax operation out once again. Since, all paths from the source to each vertex are guaranteed to be fixed by now, if you ever stumble upon a situation where you change distanceFromSource(v) for a vertex v, then a negative weight cycle starts and ends at v. The result of this is that a shortest path to v cannot be found, since for every path to v, you can make another trip about this negative-weight cycle and obtain an even shorter path.</p>
<p>So, I wrote a simple script for the Bellman-Ford routine and tested it using the USD, Euro, GBP example.</p>
<p>Here&#8217;s the Bellman-Ford routine:</p>
<div class="dean_ch" style="white-space: nowrap;"><span class="co1">#!/usr/bin/env python</span><br />
<span class="co1">#Author: Shriphani Palakodety</span></p>
<p><span class="co1">#Bellman Ford Implementation. Look it up on wikipedia.</span></p>
<p>distances = <span class="br0">&#123;</span><span class="br0">&#125;</span><br />
parents = <span class="br0">&#123;</span><span class="br0">&#125;</span></p>
<p><span class="kw1">def</span> Initialize<span class="br0">&#40;</span>graph, start<span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; <span class="st0">&#8221;</span><span class="st0">&#8216;Prepares the graph for the bellman-ford algorithm&#8217;</span><span class="st0">&#8221;</span><br />
&nbsp; &nbsp; <span class="kw1">for</span> vertex <span class="kw1">in</span> graph.<span class="me1">V</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> graph.<span class="me1">E</span>.<span class="me1">has_key</span><span class="br0">&#40;</span><span class="br0">&#40;</span>start, vertex<span class="br0">&#41;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distances<span class="br0">&#91;</span>vertex<span class="br0">&#93;</span> = 9999999e6</p>
<p>&nbsp; &nbsp; distances<span class="br0">&#91;</span>start<span class="br0">&#93;</span> = <span class="nu0">0</span><br />
&nbsp; &nbsp; parents<span class="br0">&#91;</span>start<span class="br0">&#93;</span> = <span class="kw2">None</span></p>
<p><span class="kw1">def</span> Bellman_Ford<span class="br0">&#40;</span>graph, start<span class="br0">&#41;</span>:</p>
<p>&nbsp; &nbsp; Initialize<span class="br0">&#40;</span>graph, start<span class="br0">&#41;</span> <span class="co1">#first initialize the graph</span></p>
<p>&nbsp; &nbsp; <span class="kw1">for</span> i <span class="kw1">in</span> <span class="kw2">xrange</span><span class="br0">&#40;</span><span class="kw2">len</span><span class="br0">&#40;</span>graph.<span class="me1">V</span><span class="br0">&#41;</span> &#8211; <span class="nu0">1</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> edge <span class="kw1">in</span> graph.<span class="me1">E</span>.<span class="me1">keys</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>graph.<span class="me1">E</span><span class="br0">&#91;</span>edge<span class="br0">&#93;</span> + distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> &lt; distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span> = graph.<span class="me1">E</span><span class="br0">&#91;</span>edge<span class="br0">&#93;</span> + distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parents<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span> = edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span></p>
<p>&nbsp; &nbsp; <span class="co1">#one final check for negative weight cycles.</span></p>
<p>&nbsp; &nbsp; <span class="kw1">for</span> edge <span class="kw1">in</span> graph.<span class="me1">E</span>.<span class="me1">keys</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>graph.<span class="me1">E</span><span class="br0">&#91;</span>edge<span class="br0">&#93;</span> + distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> &lt; distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span> = graph.<span class="me1">E</span><span class="br0">&#91;</span>edge<span class="br0">&#93;</span> + distances<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parents<span class="br0">&#91;</span>edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span> = edge<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> edge<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> <span class="co1">#return here since, a negative weight cycle is detected</span></p>
<p>&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">None</span> <span class="co1">#return none on successful completion.</span></div>
<p>And the test itself:</p>
<div class="dean_ch" style="white-space: nowrap;">!/usr/bin/env python<br />
<span class="co1">#Author: Shriphani Palakodety</span><br />
<span class="co1">#Mail: spalakod@purdue.edu</span></p>
<p><span class="co1">#Testing Arbitrage</span></p>
<p><span class="co1">#import graph</span><br />
<span class="kw1">import</span> bellman_ford<br />
<span class="kw1">from</span> <span class="kw3">math</span> <span class="kw1">import</span> log</p>
<p><span class="co1">#in the format cur1_cur2 = no. of units of cur2 for 1 unit of cur1</span></p>
<p>usd_euro = <span class="nu0">0.8</span><br />
euro_gbp = <span class="nu0">0.8</span><br />
gbp_usd = <span class="nu0">1.7</span></p>
<p><span class="co1">#Nodes List</span><br />
nodes = <span class="br0">&#91;</span><span class="st0">&quot;usd&quot;</span>, <span class="st0">&quot;euro&quot;</span>, <span class="st0">&quot;gbp&quot;</span><span class="br0">&#93;</span><br />
edge_dict = <span class="br0">&#123;</span> <span class="br0">&#40;</span><span class="st0">&quot;usd&quot;</span>, <span class="st0">&quot;euro&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span><span class="nu0">1</span>/usd_euro<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="st0">&quot;euro&quot;</span>, <span class="st0">&quot;gbp&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span><span class="nu0">1</span>/euro_gbp<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="st0">&quot;gbp&quot;</span>, <span class="st0">&quot;usd&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span><span class="nu0">1</span>/gbp_usd<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="st0">&quot;euro&quot;</span>, <span class="st0">&quot;usd&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span>usd_euro<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="st0">&quot;gbp&quot;</span>, <span class="st0">&quot;euro&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span>euro_gbp<span class="br0">&#41;</span>, <span class="br0">&#40;</span><span class="st0">&quot;usd&quot;</span>, <span class="st0">&quot;gbp&quot;</span><span class="br0">&#41;</span> : log<span class="br0">&#40;</span>gbp_usd<span class="br0">&#41;</span><span class="br0">&#125;</span><br />
<span class="co1">#make a small graph to represent the currency network.</span></p>
<p>cur_graph = bellman_ford.<span class="me1">Graph</span><span class="br0">&#40;</span>nodes, edge_dict<span class="br0">&#41;</span></p>
<p><span class="kw1">print</span> bellman_ford.<span class="me1">Bellman_Ford</span><span class="br0">&#40;</span>cur_graph, <span class="st0">&quot;usd&quot;</span><span class="br0">&#41;</span></div>
<p>And when run, I get:</p>
<pre>?(shriphani@Shriphani-Palakodetys-MacBook-Pro)?(533/ttys001)?(09:10P:07/02/10)?-
??(%:~/scripts)?- python arbitrage_test.py
usd
??(shriphani@Shriphani-Palakodetys-MacBook-Pro)?(534/ttys001)?(09:10P:07/02/10)?-
??(%:~/scripts)?-</pre>
<p>So, there&#8217;s a negative weight cycle and if you kick off with some USD, you can get rich.</p>
<p>Get my routines here:</p>
<ul>
<li><a href="http://shriphani.com/scripts/bellman_ford.py">Bellman-Ford</a></li>
<li><a href="http://shriphani.com/scripts/arbitrage_test.py">Test For Arbitrage</a></li>
</ul>
<p>My code reads too much like pseudocode. Didn&#8217;t know a theory class corrupts so much.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/07/02/bellman-ford-algorithms-applications-triangular-arbitrage/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Decline of Journalism</title>
		<link>http://shriphani.com/blog/2010/06/27/decline-of-journalism/</link>
		<comments>http://shriphani.com/blog/2010/06/27/decline-of-journalism/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 23:36:18 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Daily life]]></category>
		<category><![CDATA[PITA]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=575</guid>
		<description><![CDATA[A rant on the media and its many shortcomings.]]></description>
			<content:encoded><![CDATA[<p>One of the more visible themes I observe on Gandhian values (Gandhian values = values that Gandhi lived by during and after the Indian freedom struggle) is that they are not valid in the 21st century. The arguments cited included that non-violent protest wouldn&#8217;t gain the attention of the media.</p>
<p>This concern is valid. Like most educated people, I have lost faith in modern journalism. India has generated a news channel ecosystem that dedicates solid portions of a day to exploring thought-provoking concepts like the afterlife, asks the leader of India&#8217;s neighbor (Pakistan) if surgical strikes by the Indian army on Pakistani soil would lead to war (I mean seriously, do you not know what sovereignty is?), spends time exploring conspiracy theories and here&#8217;s the kicker &#8211; engages in irritating nationalist worship. No, really. Since 2005, every article about Indians has had one tune: How rich Indians owning companies started by their grandparents, able to achieve monopolies in India through bribery, corruption and other questionable activities, are acquiring companies abroad and hence <strong>putting us on the world map</strong>.(nothing reeks of underdog behavior more than stating every Indian achievement as an assertion of our geographical boundaries) Every year we learn about <strong>Bollywood showing its power </strong>(they make movies. Why is it admirable if they can pull strings?).And every game India plays against Australia is about <strong>24+ aged men troubled by Aussie mind games</strong>. They are fucking adult men. They don&#8217;t need you to defend them because they are just as big dickwads as anyone else who is playing the game.</p>
<p>The Indian media is a fucking joke. I guess this is the curse of 24 hour news. You hire people to generate so much crap 364 days in a year to fill 24 hours of every one of those days that on the one day something important happens, you have the collective journalistic capability and insight of a mediocre high school graduate.</p>
<p>Don&#8217;t agree with me? Monopolies and oligopolies are the biggest curse you can heap on an industry. Yet, all of India&#8217;s most powerful industrialists are the media&#8217;s darlings. The BCCI has been glorified by the media for the power it wields over the cricket world. Yet this one organization is responsible for the future of India&#8217;s most popular sport. We are a nation of 1 billion. We cannot generate opportunities for such a large population through one organization that conducts 2 domestic leagues. This organization is so caught up with its lucrative ventures that the Indian team is guaranteed to be tired before any major event thus putting our chances of winning the world cup at a severe risk. The BCCI is bad for the nation. The media doesn&#8217;t even question its monopoly status and its aggressive behavior towards any players who participate in a non-BCCI-blessed league.</p>
<p>And of course I read this economic times masterpiece: http://economictimes.indiatimes.com/features/the-sunday-et/people/Its-time-we-beat-the-West-let-the-East-rise/articleshow/5681401.cms</p>
<p>The headline of the fucking story is, <strong>&#8220;It&#8217;s time we beat the West &amp; let the East rise&#8221;.</strong> Really? Here&#8217;s  a 2-bit manufacturer no-one knows anything about and he uses his only marketing avenue to speak about how he is the soldier in a war against a civilization. And the paper which is the &#8220;exclusive&#8221; marketing avenue (self-proclaimed) has reporters and editors with the IQ to publish this article. The kicker is that product will first launch in the United States. How is that for building goodwill?</p>
<p>Gandhi achieved what he did because he ensured that the injustice he faced did not go unnoticed. He took the blows and then ensured that this went on record and that the world got to see it. Non-violent protest itself wasn&#8217;t a powerful tool. It needed journalism from an unbiased organization to achieve its goals since this gave credibility to the protesters&#8217; cause. To combat non-violent protest, the oppressors had to adopt methods outside the legal system and it would be hard to pull this off quietly if you attracted the media&#8217;s attention.</p>
<p>I do not believe that our media is capable of assisting another Gandhi, if a situation ever calls for an individual to assume a role similar to his in India&#8217;s struggle for her independence.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/06/27/decline-of-journalism/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>1:18 Mercedes Roadster 500k</title>
		<link>http://shriphani.com/blog/2010/06/15/118-mercedes-roadster-500k/</link>
		<comments>http://shriphani.com/blog/2010/06/15/118-mercedes-roadster-500k/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 02:05:38 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Daily life]]></category>
		<category><![CDATA[1:18]]></category>
		<category><![CDATA[benz]]></category>
		<category><![CDATA[diecast]]></category>
		<category><![CDATA[mercedes]]></category>
		<category><![CDATA[roadster]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=560</guid>
		<description><![CDATA[Some pictures of my 1:18 die-cast Mercedes Benz Roadster 500k. ]]></description>
			<content:encoded><![CDATA[<p>I recently found this beautiful car on Amazon and decided to make it part of my collection. Here are some pictures I took.</p>
<p><a href="http://farm5.static.flickr.com/4024/4688144828_1ba8520d14.jpg"><img class="aligncenter" title="Mercedes Benz 500K Typ Special Roadster" src="http://farm5.static.flickr.com/4024/4688144828_1ba8520d14.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://farm5.static.flickr.com/4039/4687512583_2863a97c3f.jpg"><img class="aligncenter" title="Mercedes Benz Typ 500K Roadster" src="http://farm5.static.flickr.com/4039/4687512583_2863a97c3f.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://farm5.static.flickr.com/4004/4687512789_5815c10d0d.jpg"><img class="aligncenter" src="http://farm5.static.flickr.com/4004/4687512789_5815c10d0d.jpg" alt="" width="500" height="375" /></a><a href="http://farm5.static.flickr.com/4069/4688145766_5f82f63efa.jpg"><img class="aligncenter" src="http://farm5.static.flickr.com/4069/4688145766_5f82f63efa.jpg" alt="" width="500" height="375" /></a></p>
<p>For the entire list, head over to <a href="http://www.flickr.com/photos/11424398@N08/" target="_blank">my flickr page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/06/15/118-mercedes-roadster-500k/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hayabusa Re-Entry Video</title>
		<link>http://shriphani.com/blog/2010/06/13/hayabusa-re-entry-video/</link>
		<comments>http://shriphani.com/blog/2010/06/13/hayabusa-re-entry-video/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 21:09:04 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/2010/06/13/hayabusa-re-entry-video/</guid>
		<description><![CDATA[NASA&#8217;s jetliner flying over Australia captured Hayabusa re-entering the atmosphere. Here&#8217;s a link to the original:HayabusaRentryVideo.avi]]></description>
			<content:encoded><![CDATA[<p>NASA&#8217;s jetliner flying over Australia captured Hayabusa re-entering the atmosphere. Here&#8217;s a link to the original:<a href="http://archive.nserc.und.edu/~kml/HayabusaRentryVideo.avi">HayabusaRentryVideo.avi</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/06/13/hayabusa-re-entry-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://archive.nserc.und.edu/~kml/HayabusaRentryVideo.avi" length="45301808" type="video/quicktime" />
		</item>
		<item>
		<title>3 CNF SAT Fail.</title>
		<link>http://shriphani.com/blog/2010/05/21/3-cnf-sat-fail/</link>
		<comments>http://shriphani.com/blog/2010/05/21/3-cnf-sat-fail/#comments</comments>
		<pubDate>Fri, 21 May 2010 15:58:21 +0000</pubDate>
		<dc:creator>Shriphani</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[3-CNF-SAT]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[NP Complete]]></category>

		<guid isPermaLink="false">http://shriphani.com/blog/?p=554</guid>
		<description><![CDATA[So, at 2:00 am last night I decided I had completed my 3-CNF-SAT algorithm (which runs in polynomial time!!). Well, here is the pseudocode: ROUTINE(P): -> Make a hashtable 'h' of size 3 * no. of clauses -> For clause p in P: for each 'distinct' variable x in p: h[x] += 1 -> Find [...]]]></description>
			<content:encoded><![CDATA[<p>So, at 2:00 am last night I decided I had completed my 3-CNF-SAT algorithm (which runs in polynomial time!!). Well, here is the pseudocode:</p>
<pre>
ROUTINE(P):
-> Make a hashtable 'h' of size 3 * no. of clauses
-> For clause p in P:
	for each 'distinct' variable x in p:
		h[x] += 1

-> Find the variable with max frequency by going through hashtable 'h'.
-> Set this variable to True and remove those clauses from P in which this variable is present. Let this set be P'
-> Run this routine on P'
</pre>
<p>I knew it, this is right, this would work and would not fail. I was sure I had the answer.</p>
<p>BUT&#8230;</p>
<p>You really can&#8217;t answer yes or no using this technique:</p>
<p>For example, (x1 v x1 v x1 )  ^  (~x1 v ~x1 v ~x1) has no solution. But the above algorithm has no way of figuring that out. So, I fixed it by doing:</p>
<pre>
ROUTINE(P):
-> Make a hashtable 'h' of size 3 * no. of clauses
-> For clause p in P:
	for each 'distinct' variable x in p:  //when I say distinct variable, x1 and ~x1 are distinct
		h[x] += 1

-> Find the variable with max freuqency by going through hashtable 'h'.
-> Set this variable to True (and the negation of this var to false) and remove those clauses from P in which this variable is present. Let this set be P'
-> Check all removed clauses to see if all these clauses return True. If not, there isn't a solution
-> Run this routine on P'
</pre>
<p>Now, I have no idea how to prove that this doesn&#8217;t work (it doesn&#8217;t and I know it). </p>
<p>Oh well whatever. Some day, I will find out why this is wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://shriphani.com/blog/2010/05/21/3-cnf-sat-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
