Monday, October 31, 2016

Genetic algorithms: Gaming our life goals


This is the second of my 2-part post on Genetic Algorithms (GA). While the previous post introduced the concept and highlighted the salient features of why I find GA fascinating, this post is an attempt at applying this technique to improve our personal lives.

To summarize the basics, following are the defining aspects of Genetic algorithms, when you apply this to solve an optimization problem:

  1. Population: Begin with multiple solutions (random & inefficient, to start with)
  2. Evaluation: Set a measurable criteria to evaluate effectiveness of the solution against a target
  3. Selection: Select the (relatively) top-ranked solutions, and kill the rest
  4. Recombination: Combine these top solutions (say 10%) in some manner to create the next generation of multiple solutions
  5. Mutation: Once in a while, instead of the usual Recombination (step #4), create new solutions with some unusual (maybe illogical) logic 
  6. Evolution: Iterate with these new solutions and loop through steps #1 through #5 to keep improving solutions, generation after generation until target is achieved


Now, for the parallel to our personal lives and how Genetic Algorithms could possibly come to our rescue. Read each of the below in conjunction to the concepts numbered in the same order 1-thru-6, above:

  1. Cultivate multiple habits or choose several activities (say 10 to 15) to pursue at work/home. 
    • For instance, joining a gym, waking at 5 AM, setting 1 hr of no-gadgets time every day.
  2. Set some end-goals that can be used to measure against. Now periodically (say once a month) evaluate whether each of the habits/activities are taking you any closer to the stated goals. 
    • Examples for goals include, learning a new skill, achieving something at work, reducing 15 kg weight, spending more time with loved ones.
  3. Continue with those few habits (say top 5)  that propel you towards the goals and discontinue all other activities.
  4. Alter the habits slightly by learning from things that worked out. Create variants of new activities (totally the earlier 10 to 15) that are directionally towards your goals.
    • For instance, you might try zumba instead of the gym, or wake up at 5.30 AM.
  5. Once in a while, break your routine and add some completely random habits, preferably things that make you uncomfortable.
    • You may decide to spend one day of your weekend walking around the city on foot, or maybe spend few days every month in the most remote & unconnected part of your state.
  6. Continue with this process and iterate with new & improved habits, say every month, until you reach the goal.

One might wonder that parts of the above process look intuitive and some of these could be things one already does. In my opinion, this becomes immensely powerful on account of four things: Choosing a larger set of habits,  measuring them against a set goal periodically, continuously tailoring the habits or totally killing them. Finally the most powerful one is in consciously breaking routine and adopting some bizarre habits.

Let me know what you think.


Genetic algorithms explained: Evolutionary way of problem-solving


I recently learnt about Genetic Algorithms (GA) and must say I've been quite fascinated by it. This is a two-part blog post on this topic. In this first post I will make an attempt to explain it in non-technical terms, with a simple example to illustrate the concept. The second post would be on applying this technique beyond the realm of business problems - by contemplating on how one could apply this to improving some aspects of our lives.

Now onto Part-1.

I had blogged earlier about Biomimicry, which in simple terms is design inspired by nature. Genetic Algorithms fall into the same category of solving human-faced problems, by getting inspiration from nature's solutions. In other words, this is the discipline of copying how nature operates in a bid to come up with similar harmonious solutions.

Placing Evolution in Perspective

To understand Genetic Algorithms, we'll try and understand the biologics of evolution, by using the bare minimum terminologies. 

  • We are way too familiar with how one generation of humans are smarter than the previous ones. We, collectively are more evolved and (perhaps) smarter than our ancestors, while the same can be said of our kids who are way ahead of us, thanks to evolution. 
  • Per the theory of natural selection, organisms better adapted to their environment tend to survive and produce more offspring. By survival of the fittest, the more evolved species reproduce more and pass on their genes down the line, while the weaker ones slowly die and get extinct.
  • And, there is this quirky process midway wherein some organisms suddenly have completely unexpected traits. There are the geniuses, those highly regarded people in history of mankind with IQ levels closer to 200, like Leonardo Da Vinci. You've most likely heard of rare people with 6-fingers in a hand, which is also quite unusual. All these are likely cases of mutation, wherein suddenly an unexpected change happens, in otherwise linear, incremental evolution. If this change is strong enough to influence rest of the species, it spreads through reproduction and impacts the subsequent generations. Else, it just stays an aberration and doesn't get passed on. To get this in perspective, think X-Men!
In summary, a species of organism keep adapting to their environment, incrementally evolving and getting smarter. The smarter ones survive and reproduce more, while the weaker ones die. Once in a while, there is a sudden & unexpected change in traits of few organisms within the species and if this is remarkable and powerful enough, it gets passed on to the next generation and slowly spreads to become the defining characteristic of the entire species. Else, the mutated offspring dies and doesn't impact rest of the species.

GA: Application to Problems

What if we try and apply this evolutionary biological process to solve problems in the area of optimization. We can create a computer program that exactly mimics this process of evolution by keeping all the ground rules coded in its entirety, grow solutions from generation-to-generation, until we arrive at an optimized solution that is more efficient than a set threshold.

To illustrate with an example, lets take the popular problem of Travelling Salesman. Given a set of 5 cities that a Salesman has to travel to (exactly once to each city), the problem is to find the route that minimizes the distance travelled by the person. This is an optimization problem and while its simple to solve by hand for the 5 cities, it becomes non-trivial if you increase the number, to say 30 cities.

Applying Genetic algorithm to this problem: 
  1. Start with a population containing a set of multiple random solutions - that is, multiple ways of ordering the 5 cities. 
  2. For each of the solutions in this 1st generation population, evaluate by computing the total distance travelled. Order the solutions from best to worst (within this iteration).
  3. Select the top 2 or 3 solutions with their ordering.
  4. Marry within this solution by randomly exchanging routes between the solutions (while sticking to ground rules, such as no repetition of cities). This step mimics the reproduction or recombination, as it happens in nature.
  5. The above step creates the next generation with a set of new potential solutions.
  6. Once in a while (say every 10th iteration), introduce mutation by performing a random operation. For example, you could swap every pair of cities in the route created until that step.
Repeat the same process from step #2 through #6 above, until you arrive at the solution with the lowest distance travelled. Each iteration is the equivalent of one generation and through the process of evolution, each subsequent iteration would have atleast some solutions which are slightly better than the earlier ones. You might iterate through this 100s or 1000s of times depending on the problem, but this process is guaranteed to come up with the most optimal solution.

Summary

The fascinating aspect about this technique is that you can arrive at the best possible solution, and possibly the global minima to any optimization problem. You just need to code this in the structure & process as outlined above, and without getting into construction of complex mathematical equations or their solutions, you can get the best solution through an evolutionary search procedure. Check this article for a more detailed explanation. They seem to be applied to a variety of real-world problems, and they sure hold a lot of promise.


Friday, October 28, 2016

How to read 100 books in a year


I lifted this post title straight from an article on Zapier titled 'How to Read 50 Books a Year, in 7 Easy Steps'. I just doubled the number to make it more appealing.

Though worded like a clickbait title, the author, Stephen Altrogge's content captivated my attention. He offers some sound, practical advice and this was stuff I wasn't practicing, or just didn't know a year earlier. In the light of my dismal progress on my Goodreads 2016 challenge, this is advice worth re-emphasizing to myself.

Let me summarize 5 of the tips I could relate to, here. For a full read, please check out the original post that has several good examples and useful references:

#1: Make your book list.
This helps to not only stay on top of your reading list, but the social integration with friends, recommendations and newsletters keep your motivation levels high.
> I set up mine on GoodReads just earlier this year.

#2: Begin reading atleast 2 books at a time.
To account for mood fluctuations and change in interests at different times of the day/week, this tip retains you within the realm of books. Else, you might end up watching movies, reading endless feeds on Facebook or whatnot.
> I never did this consciously earlier, since I considered it sacrosanct to finish one book cover to cover, before picking up the next.

#3: Read in small chunks.
10 minutes is good enough to catch up on some portion of the text and you don't need hours together to settle down with a book. This is another area where read-out-aloud apps can come in handy.
> This was a liberating tip to break my mental block of the need for atleast an hour to pick up a book.

#4: Learn to increase your reading speed.
Increase your throughput and you increase your net output. There is definite benefit in speed-reading books and I was surprised to hear about browser-extensions and apps that train you on this.
> I have an average reading speed and if the content gets interesting I slow down to savour every word, and take some moments to live the experience vicariously. This tip is something to be tried out.

#5: Be selective with your reading choices.
Life is too short to finish a bad book. There's no shame in putting a book aside or not finishing it, in order to get most out of the next book that you'll actually enjoy finishing. And for some books reading every word might be an 'overkill', and there is a 'layered' approach to get a general understanding of the book.
> This was another revealing tip. A habit closely tied to #2 above, I used to loathe dropping a book midway and there are occasions I had to push myself several weeks to get over to the last page. 


-->

Thursday, October 27, 2016

Your neighbourhood traffic signal could get smarter, and catch violators


Ever since the online system for traffic chalans went live in Hyderabad, one sees fewer incidents of cops talking (read negotiating) with traffic signal violators, who stand meekly by the roadside, trying to pull a trick or two (or some rupee notes) from their bag to go free.

Over the past few years, a camera wielding cop evokes more fear from the public than a lathi wielding constable! Any signs of a violation, the traffic constable clicks a picture of the vehicle with the number plate and promptly upload them online. The online system, app reminders and mobile notifications take care of the rest.

The online system has indeed been a welcome change. However, this isn't to say that the 'negotiators' have been totally done away with. Moreover, the lack of a cop by the road-side makes many a motorist go berserk, given that there isn't the 'papparazi' to catch one in action.

This is one area where computer vision, image processing and automation can simplify lives further, and bring about some orderliness. Imagine if HD CCTV cameras are setup at every junction or major points in the roads. Now, computer vision can process the streaming images, make out the number plates and potentially alert remote personnel on traffic violations. Upon confirmation, a traffic challan can be immediately raised. A futuristic version of this system, could process everything fully automatically.

This not only automates & simplifies traffic monitoring and law enforcement, but also effectively does away with any chance of 'negotiations' and out-of court settlements! Importantly, this instills a fear of the unknown in the public, that someone is perpetually watching over one's shoulders and that no violations would be spared.

Such a system is very much possible today with advances in image processing and computer vision, while the streaming loads can be handled by a standard big data setup with a Hadoop/Spark cluster. Revenues from the challans and enforcement will more than cover the cost of high quality cameras as well.

Friday, September 30, 2016

Google Now and its Indian predictions

I've been tracking Google Now for a while. However, Google did not push most of the features in India, though they have been rolling out incremental capabilities in US and few other geographies over the past years. 

In the past few months I was excited to see Google Now cards being gradually pushed onto my android mobile. I've been checking the cards, customizing preferences and feeding inputs based on the suggestions it had been surfacing. For instance, there are cards for weather alert, stock movements and news story suggestions based on browsing history. Few weeks back, I was glad to notice stories suggested from my Feedly account, based on Google Now's integration with the Feedly app. 

Couple of days back, I was amazed to see Google Now push a travel card, alerting me to leave for the office at 9.10 AM. I later figured that this was based on a meeting in my calendar that was setup at my office; this was combined with my home location, and by figuring out the possible routes and travel times, Google noticed a surge in traffic on that day. Per its calculations, the usual 30 minute journey was supposed to take 50 minutes, and hence it prompted me to leave immediately. 

Amazed with this alacrity, I left home a bit earlier and indeed found the traffic to be excessively bad that day. I duly checked back with Google on the best route for the day, and it showed me a off-road route, under the Hafeezpet railway bridge as the shortest one, while my usual route was projected to take 40 minutes longer than usual. Grateful to Google, I took up this route which was something I used to take very occasionally. True to the predictions, I encountered very less traffic on the route, inspite of all other roads being clogged.

With everything going picture perfect right from the start & in a dreamy state, I was woken up with a rude shock when I saw that the underpass road was filled with water upto 3 feet, from the previous day's heavy rains! That was perhaps the reason for less traffic on this particular route. Taking a U-turn, I went back to my usual route, and spent an hour longer commuting to the office. I had the Google assistant turned off for the rest of journey.

The Indian market is indeed unique and a tough one to crack! Hope the Now Cards algorithms learn its peculiarities soon enough to get accustomed to this market.

Monday, September 19, 2016

A 'rocky patch' for Hyderabad's Rock structures


Hyderabad has a defining characteristic. No, I'm not talking Biryani, but the famed rock structures that dot this city. Banjara Hills and Jubilee Hills are perhaps as popular as Charminar. One can find a series of undulating terrains and rocky structures not just in these localities, but pretty much throughout the city.

These charming structures would pause anyone in their tracks and make the people wonder as to how they've managed to achieve the unique balance.
Rock structure at Ghar-e-Mubarak, near Golconda Fort


Hyderabad is blessed with so many such structures and clusters of rock formations.
Rocks at BITS, Hyd (Pic: Shailesh Jain) Balancing boulders (Pic: TribuneIndia)

The sad part of the story is that the city is fast losing these landmarks. As Hyderabad keeps getting more attractive as an investment destination and the land value goes through the roof across the city, the first casualties are these structures.
Before (A patch of land near my office) ... and After

Its a common sight to see an entire rock hillock get levelled to further commercial interests.
Check out this hillock.. ..and the work in progress to level it

Khajaguda, an adventure enthusiasts favourite, and a second home to my club, GHAC (Great Hyderabad Adventure Club) is at the verge of getting wiped out. This place has hundreds of acres of fascinating rock structures. Unfortunately, this has not been spared as well, and over half of this place has already been blasted to dust.
GHAC bouldering event at Khajaguda

There are some good souls fighting for the rocks. There is the 'Save Rocks Soceity', a 20 year old organization that has been taking up the cause of rocks, and has also got few of the sites declared as heritage-rock-sites by the government, to bring them under a protective umbrella. They do a lot of awareness campaigns and events like the famed 'Hyderabad Rockathon' in partnership with GHAC.

Unfortunately, this is too little and needs more public support, financial muscle and support from the power corridors to really save Hyderabad's most popular landmarks, which are perhaps more historic than the Charminar. After all, rocks take a few thousand years to form and they are now going through a mass extinction - great structures blasted & levelled in a few seconds.

Saturday, September 03, 2016

Facebook's misstep on data privacy with Whatsapp


Facebook received bad press yet again last week, after its internet.org fiasco in India, several months back. You might have got a notification on your Whatsapp that the 'terms and conditions' had changed and you'd need to 'accept' them to continue using the services. One of the key changes in this was the user's implicit permission to let FB use their Whatsapp profile info to sell more targeted ads on your Facebook account. 

Image source: Techcrunch
And, this created considerable outrage, with a lot of messages going viral (within whatsapp!). There were talks of privacy breaches and how Facebook has started invading more spheres of our private lives. The messages also educated users with a simple set of steps on how to turn this setting 'off' in Whatsapp.

If for a moment you take a dispassionate look at the whole thing, it doesn't appear to be so alarming. Here is a parent company (Facebook) trying to cross-leverage its presence and services with a subsidiary (Whatsapp, which it bought for a bomb of $20 Billion), to better monetize the user base. The users were anyway getting both the services for free. And the new terms clearly stated that only the whatsapp user profile details would be used and none of the chats, groups or other interests would be shared.

Then why the outrage? Its not new in the B2C space for companies to cross-leverage or cross-sell services across their spectrum of products or subsidiaries. Take Google for instance, who has systematically achieved deep integration amongst their wide gamut of products, wherein consumer intelligence from one product enriches the others. But, the fundamental difference here is that the features for the user have always come in first and hence have been well received (though not without its share of suspicion); like the smart Google Now that simplifies your life. Facebook has erred by putting the carriage before the horse, and attempted to monetize first without linking the two for user's gain.

This apart, a side issue has been the perceived dishonesty or malicious intent in the way users have seen FB roll this out. The nature of an implicit, hidden agreement that kicks in when a user 'accepts' T&C certainly didn't help. When you try checking-off the box to disagree on usage of your profile info for ads, the prompt checks 'Are you sure you want to do this? You'll never be able to change this ever again'. Why should this sound like a once-in-a-lifetime favor that FB is doing you. After all, its a user preference and one might be okay to go back and enable the link when they see some benefits coming their way.

Finally, another undercurrent for all of this is the extremely accurate and targeted nature of the ads on Facebook, which has put off a lot of people. Actually this is one area FB must be congratulated for the accuracy they've managed with their algorithms! Unfortunately, the market at large doesn't see it that way. The advances in analytics have been exponential in a brief span of time in an unregulated market, that unpeople haven't been able to fathom it yet. 

A personalized recommendation is not seen as a smart salesperson suggesting just-the-right product, but rather like an intruder who has not only got into your house without permission, but has setup a canopy right in your living room to sell stuff by overhearing what you talk to your family!