Saturday 17 April 2010

Predicting the length of a lifetime.

For the last couple of days airspace over the UK, Scandinavia and much of Europe has been locked down as a result of volcanic ash. This stuff is lethal to jet engines and has left many people stranded from home while they wait for it to clear. One such person would be my good friend Dave who is currently stuck in Vancouver.

While he has been moping around in a foreign airport lamenting the vast swathe of ocean between him and his girlfriend I've been doing some maths. The fruit of this endeavour? An application which can predict, with varying levels of confidence, the time left for an object/disaster/entity to exist. A blanket of ash in the atmosphere for example.

You can grab the program here:
(It is named in honour of Dave.)

So, how does it work?

Probability! What we are doing is calculating the probability of a random moment in time being in a particular section of something's life. This turns out to be very easy. There is a 50% chance that our moment is in the first half (first 50%) of the lifetime, a 25% chance of it being in the last quarter (last 25%) of the lifetime and a 60% chance of it being in the middle 3 fifths (middle 60%) of the lifetime. You can probably spot what's going on here; there will always be a n% chance that a random moment in time between object A's beginning and end will be within a n% section of A's life.

We are interested in the middle section of this objects life. From this we can deduce with n% certainty the minimum and maximum percentages of lifetime that it has left. I'm going to start using the volcanic ash as an example now to try and make things clearer.

At the moment the ash cloud has been disrupting things for 2 days. I want to know, with 60% certainty, how much longer this will last. Now, I don't know exactly how far through the ash clouds life time I am right now. Only that I am somewhere between its beginning and its end. but I can say that it is 60% probable that I am within the middle 60% of its life (between the parentheses { }).

[--20%--{------60%------}--20%--]

So, the ash cloud will have expended somewhere between 20% and 80% of its life already. meaning that it has somewhere between 80% and 20% of its life left to 'live'. Now I know that the ash cloud has been around for about 2 days. If that is 20% of its life then its total life will be:

5 * 2 days

(5 = 100% / 20% )

which is equal to 10 days.

If 2 days is 80% of its life then its total life will be:

2 days + (2 days / 4)

(4 = 80% / 20%)

Which is equal to 2.5 days.

Now that we know the minimum and maximum values for the ash clouds total life we are one small step away from finding out how much time is left; take 2 days away from minimum and maximum values:

10 - 2 = 8
2.5 - 2 = 0.5

These results tell us, with 60% confidence, that there are between half a day and 8 days left until the ash cloud clears and Dave can be reunited with the love of his life.

Some of you will be thinking that 0.5 to 8 days is very vague, especially if we are only 60% confident that this range is correct and you would be right! The sacrifice we make for having any real confidence at all is the precision of our results. This becomes even more apparent when we try increasing our confidence level. Bumping it up to 80% gives minimum and maximum remaining life values of 0.2222 and 18 days respectively. Also, this doesn't really work if you already have a good idea of how long something will be around for because you wont really be picking a random point in time. But wait! Before you dismiss this as being useless (OK, I admit it is pretty useless but keep reading anyway) understand that, as long as you include your confidence level, any statements you make using this method are guaranteed to be 100% true. Why shouldn't they be? This is maths, the universal language of truth, not magic.

Congratulations on making it to the end of my post. As a reward have the source code to my little program, it is written in vb.net, you can grab the free express edition from Microsoft here. I used a slightly less round-about way of doing the calculations but they are still essentially the same as the ones in this post.

feel free to comment, criticize and question this post. I'll do my best to reply to everything (within reason).

David.