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.