<?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 Sunil on Medium]]></title>
        <description><![CDATA[Stories by Sunil on Medium]]></description>
        <link>https://medium.com/@sunils27?source=rss-f1c4edd6601------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NtUxcYDBvdlCbJfx.jpg</url>
            <title>Stories by Sunil on Medium</title>
            <link>https://medium.com/@sunils27?source=rss-f1c4edd6601------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:14:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunils27/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[Reduced Order Modeling using TensorFlow]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@sunils27/reduced-order-modeling-using-tensorflow-part-1-5697c49fb4d4?source=rss-f1c4edd6601------2"><img src="https://cdn-images-1.medium.com/max/1090/1*5NfONJy2b6Y_MrsFB6yDXg.jpeg" width="1090"></a></p><p class="medium-feed-snippet">While in grad school, I worked on an unsupervised machine learning (ML) problem with computational fluid dynamics (CFD) data (link to the&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@sunils27/reduced-order-modeling-using-tensorflow-part-1-5697c49fb4d4?source=rss-f1c4edd6601------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@sunils27/reduced-order-modeling-using-tensorflow-part-1-5697c49fb4d4?source=rss-f1c4edd6601------2</link>
            <guid isPermaLink="false">https://medium.com/p/5697c49fb4d4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pods]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[reduced-order-modeling]]></category>
            <dc:creator><![CDATA[Sunil]]></dc:creator>
            <pubDate>Thu, 18 May 2017 06:21:38 GMT</pubDate>
            <atom:updated>2023-01-20T15:53:29.290Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Simple Competitive Learning]]></title>
            <link>https://medium.com/@sunils27/simple-competitive-learning-4978717a7fc8?source=rss-f1c4edd6601------2</link>
            <guid isPermaLink="false">https://medium.com/p/4978717a7fc8</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[competitive-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sunil]]></dc:creator>
            <pubDate>Fri, 24 Feb 2017 00:01:29 GMT</pubDate>
            <atom:updated>2017-02-24T00:01:29.738Z</atom:updated>
            <content:encoded><![CDATA[<p>I spent some time in the recent past learning and implementing competitive learning algorithms. To start off, in this post I’m writing about simple competitive learning.</p><h4><strong>Competitive Learning</strong></h4><p>Competitive learning (CL) algorithms are a class of unsupervised learning algorithms that are typically used to cluster high-dimensional data. Given a dataset, the goal of CL is to compute a set of cluster centers that can be a compact representation of the original data. In mathematical terms, given a set of data {<strong>x</strong>}, find a set of clusters centers {<strong>c</strong>} that satisfy the relationship :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*dOLYpTyelaUaTwFdR4k9-A.png" /></figure><p>i.e., the distance of the <em>p </em>th vector in {<strong>x</strong>} from its closest cluster center must be less than (or equal to) its distance from any of the other cluster centers.</p><h4><strong>Simple Cluster Center Update Algorithm</strong></h4><p>To start with, the following simple example with two-dimensional data is considered to go through the concepts relatively easily. To begin with, the cluster centers (or neurons) are initialized randomly. Each data vector in {<strong>x</strong>} is then evaluated against each cluster center. The cluster center that is closest to the (<em>p th</em>) vector being evaluated is termed the <em>winning center </em>(or Best Matching Unit-BMU). This neuron is said to be activated when it is BMU. Once the winning neuron is found, it is updated (moved closer) to the <em>p th </em>vector using the relationship:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*fTQUf4GoL3egqDioinT15w.png" /></figure><p>It is important to note that <em>only </em>the winning center is updated. Here <em>ϵ </em>is the <em>learning rate</em>, a “hyper-parameter” that dictates the rate at which cluster centers get updated i.e. the distance by which they move in the two-dimensional output space. For this simple algorithm, I’m going to use a constant user-specified learning rate <em>ϵ.</em></p><p>The distribution of the two-dimensional data is shown below. It is simply a set of randomly generated points in the range [-2.0,2.0] in both the <em>x </em>and <em>y</em> directions. Since this is an introductory example I will be using only 4 randomly selected points as cluster centers, so we expect to see 4 clusters as the output. The cluster centers are shown as black triangles in the figure. The initial positions of these centers are close to the origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*yaDSUloijGs9yCoxNfKwxA.png" /></figure><h4><strong>Python Implementation</strong></h4><p>The programmatic implementation of this algorithm in python is straightforward and the code is posted here. With a learning rate <em>ϵ=0.01 </em>the algorithm was run 1000 times to update the cluster centers. Note that a <em>convergence criterion</em> was not specified in this case. The resulting cluster centers are shown below with the yellow triangle markers. It can be seen that each cluster now has a corresponding <em>center. </em>Data is colored by the ID of each winning neuron. You can see that all the data has segregated into 4 neat clusters. However, since there is no convergence criterion specified the winning centers are not at the geometric centers of each of the regions. The update equation (above) is influenced by the order of the points that are passed though it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*INIvvgUCZhyM23Eikxi5VQ.png" /></figure><p>As an experiment, to see what other clusters the algorithm could come up with, I removed the pseudo-random number seed and let the algorithm initialize with completely different values on each run. There was one that was particularly interesting (below); to see the blue cluster align itself along the boundary of three major clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*u6NjUW6qxHlc5lZ8BJ0vBg.png" /></figure><p>I ran some more “standard” two-dimensional clustering scenarios using datasets from <em>sklearn</em>. Below are the results for the noisy two-moons, blobs and, two-circles datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*fvKX5oN0802QRlVPXbC3PQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*K2WV9MYe3FFkNbp_yMl-LA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*7YJdgcOTpEsUSlXr_w4_7Q.png" /></figure><h4><strong>Final thoughts and improvements</strong></h4><p>This is a simple center update competitive learning algorithm, but it still produces very reasonable results. It is important to note that the center update equation is influenced more by the data that it has seen later as opposed to earlier, for example, <strong>c</strong>²¹ (the center vector at iteration 21) is influenced more by <strong>c</strong>¹⁹ than by, say, <strong>c</strong>⁵. This can be proved mathematically (Kirby). This is important because the order in which the data is presented to it can influence its final location especially with a fixed learning rate.</p><p>Another significant drawback of this algorithm is its inability to take into consideration <em>regions of influence. </em>Each cluster center has some proximity to other centers (in the output mapping space) and this is not considered in the update equation above. In other words, if the cluster centers are considered neurons, and <em>only</em> one of them is active for a given input vector. By considering a region of influence, its neighboring neurons can also be activated, albeit to a lower magnitude, and neurons far away from the winning neuron have a very low magnitude and hence a negligible influence.</p><p>These drawbacks are addressed by Self Organizing Feature Maps algorithm which I will be writing about in my next post on competitive learning.</p><h4><strong>References</strong></h4><ol><li>Geometric Data Analysis, <em>Michael Kirby</em>.</li><li>Neural Networks &amp; Learning Machines, <em>Simon Haykin</em>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4978717a7fc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Processing geospatial data with AWS Lambda]]></title>
            <link>https://medium.com/@sunils27/processing-geospatial-data-with-aws-lambda-9085d98fe48d?source=rss-f1c4edd6601------2</link>
            <guid isPermaLink="false">https://medium.com/p/9085d98fe48d</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[geospatial]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Sunil]]></dc:creator>
            <pubDate>Sun, 22 Jan 2017 00:44:55 GMT</pubDate>
            <atom:updated>2017-01-22T00:44:55.401Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been trying out several things with AWS Lambda recently. I’m writing about some of my learning and experiments of using AWS Lambda functions with geospatial (location) data.</p><h4><strong>AWS Lambda</strong></h4><p>AWS Lambda is a part of Amazon’s serverless compute infrastructure. Lambda functions can be invoked in response to events triggered by other AWS managed services like DynamoDB, the Simple Storage Service (S3), API gateway and a few other services. Lambda allows code execution without the need for provisioning EC2 instances, so it obviates the need for managing servers, reducing the total cost of ownership in addition to lowering maintenance costs over the long-term. As a result, you pay only for the compute time utilized by the lambda function, in 100ms increments.</p><p>Since there’s no instance provisioned, developers cannot make any assumptions on persistent data on local disks. Lambda functions are “packaged” in containers and the Lambda function is invoked when a corresponding event gets triggered.</p><p>I don’t plan on going into details about the API since the <a href="http://docs.aws.amazon.com/lambda/latest/dg/java-programming-model-handler-types.html">AWS docs</a> do a great job. I will however, setup a simple example (using Java) and follow it up with a more interesting and (somewhat) practical application involving geospatial data. For the Lambda function to be triggered by a user invoked end-point, I first had to create one.</p><h4>Setting up an end-point using API Gateway</h4><p>This blog has lots of information on creating an API end-point using the API gateway. The key here is to use the appropriate <em>body mapping</em> <em>template </em>so that the entire JSON payload from the end-point gets passed through to the Lambda function.</p><h4><strong>A Simple Example</strong></h4><p>Once the API end-point has been created, it is now time to write the Lambda function. A Lambda function implementation in Java needs a specified <em>handler</em> in order for AWS Lambda to invoke it. In this simple example, I will create a Lambda function that will create a new file in an S3 bucket (<strong><em>locationdatabucket</em></strong><em>) </em>every time it is invoked. Pretty simple. The input data to the Lambda function comes from an API end-point (a POST request) created using the API gateway. This gateway end-point invokes the Lambda. I will be using simple Java types for both the input and output. I’m naming this Lambda <em>CollectData.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*4Z0rXVfV0bQagjjNkDcfwg.png" /><figcaption>Lambda triggered by user input via API gateway</figcaption></figure><p>The handler method is shown below. It accepts an InputStream and returns a stringified JSON as the output. The output is of course optional and one can return a void as well. Depending on whether the Lambda is called synchronously or <a href="http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-lambda.html">asynchronously</a>, the return type can change. Also, asynchronous invocation requires setting up Lambda proxy integration. Here the Lambda function is going to be called synchronously.</p><pre>public String handleAPIGatewayRequest( InputStream inputStream, OutputStream outputStream, Context context) ){<br> <br> ...</pre><pre> ... <br>}</pre><p>I consider a simple situation where the location of a user is captured and sent to the API end-point, say, by a mobile or web application. The end-point accepts a payload that includes the latitude and longitude and is passed through in its entirety to the Lambda function. The Lambda function then creates a file in an S3 bucket with the following information, in JSON format.</p><pre>UserId, Latitude, Longitude, Timestamp<br>123456, 37.42918, -122.1225, Jan 5 2017 12:39:03PM</pre><p>Every user location gets saved in a new file in the S3 bucket. Given that location information is (usually) ephemeral, we can do fancier things like separate out buckets by time-of-day, city, etc. For the purposes of keeping this post focused and concise I will not be considering these cases.</p><p>Now that the first Lambda is complete, I will add some more complexity and yet another Lambda function to perform a different computation based on the data collected by the <em>CollectData</em> Lambda function.</p><h4><strong>Adding some complexity and another Lambda function</strong></h4><p>Consider the simple extension where we need to find the subset of users that are closest to any given user. This functionality can be exposed to the caller via an API gateway end-point (GET request). For the distance query to operate on geospatial data, all the user locations (ideally, within a certain time-window) must be indexed. Once indexed, given a reference location, the index can be queried for the closest neighbors within a certain distance of the reference. The <a href="http://tsusiatsoftware.net/jts/main.html">Java Topology Suite (JTS)</a> can be used to create a Quadtree index for all the user location files in the S3 bucket.</p><p>I’m going to create a second Lambda function to index the geospatial data and call it <em>LocationIndex. </em>As user location files are created in the S3 bucket (locationdatabucket) by the <em>CollectData</em> Lambda, the <em>LocationIndex</em> function picks up the latest unprocessed file and updates the Quadtree index. So, the <em>LocationIndex</em> function first creates and then updates a spatial index. The <em>LocationIndex</em> lambda is triggered by an S3 event (unlike <em>CollectData</em> which was triggered by an API end-point).</p><p>The important piece here is: the index cannot be re-created on every invocation i.e. every time this lambda function gets called, since it’s an expensive computation. The index needs to be stored and updated as new locations get added. To solve this problem, the index is serialized and stored in another S3 bucket <strong><em>(locationindexbucket)</em></strong>. Every time a new location is updated in the <em>locationdatabucket, </em>the <em>LocationIndex</em> Lambda function picks up the new location, gets the index from S3, updates it with the new information and puts the updated index back into S3 <em>(locationindexbucket)</em>. It is important to note that S3’s <em>eventual consistency</em> model can interfere with the timeliness of updates on the <em>locationindexbucket. </em>So one needs to be careful, especially if the expectation is real-time consistency for queries on the index.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*--pH9CfFjcfQEv7weY99_w.png" /><figcaption>LocationIndex Lambda triggered by new locations</figcaption></figure><h4><strong>A third Lambda</strong></h4><p>I will now be adding a third Lambda that only reads in the quadtree index created by <em>LocationIndex</em> and queries it to find the closest points to a given reference point. I’m going to call this <em>FindClosest</em>. This Lambda function, on every invocation first gets the index from S3 and queries the index for all points that lie within a specified distance. The <em>LocationIndex</em> lambda function is “fronted” by an API gateway end-point (GET request), whose query-string includes the reference point and distance which are used to query the index. A point to be noted is that end-points trigger the first and third lambdas while the second lambda is triggered by an S3 creation event. In essence the lambdas are “communicating” indirectly through user inputs and other services and not with each other directly. The complete picture is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*9iGUTgTaqlorCQ5erxVxoA.png" /><figcaption>The complete data flow</figcaption></figure><h4><strong>Improvements</strong></h4><p>By no means is the technique described here meant to be bullet-proof. Creating a file in S3 for every event is really inefficient. A MUCH more efficient approach would be to update a <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> table or a <a href="https://aws.amazon.com/kinesis/">Kinesis</a> stream and have a Lambda function be triggered by the update. I have a working version of this improvement and will be writing a (short) post about it soon. I am exploring AWS step functions and plan to use it to orchestrate several lambdas.</p><h4><strong>Finally</strong></h4><p>This example shows how AWS Lambda functions can be used with geospatial data and some of the trade-offs that need to be made. It is also representative of how lambda functions can be used to create micro-services that can function independently as well as get invoked as a part of a larger sequence of tasks. Since lambdas have timeouts (maximum 5 minutes), it is not possible to run tasks that take longer than that time period per lambda.</p><p>Any comments or feedback is appreciated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9085d98fe48d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrading my Alienware Aurora desktop GPU]]></title>
            <link>https://medium.com/@sunils27/upgrading-my-alienware-aurora-desktop-gpu-e98d42ae22c?source=rss-f1c4edd6601------2</link>
            <guid isPermaLink="false">https://medium.com/p/e98d42ae22c</guid>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[alienware]]></category>
            <category><![CDATA[upgrade]]></category>
            <dc:creator><![CDATA[Sunil]]></dc:creator>
            <pubDate>Sun, 15 Jan 2017 17:14:20 GMT</pubDate>
            <atom:updated>2017-03-03T22:12:45.015Z</atom:updated>
            <content:encoded><![CDATA[<p>I have an Alienware Aurora desktop that I bought back in early 2010. It’s a great machine and has served me well over the last few years. I’m not much of a gamer, but I bought it for the GPU which I used primarily for computational work. My learning and implementation of some deep neural networks has necessiciated a decent GPU and I decided to upgrade my Alienware desktop.</p><h4><strong>The problem</strong></h4><p>The machine had an <a href="http://www.geforce.com/hardware/desktop-gpus/geforce-gtx-260/specifications">NVIDIA GTX 260</a> graphics card with 192 CUDA cores and 1.8 GB memory (yes). It also has two PCI-e 2.0 slots for graphics cards. While the GTX 260 was great for (circa) 2010, it is not very useful now. With several architecture updates over the years and NVIDIA packing in a lot more CUDA cores now, there is VERY LIMITED use for a GTX 260.</p><p>Also, I have in the past used an AWS GPU P2 on-demand instance for some neural network training experiments I was running. While this was convenient, it cost me an additional 45$ on my AWS bill for about 40 odd hours of experimentation and training. Considering that the 40 something hours were clocked in about 3 calendar days, it convinced me to seriously explore the possibility of upgrading my GPU. So, I started looking for a replacement GPU for my Alienware Aurora.</p><h4><strong>Finding a GPU</strong></h4><p>There are obviously several options here for <a href="https://www.nvidia.com/en-us/geforce/products/10series/geforce-gtx-1080/">high</a> to <a href="http://www.fool.com/investing/general/2016/04/06/heres-everything-you-need-to-know-about-nvidias-12.aspx">“unlimited”</a> budgets; but my search was restricted by the following parameters:</p><ul><li><strong>NVIDIA GPU : </strong>I considered getting a Jetson TX1/TK1, but then realized that the ARM processor would most likely limit the libraries that I can install on it. For example, TensorFlow is not (yet) supported on a Jetson (there are <a href="https://github.com/tensorflow/tensorflow/issues/851">roundabout ways</a> of getting it to work, but non-ideal for my purposes). So I decided that a Jetson board would not be the right direction to go. For somewhat similar reasons I did not want to go the AMD Radeon route either.</li><li><strong>Price</strong> : I limited the price to the 150–250$ range. This is what I was willing to spend.</li><li><strong>Power Supply Unit </strong>: While I initially thought this might be a major problem, turned out my Aurora desktop has a 875W PSU. I had to search my email history and dig up the specs of my machine for this information. It turned out to be a non-issue. I can actually add a second GPU and still be OK.</li><li><strong>Memory </strong>: Based on my plans for using the new card, 2GB of memory would be sub-optimal and insufficient over the long term. I would need atleast 4GB and ideally 6 GB. I’d love 8GB, but I was pretty sure I wouldn’t get one with what I was willing to spend.</li></ul><h4><strong>What I found</strong></h4><p>I found several options within my search parameters:</p><ul><li><strong>GTX 960 </strong>priced at about 200$ for the 4GB and 1024 CUDA cores. I even found one at the local Fry’s that was selling for about 150$ because it was an open box. Unfortunately, by the time I got there I was told it was being used in another system build.</li><li><strong>GTX 1050 Ti </strong>priced at a little less than 200$ for a 4GB and 768 CUDA cores, it looked a little pricey for the performance.</li><li><strong>GTX 970 </strong>which was priced over my budget at about 300$ for a 4GB. I was willing pay extra for this if I didn’t have any other options (an unlikely scenario).</li><li><strong>GTX 1060 </strong>priced about 260$ for the 6GB and 1280 CUDA cores. At about 10$ over my budget and an additional 2GB of memory compared to the others, it seemed quiet reasonable so I ended up purchasing it (EVGA). The local Fry’s even price matched with an online competitor.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*Pe_oR26h1i9psh3C67Tc2w.jpeg" /></figure><h4><strong>Installation</strong></h4><p>The installation of the GPU itself was pretty simple. The Alienware Aurora has a convenient latch mechanism to open the side panel. Once its open, theres a plastic casing that needs to be lifted to reveal the GPU, motherboard and other components.</p><p>What surprised me a bit when I opened it up as a red-white cable connecting the motherboard to the GPU. It was obviously not the 6-pin power adapter. It surprised me because the new GTX 1060 had no slot for such a cable. I finally saw the SPDIF label on the motherboard and realized I didn’t need that anymore with the 1060. The rest of the installation was pretty easy and I was done and powered up my system in less than 15 minutes. The driver installation and CUDA 8.0 install both went well.</p><h4><strong>Quick Test</strong></h4><p>As a quick test I built the NVIDIA CUDA samples and ran <em>deviceQuery </em>to make sure everything works. Now to put this to work!</p><pre>Detected 1 CUDA Capable device(s)</pre><pre>Device 0: “GeForce GTX 1060 6GB”<br> CUDA Driver Version / Runtime Version 8.0 / 8.0<br> CUDA Capability Major/Minor version number: 6.1<br> Total amount of global memory: 6144 MBytes (6442450944 bytes)<br> (10) Multiprocessors, (128) CUDA Cores/MP: 1280 CUDA Cores<br> GPU Max Clock rate: 1835 MHz (1.84 GHz)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e98d42ae22c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>