Thursday, December 16, 2010

Things are not as they appear

This post is probably going to be more or less random as I have no idea what I am going to think of in the next few minutes. The general idea I would like to explore is some of the basic principles that hide beneath some of our day to day activities and thought processes.

1) Murphy's Law:
In its crudest formulation it states that "Anything that can go wrong, will go wrong". I find this to be one of the widely quoted adages and have come across this in the context of many things. This is inherently a pessimistic approach at heart but I have known many who have interpreted this positively to try and counter as many problems as they could think of. Being an optimist (most of the time :-)) here is how I look at it from an analytical point of view.
This "law" in itself is just an adage with no mathematical or theoretical backdrop. This means that there is a finite probability that this may not be valid and may in fact be wrong. Thus as stated by this law itself, if it can go wrong, it will. This is a contradiction in itself and leads me to believe that this in fact does not hold good.

2) Short and sweet:
I think that the growing popularity of T20 in cricket, Youtube and Facebook etc are all linked to the same phenomena namely dwindling attention spans. As modern life gets more and more complicated, we are being bombarded with information every instant and our brains are not capable of handling the volume. In fact, our brains do not even process most of the information that our senses normally send it. It acts on what it thinks is important and saves the rest to our subconscious mind. This is one of the reasons why people under hypnosis can recall vivid details about an encounter while their conscious minds cannot.
I think that the way the brain tries to handle this information overload is by time slicing (a scheduling method) where it allots a small time frame for processing an event before moving on to the next.
The result of this is that we are becoming incapable of sustained thought which is essential for creative thinking. This is going to become a challenge in the future and I already see it happening on the job. The focus in any training be it for toddlers or engineers seems to be in keeping them engaged which is a good thing but I dont think it gets at the root cause.

3) Codes of Conduct:
Shall I be kind or turn a blind eye? A question that springs to mind every time I see a beggar or some shady character peddling something. Actually, the question is bigger than that. Most of us are faced with situations where we have to decide whether we should take a chance and help someone out and risk being taken for a ride. The response is usually dependent on non quantitative data like how kind (gullible) the person is or some other emotional response. Interestingly, this social interaction was modeled using a computer game a long time ago and many different strategies came to the table.
The biggest surprise was that out of all the models the most successful strategy that emerged was the simplest and something that we have always heard of: "Tit for tat".
This strategy comprises of a few simple rules:
  1. Make your first move nice and co operate
  2. Be in a position where it is possible to retaliate
  3. Forgive past transgressions
If you think about it, these simple rules have been at the heart of even the Cold War ( Mutually Assured destruction). In essence, the best strategy is to help people but only if you have the capacity to retaliate if needed. Dr.Richard Dawkins has some wonderful thoughts on this in his book "The Selfish Gene". Simple rules for a complex world, just the way I like it :)

Thoughts welcome!

Sunday, October 31, 2010

Naughts and Crosses

Owing to a debate at home regarding the age old game of Naughts and Crosses I decided to do a statistical analysis of the game itself. My initial premise was that the person making the first move is at an advantage and the analysis seems to validate this. Admittedly, I just analyzed the first six moves as most games are decided by that time (truth is I got lazy after 6 rounds of iteration :-) )
Maths Alert:

If you are easily nauseated by mathematical models and concepts or are below 100 years of age then please stop reading here.

Since you have not stopped reading I sincerely pity you but anyways here are the mundane details

1) The first question to be answered of course is how many moves are possible in the game itself. Simple math tells us that the number of ways two symbols (X and O) can be arranged in 9 positions is given by 2^9 which is 512. As usual, simple maths is not sufficient as we have to take into account the rules of the game which says that the symbols "X" and "O" must be placed alternately thus invalidating many of the combinations calculated by the mentioned method. I looked at it from a different perspective and realized that the game would involve 5 "X"s and 4 "O" upon conclusion. Thus the number of ways in which 5 "X"s can be placed in 9 places is 9C5. This is 9!/(5!*4!) = 126. The remaining 4 positions can be filled by 4 "O"s in 1 way. Thus the total number of combinations possible is 126

2) Looking at the layout, it becomes apparent that there are 8 possible routes that spell victory (Figure 1). Thus the possibility that a "X" or "O" is placed on a path that may lead to victory is 8/126 = 0.06


Figure 1

3) Now the fun part :-).
For each possible moves there is a possibility that the placed symbol may lie on a number of "success" paths. Looking at the best case and worst case scenarios in each case we come up with the following:
For the first move by Mr "X" he can opt to put an "X" in positions that put the symbol on a path that is common to 4, 3 or 2 success paths. Taking the best case and worst case scenarios which look like Figure 2 we end up with probabilities of 0.24 (4*0.06) or 0.12 (2*0.06)








Figure 2

4) Now Mr "O" also has best case and worst case scenarios depending on what Mr "X" has done and we end up with the following scenarios (Figure 3)







Figure 3
The corresponding best case and worst case probabilities are therefore 0.18 and 0.06

5) Repeating this iteratively for 4 more moves we end up with the following scenarios (Figure 4)






Figure 4

The following table presents the Best Case and Worst case probabilities for each move and then sums up the probabilities for Mr "X" and Mr "O". The average overall probability considering equal weightages for Best case and Worst case scenarios is then calculated.

















6) My conclusions
a) The person beginning first has a 28.5% chance of winning
b) The person going second has a 24.5% chance of winning
c) Overall there seems to a 47% chance of a draw

NOTES: Please find below some of the answers to the questions that this blog article may prompt you to ask me.

1) Yes, I have a life
2) I do have a job
3) There was no point in doing this
4) You shouldnt bet money on this analysis
5) Oh Yeah?
6) Same to you.

:-)

Cheers
Sam

Sunday, October 3, 2010

Beware of Logic

I have recently realized that many of the morons I have encountered over the years are not to be blamed for their condition. Under normal circumstances, it seems that everyone has a preference to think logically (or at least try). So why is that, that an overwhelming majority still believe in God, Astrology, Birthstones and the like? The root cause of this seemingly contradictory behavior lies in a flawed sense of logic. Though most people would like to think logically, the very definition of logic seems to take on different colors for different people and as is obvious, most have no idea what logic really implies. I have tried to analyze some of the common fallacies that I have come across and I am pretty sure most of you would have encountered the same.

1) Burden of Proof – This tops the chart by a long shot and I have come across this in the context of practically every supernatural phenomenon you can think of ranging from God to gemstones. The premise is simple. The person holding the viewpoint is convinced that because I am not capable of proving that the thing being discussed does not exist, hence it must exist. To them this seems perfectly logical. Unfortunately, logic dictates that the “Burden of Proof” lies with the one holding the belief and thus unless someone can prove that God exists, logically it does not. There is no way to prove that something does not exist.

Invoking reductio ad absurdum, let’s say I say that I believe that there exists a three headed lion that can breathe under water and talk like a human. Can anyone prove to me that it does not exist and hence I conclude that it must exist? Seems silly now doesn’t it?

2) Appeal to tradition/popularity – This is the lazy mans definition of logic. The central premise of this is that if something has been going on for generations or is endorsed by a majority of the people then that is a necessary and sufficient cause to prove its validity. The fallacy here is that the age of a belief or the number of people following it has no correlation to its validity. Traditionally, we had believed in Earth being the center of the solar system, the earth being flat, speeds beyond 25 mph are lethal, diseases being caused by witches and demons and now we all know how these went. There is perhaps a link to this kind of logical fallacy and the natural tendency of people to shy away from anything new.

3) “Post hoc, ergo propter hoc” and Relativist Fallacy - Post hoc, ergo propter hoc literally means ”After this, therefore because of this” and this seems to be the root cause of many superstitions. This logical fallacy is ascribing cause and effect simply on the basis of when events occurred. Someone may have bought a lucky charm and after a month something happened and hence the conclusion is reached that the charm must have something to do with it. This is similar to someone jumping in India and an earthquake in California that happens a month later being described as cause and effect. Relativist fallacy is typical escapism. The idea here is that the truth is subjective. This typically comes up when a person has to admit that he/she is logically incorrect but then goes on to say that he/she has personally experienced something or “believes” that something is correct. This stems from an individual’s reluctance to give up long held beliefs and they find it easier to find escapism by making truth subjective and they conclude that they somehow fall outside the purview of what is logical.

I find this to be rather interesting, because it shows that most people would like to justify their beliefs and that is a good sign. The only problem being then is that what they deem as logic is unfortunately not so. A classic example is perhaps the belief in Astrology. Ancient civilizations found out that they could observe the motion of stars across the sky to predict seasons and that was invaluable to them for deciding when to plant crops and when to harvest etc. Thus to them it was also “logical” to assume that if the stars could influence the seasons then they were also bound to have some effect on human lives and destiny. Thus the belief in astrology started.

The fallacy here is obvious. The seasonal changes are actually caused by the rotation/revolution around the sun and the position of the stars have no role to play. Let me assure you that meteorologists can predict the monsoons accurately about a week in advance and they are not star gazing. So, we have stopped relying on the stars for predicting seasons but we still hold on to the secondary belief of them influencing us? Hilarious to say the least. Maybe logic should be made a compulsory subject in schools. The least we owe to the future generations is to give them the right to decide for themselves what is fact and what is fallacy.

Monday, August 2, 2010

Quantum Model of Software Development

Of late I have been trying to co-relate some of the principles of Quantum Mechanics with those of Software Development. Though many models exist for developing software (SDLC, Agile, Waterfall etc) we all know that none of them are "perfect". Here is what I think is causing this indeterminacy.

Quantum Nature of Software
1) Quantization :
The number of bugs in a given piece of code is quantized. That is the number of bugs will always be found to be integers. There is 0 probability for the occurrence of 1/2 a bug.

2) Sams Uncertainty Principle (If Heisenberg can get his name in so can I :-) ):
It is not possible to predict the time line and the quality of a product simultaneously.
Hence any estimation that assures on time delivery will have quality issues and better quality software will induce a time penalty.
The equation relating these can be expressed as follows:
Definitions:
Quality(Q): Bugs per 1000 Lines of code (LOC)
Time (T): In any units (preferably in person days)
FP(CP): Function points (Coding language): This is the number that represents the average
amount of time needed to code 1000 lines in a given programming language.
Thus,
Q*T = 4.FP(CL) where 4 represents standard DIR (Defect injection ratio)

In other words, 0 defect implies infinite time!

3) Bug Tunelling effect:
There exists a finite non zero probability of a code issue in one module causing an inexplicable bug in another even if the interfaces are seamless.


Begin Random Rant

Sorry to digress but whats the deal with all these quality models CMM, Six Sigma etc ?
These models are like teenagers and sex
1) Everyone is talking about it.
2) Everyone thinks everyone else is doing it
3) Almost no one is really doing it.

End Random Rant

Enjoy. Comments welcome! :-)

Monday, July 26, 2010

Newton - A "Relative" of Einstein

While answering the query of a school kid recently pertaining to the Law of gravitation, I started thinking a bit more about Newtons laws of motion. One thing led to another and a thought experiment now seems to suggest to me that Newton may have unknowingly laid down the foundation for the Special Theory of Relativy in some sense. This is a very crude comparison in some senses but nevertheless it seems interesting (well to me atleast :-))
Here is what I have come up with.
We all know that Newtons law says that F=ma i.e The force is equal to the product of the mass and the acceleration of a body. Viewed in terms of an objects relation to the force of gravity, this also leads to the definition of "Weight" which is w = mg and here g being the acceleration due to gravity.
In essense thus, the acceleration of a body can be thought of as contributing to its weight. Acceleration on the other hand implies an addition of energy to the system. Thus, adding energy to a body by accelerating it in some sense increases the weight of the body and hence necessitates addition of higher amounts of energy to maintain the acceleration. This is also refelected by the Inertia of Motion exhibited by a body.
Looking at this from a different viewpoint, it appears that the addition of energy to a system and trying to increase its acceleration will in some respect manifest as an increased weight of the system. (E=mc2.. wink :-) )
So the next logical qusestion would be what the limiting condition is i.e how much energy can be added to the system so that its weight (mass) becomes so large that no amount of energy can accelerate it further. What Einstein found is this limit and gave us the exact relation between mass and energy.

Saturday, July 10, 2010

Chaos Theory - One dimension Logistic map (Excel)

Chaos Theory - Pretty interesting stuff and somehow very profound. It is yet another of those mathematical models which goes against the very grain of mathematics itself (well the 19th century view of mathematics to be precise).
Mathematics has always been regarded as the holiest of the scientific subjects owing to its inherent properties of being testable, predictable and deterministic. It was natural to assume that if something could be described mathematically then there would remain no surprises and it made perfect sense. Then maths got complicated!
1) Probability Theory - Here, after rigorous mathematical somersaults all you would end up with is the probability of the occurrence of an event not a certainty. Though it can be argued that it does limit the range of possible outcomes and hence is deterministic in some sense.
2) Quantum Theory - My favorite ! The uncertainty principle virtually guarantees that no matter what instrument is used it is impossible to determine the position and momentum simultaneously. Then of course there is the "Measurement problem" the mention of which will send shivers down any Physicists spine. To put it bluntly, if you set up an experiment to measure something like a Photon as a particle then you will detect it as a particle. An experiment set up to detect it as a wave will detect it as a wave. Funny isnt it? :-)
Well thats how the collapsible wave function of gauge boson behaves..deal with it. So essentially here mathematics has determined that you cannot determine.
3) Chaos Theory - Perhaps the most counter intuitive of all theories. Seemingly innocuous linear equations display behavior that is very surprising. I was trying to model the one dimension logistic map equation which is incidentally one of the good example of deterministic chaos. This equation is also very intriguing because this has wide uses in fields as diverse as ecology! ( Population Growth model) . In essence this equation has a very high dependency on the initial conditions and the behavior changes drastically with changes in initial conditions.
The linked spreadsheet has the equation embedded and plots a graph of 200 points based on the input value of the scaling parameter k ( Sheet: Input, Cell: A8). I have put down the ranges of k that induces different behavior from the same equation. Have fun trying it out for yourselves.
Also, Wolframs Mathematica has done a better job of modeling this equation so if you want to try out a widget which allows a greater control of parameters as well as a mean square minimized error then please refer the Wolfram Demonstration Project

And to think, our universe Probably started from Chaotic conditions on a scale that necessitates the existence of Quantum effects.

If God exists he must be ROFLing now.. couldnt have made it more puzzling. :-)

Saturday, June 26, 2010

FIFA 2010 - Mathematical modeling

After having sleep deprived myself for more than two weeks, I decided to try and take out some suspense from this World Cup :-)
The following is my analysis of the next round and predicted winners, the metric used was the normalized linear combination of the goals scored for and against a team. Lets see how things turn out.

Friday, June 4, 2010

Are we getting smarter?

I guess everyone would have noticed that kids nowadays on an average seem much more intelligent. This might not appear very surprising but I got thinking about this phenomena a bit more and it seems that there might be more then what meets the eye.
It is a well known fact that the rate of evolution in humans is 10 to 100 times the average long term rate. You might be surprised to know that 10,000 years ago no human had blue eyes but now the gene OCA2 has emerged and so we do. The mundane (and perhaps logical) explanation for this phenomenon is that the population explosion that mankind has experienced provided for a lot opportunities for mutations to creep in. That plus the added challenges of post industrial life may have contributed to this accelerated rate of evolution.

From this viewpoint it seems natural to assume that generation next will be better equipped to deal with the challenges that we now face and indeed we do see this happening in the animal kingdom as well. However, can this phenomena alone explain this growth in intellect? Rats, ants, rabbits, mosquitoes even, all propagate at rates much higher than humans but I am yet to see a rat that can understand calculus (not that I have tried teaching it to one :-)). Cockroaches have a few million years of lead on us but they havent done much beyond survival yet. There seems to something else driving our evolution that cannot be explained away by physical processes.

Here is my hypothesis:

Before I present it I think I need to point out a surprising form of memory called "Flatworm memory". In an experiment conducted in in 1953, Dr James McConell made a few worms get through a maze and then he killed them and fed them to a second batch of worms. These made it through the maze faster than all the control groups. The same experiment has been repeated with goldfish, rats and canaries with similar results. An injection of RNA seems to induce the same result. So, this cannibalistic experiment seems to point out that somehow memory is being absorbed and hence knowledge is being passed on by the act of digestion.

Maybe humans also transmit information in some way to their surroundings. If we assume that mankind as a whole is connected to a hypothetical meta physical universe that holds the consciousness of the species itself then things start getting interesting. Knowledge acquired by prior generations get accumulated in this "cloud" and any new sentient being that can tap into it instantly inherits this vast expanse of knowledge. This can explain why people are getting smarter. Yes, we have the internet and news travels fast but that is information. Knowledge is a different ball game. It is the ability to interpret information and God knows that the internet does anything but help that cause. Looking at major religions we can draw similarities between many stories and all seem to have a similar theme. Is this coincidence because during ancient times it was not possible for stories to circle the globe rapidly or is it something else? Here for example is a list of the similarities between Jesus and Krishna.
This is not mere speculation, the Global Consciousness Project has been running for over 10 years gathering data and analyzing correlations between random numbers and for many major events they have noticed a significant deviation. This is being speculated to be the result of a global consciousness that can actually have physical and measurable effects. Surprised?

Maybe there is more than just our appearance and genetics that makes us HUMAN. Certainly a tantalizing prospect.

Tuesday, May 18, 2010

Unprovoked Thoughts

Unprovoked Thoughts


The rising sun, desperate heat
The thought of sweet rain.
Randomness of pure thought
A smile, a laugh and pain.

Memories, dreams, hopes
Fleeting glimpses of a time past;
Fear, regret, plans and tears
How long will it all last?

Some things frozen in time:
Small joys, bigger smiles
Friends standing forever
Roads walked alone for miles.

Dreams that turned to life
Unrealized reality that taints.
Ah! Randomness of thought
What a canvas it paints!

Friday, April 16, 2010

Antithesis of Anectdotal Evidence

I dedicate this article to the old and senseless sayings that have been thrown my way since I remember.

To start off with, I got this recently from someone saying that repetition is always boring and change is always welcome. Hmm.... and I think to myself that over the last two years Katrina's skirt has remained at the same length and I havent heard so much as a peep from anyone??

Anyways, I had this idea of trying to have a conversation with myself using as many idioms as I could think of and each conveying the opposite of the other. So here is how it went.. the theme being me trying to convince myself to open a Demat account

Me: You should make hay while the sun shines
Myself: But shouldn't I look before I leap
Me: All I am saying is you should start now, Rome was not built in a day
Myself: But shouldn't I do as the Romans do when only in Rome
Me: No, doesn't matter. All roads lead to Rome anyway and Time and Tide wait for none
Myself: But I think its better to be safe than sorry
Me: Action speaks louder than words
Myself: But You know a fool and his money are quickly parted
Me: But A rolling stone gathers no moss.
Myself: All that glitters is not gold
Me: A stitch in time saves nine
Myself: Beggars can't be choosers
Me: A man's got to do what a man's got to do
IRENE: Wise men argue cases, fools decide them
???????????????.....

Not to mention a saying that has always had me confused. A watched ketttle never boils. What??

The specific of water is 4.186 joule/gram °C. So under standard temperature and pressure it is always possible to calculate the amount of heat needed to boil water and that can be equated to the time taken given a knowledge of the heat source. Till date I haven't come across an equation that factors in "watching" and its relation to the time taken but surprisingly I have heard this adage a lot.

Well, let me end it here with a quick note. You shouldn't believe everything you hear :-)

Thursday, January 28, 2010

SDLC - Bollywood style

Software Development Life Cycle.. as most would call it. However, typically some vendor organizations adhere to the more popular version.. (Sab Dhakkano ko Lagao Chunna)
:-)
Anyways, I was wondering that if a developer could relate each of the stages of SDLC to a Bollywood song then what would they be. Here is what I came up with based on my personal experiences

1) Requirement Gathering:
Choli kai pichay kya hai?Choli kai pichay? Ku Ku ku ku....

2)Design:
Na bole tum na mainay kuch kaha, kaha...

3) Implementation:
Sathi haat badhana. Ek ekala thak jayega, mil kar boj uthana.Sathi haath badhana..

4) Testing:
Yehhhhh Kya hua, kaisay hua, kyon hua. Woh choddo yeh na socho...

5) Deploy:
Raat ka nasha abhi, aankh sai gaya nahi...

6) Maintenance:
Hum hongay kamyiab, hum hongay kamiyab ek din, ek din..


Adieu!
Thoughts welcome