Showing posts with label real world. Show all posts
Showing posts with label real world. Show all posts

Thursday, 24 November 2011

Maths and the Real World: Bayes' Theorem

Bayes' Theorem is one of the most practical theorems to apply to everyday life and if used correctly it can be an indispensable decision making tool. In a nutshell what the Bayes' Theorem does is measure the confidence that something is true. It takes the uncertainty before and after observing the modelled system and links the two.


We shall use an example to help explain what the Bayes' Theorem is and how it works. Let's consider the example that you have had a persistent headache for a week now and you're not certain what the cause it. But you do believe that it is caused either by stress (hypothesis A) or by having caffeine (hypothesis B).


So to test if stress is the key to the chronic headaches you have a day of relaxation whilst you've got a headache and have had coffee on the same day. By the end your headache has gone, so this can be considered as evidence. This should have some relation to how much more likely is A than B. But how strong is this evidence exactly? And how do we show which hypothesis it supports? Bayes' Theorem tells us that these answers lie in what is called the Bayes' Factor.


The Bayes' Factor is the question: "How much more likely would it be for this evidence to occur if A were true than if B were true?". This question must lead to one of three conclusions:


  1. The evidence would be more likely to occur if A were true than if B were true. This means that the evidence supports A rather than B.
  2. The evidence would be just as likely to occur if A or B were true. This means that the evidence has no real weight to whether A or B is more likely to be correct. That means that the "evidence" is not actually evidence at all.
  3. The evidence would be more likely to occur if B were true than if A were true. This means that the evidence supports B rather than A.
In our example of chronic headaches the Bayes' factor becomes: "How much more likely would it be for the headache to disappear after having a day of relaxation if stress were the cause compared to if caffeine was the cause?".


Now we do do not know the precise answer to this, but we can give a rough approximation to it. A day of relaxation could have some effect at stopping a headache if caffeine was the cause, but it shouldn't have too much of an effect, no more than a 1 in 5 chance for a persistent headache. On the other hand if the factor of stress is dealt with and the headache disappears, that is a pretty good indication that stress is the key cause, so the chances that stress is the main cause is about 1 in 2.


How likely the headache would have stopped given A is 1/2. How likely the headache would have stopped given B is 1/5. Hence the Bayes' factor, how likely would it be for the headache to stop given A compared to how likely it was to stop given B, is at least (1/2) / (1/5) = 2.5.


This means that given our evidence we should now believe that A is at least 2.5 times more likely compared to B, this is compared to what we used to think. The Bayes' factor tells us how much more our new evidence should cause us to believe the likelihood of one of our hypotheses.


Now let's suppose that you already suspected that stress was twice as likely to be the main cause (as you had recently taken on more responsibility causing more stress). Now we know that the Bayes' Factor is at that A is at least 2.5 times more likely than B, but as we already believe A to be twice as likely as B we know that A is now at least 5 times more likely than B.


Bayes' Theorem is useful because it tells us the correct sort of question to ask ourselves and then it uses maths and statistics to provide us with a suitable answer and easy to understand conclusion. Bayes' Theorem can also provide an answer when looking at just one variable, you simply change B to to A' (not A).


However as humans we tend to have a very poor ability at distinguishing what is or isn't evidence. If we're expecting a particular result we're far more likely to apply whatever evidence we've got and assess it with bias.


So the important part of interpreting the evidence we now have is to always use the question "How much more likely would it be for this evidence to occur if A were true than if B were true?". In the next post I do I will be writing about the maths behind Bayes' theorem.

Wednesday, 16 November 2011

Maths and the Real World: Linear Programming

Linear Programming may be bread and butter to you or it may be an entirely new concept. But it is one of the most applicable pieces of maths that is used in every day life by business and companies alike, this of course is minimising costs and maximising profits.


I will propose a problem to you, you are a company that sells two types of fruit drinks that consists of fruit juice and sugar syrup. Juice A consists of 0.3 litres of fruit juice and 0.5 litres of syrup and Juice B consists of 0.6 litres of juice and 0.4 litres of syrup. You have 30,000 litres of juice and 40,000 litres of syrup already in your stock. The profit for Juice A is 20p and the profit for Juice B is 30p. Given this scenario, you wish to maximise your profit.


How would you go about doing this? Well let's begin by putting the information we have in a table and go from there.



Fruit Juice (in litres)
Syrup (in litres)
Profit (in pence)
A
0.3
0.5
20
B
0.6
0.4
30
Total
20,000
30,000



Now, from this information we need to construct the constraints of the problem into mathematical terms. What inequality will represent the amount of fruit juice that is allowed to be used? Well it must be less than or equal to 30,000 that is clear, it also depends on how much of it is used by Juice A and Juice B, so if 0.3 of A is used each time Juice A is created, and 0.6 of B is used when Juice B is created. This then means that 0.3A+0.6B ≤ 30,000. Using the same rules we must concur that 0.5A+0.4B ≤ 40,000. Also we want to maximise the amount of profit that we make, this means that P = 20A+30B. But there are other less obvious constraints that we must consider. We can not use a negative amount of juice or syrup so A ≥ 0 and B ≥ 0.

To get an idea of what sort of values we can have we plot these inequalities onto a graph which will give us an idea of what values of A and B are actually possible to obtain.

The blue shaded region is the answers that are within
 the constraints of our inequalities. This is called the
region of feasibility.
So we have the region that the answers must be within, now we want to go about maximising the profit which has an equation of, P = 20A+30B. This will be the last point that the line P = 20A+30B touches on the region of feasibility, this means that what P actually equals is arbitrary as we only need to gradient of that line and it will then be moved until it touches the last point it possible can on the region of feasibility. So we will choose a number that is convenient to plot for us, I'll be using P = 600.

The line begins to gain opacity as it moves closer to the
further point on the region of feasibility. Point 'A' is the
 maximum point within the reason of feasibility, therefore
this is the maximum value.
We could try to read this point of the graph but it would far more accurate to solve this using where the point is met by the two equations and solve simultaneously. So we are solving the simultaneous equations of 0.3A+0.6B = 30,000 and 0.5A+0.4B = 40,000.

This then in the context means that to optimise the profit within our constraints we should make 200,000/3 litres of Juice A and 50,000/3 of Juice B. This then equates to about £6333, which is the maximum profit we can achieve from the circumstances we have been given.

This is just an example of how to use linear programming to optimise finances, but it is easily transferable to almost any situation. The only thing you may need to watch out for is if A and B are number of items that need to be sold, they must be whole numbers (obviously) so you may need to round and then check that this will still lie in the region of feasibility.

Again, I hope you find this interesting and in fact very applicable to real life. If you have any questions on anything I have done, how it works or even how I create my images, please comment and I will reply.

Monday, 28 March 2011

Maths and the Real World

"Go deep down into anything and you will find mathematics" - Dean Schlicter


Often a lot of students who first begin algebra or quadratic equations fail to see how this has any implications on the real world. The aim of secondary school seems less to inform about the uses and necessities of mathematics and more on driving the knowledge into your head.


But maths in all its bewildering complexity and brute simplicity is all around us whether we choose to acknowledge it or not. Science is all compromised from formulas and predictions, all of which is algebra. Some of the greatest and most eloquent works in science are equations.


The basis of quantum mechanics, the Schrödinger Equation,  is a relatively complex form of algebra involving constants and variables to plot possible points at which a particle can be at. Almost the entirety of mechanics relies on inputting numbers to calculate forces and other movements. And engineering is virtually completely maths. The importance of algebra is clear for all to know.
Obviously this is incredibly advanced and I do not want
you to focus too much on the content and meaning of the
equation, more on the algebra behind it and how this can
be used, regardless of the difficulty level
.
However, my love for maths does not come from number crunching. Altering one number into another via some function, is of course the most obvious way in which maths is related to everything, but it is not the beautiful way.


Bertrand Russell famously said that: "Mathematics, rightly viewed, possesses not only truth, but supreme beauty". And the majesty that maths holds can be represented by the elegance of space. Space is perhaps one of the only ways to think of infinity, the size of which we can currently see is 46 billion years, or around 45,000,000,000,000,000,000,000,000 kilometres in radius. Estimates of planet sizes, dark matter and even black holes; all are only possible with maths and how it is implied to the real world and the universe.

Nature also likes to throw in a little bit of maths occasionally, times of the year when animals hibernate and mate are often prime years as they're harder to predict because of a lack of a pattern. The fibonacci spiral is seen in many natural phenomena, as well as perfect shapes occurring regularly.
The fibonacci spiral is seen in many shells, the stretch that
maths has really has no limit
.

I will also do a future post discussing the economy, how it works and how maths is applied to that.