Introduction To Probability - 1.5

June 16th, 2009 by reddavis

How would be go about calculating the probability of winning the lottery?

In total there are 7 balls that are drawn for the UK National Lottery: 6 normal balls a bonus ball. The seven balls are all drawn from the same batch of 49 balls.

To receive first place you need all 6 normal balls. To understand whats going on here we need to understand factorials.

Factorials

There are 3 people in a room: A, B, C. If we were to ask them to leave the room, what are all possible combinations in which they leave the room:

ABC


ACB


BAC


BCA


CAB


CBA

A way to calculate this is: N = 3×2x1

Now if there were 24 people, the number of combinations would be: N = 24×23x22… Now this equals a rather large number, which would make writing calculation a pain in the ass, so we shorthand them like so:

24!

This is a factorial.

Let’s say we now have 4 people in a room and ask them to leave just like we did before, but this time we only care about the first two people who leave. How many different combination can we have? We can work this out like so:

4×3 = 12

If we had 24 people and only cared about the first 5 we would calculate it by:

24×23x22×21x20

As you can see, it can get a bit boring having to type all of that into a calculator, so we can use this instead:

n! / (n-r)! where n = number of objects, r = amount we care about

From this we can work out that:

C = 4! / (4-2)!


C = 24 / 2


12 Different combinations

Back to the lottery…

You may noticed that the method I was just talking about care about order but in the lottery it doesn’t matter if the number 2 comes first or third (disregarding the bonus ball as we have no care in it to win). To disregard order we can calculate the number of ways 6 numbers can arranged:

6! = 720

We take the total number of combinations for 6 balls and divide it by this number:

49×48x47×46x45×44 / 720 = 13,983,816 combinations

This means that the probability of us winning first price is 1/13,983,816

This looks messy again, so lets combine this with what we already know:

Number of Combinations - Order Matters

S = n! / (n-r)!

Number of Combinations - No Order

T = S / r!

And this is turned into:

nCr = n! / (n-r)! x r!

Next time we’ll calculate probability of winning other place prizes

Universities: A Type Of Corporation?

June 10th, 2009 by reddavis

As my girlfriend is in the middle of an exam I offered to do the application for her uni accommodation (as it opens at 10:30).

Annoyingly I wasn’t very surprised by the craptastic user experience I had.

So, after going through problems with registering next I had to apply for accommodation; so I click applications (I think thats what it said, I can’t find out as the service has now been shutdown due to “problems”). A page comes up showing me that I have 0 applications, nothing new there. Now how the hell do I submit a new application? Theres no sub-menu below the menu that I just clicked, theres no sub-menu in the main window…Oh, there it is! Right in the bottom left, now why would you put it there? It’s like putting Diggs “Submit new” button in the footer!!

Here’s a picture (I’ve cut the side bar off)

picture-4

They couldn’t even bother to make the background on the help buttons the same colour as the background their sitting on:

picture-1

After finding my way around I managed to get the the page where I had to accept the terms and conditions. I’m noticing a trend here…They like to put important button in the bottom left! If you look at the picture below, how far do I need to move my mouse to just submit this one fielded form!? Not only that but I’m seeing some terrible logic going on here…(I think this deserves its own paragraph)

It asks you to confirm you have read and understood the T’s and C’s. Next to the writing is a tick box, nothing new here as its normal practice, but then in the bottom left their are two buttons, and “Yes” and a “No”. What!? Am I ticking the box to confirm I have read it and then using the buttons below to confirm I understand it?? What if I don’t tick the box but click yes?

picture-3

Not only that, but through the whole process I received lots of 503 errors. Now, I can forgive if all of a sudden they received a ton of traffic and weren’t expecting it, but they must have set this date months in advance; not only that, but they go through this same process every bloody year! Buy or hire another 1/2/3 servers just for a day, take EC2 or Mosso for a spin. Your not exactly selling the last 1000 tickets for Leeds and Reading festivals.

I had also sent an email around 10:30 this morning asking whether there were problems their end, I also sent another one telling that the app had told me to contact them. I have yet to hear back for either email. To put them to shame, I emailed Pragmatic Programmers this morning to see whether they could transfer a book I got for my bday to my account. Within an hour it was done!

I got that awesome service for buying a book (well I didn’t actually buy it, which makes the whole service even better), yet we’re paying the university thousands of pounds and we still had to go through this poo bath! Universities can sometimes remind me of those big corporations who know that people need (or think they need) their product so feel that they don’t have to care about their users.

Line Type By Good Service

June 7th, 2009 by reddavis

I’ve put some data together to see if theres a correlation between line type and delays.

I used the info on Wikipedia to get what type each line is

line-type-by-good-service2

Line Status By Amount

June 6th, 2009 by reddavis

Jubilee isn’t so great at only being in “Good service” 52% of the time and Hammer Smith & City is only “Good service” 60% of the time.

Some More London Tube Graphs…

June 6th, 2009 by reddavis

I’ve created a bunch of graphs to see if theres any relation between time and tube status. Most of the graphs show theres a decline in “Good service” around rush hour times.

Some interesting points:

  • A large amount of Bakerloo delays happen in the morning rush hour.
  • Circle line suffers from a lot of severe delays around both rush hours.
  • Metropolitan line has a lot of problems during morning rush hour, but it alright evening rush hour.
  • Picadilly line is very reliable compared to other.
  • Victoria line has had a spread of planned closures, I believe their doing work on it, but haven’t been on that line for a long time.

Tube Status Stats

June 4th, 2009 by reddavis

The last couple of weeks I’ve been collecting data on:

Tube - Status - Time - Weather - Temperature

I am playing with different ways to see if I can write a program to predict the status of a tube.

I thought I’d post a couple of graphs to show the different statuses of the tubes.

Introduction To Probability - 1.4

June 3rd, 2009 by reddavis

So far we have been talking about a distribution function in a finite sample space, but what if the sample space is infinite? As long as the sample space is countably infinite then…

As an example let’s say we are going to keep tossing a coin until we get a head. There for our sample space is…

OHM = {1,2,3,4…}

The possibility of getting a head first time is 1/2, second time is 1/4 and third time 1/8 and so forth. We can represent this as…

m(n) = 1/2n where n = 1,2,3,4…

We know (from a previous rule) that the sum probability of all items in a sample space must = 1. A geometric series proves this

r + r2 + r3 = r/1-r

So to put this to use. Let’s say we want to know the probability of a head turning up after a even throw. Our event E would look like:

E = {2,4,6,8…}

E = 1/4 + 1/16 + 1/64 + …

E = (1/4) / 1 - (1/4) = 1/3

Therefore, the probability of getting a head after a even throw is 1/3 and after a odd throw 2/3

Introduction To Probability - 1.3

May 26th, 2009 by reddavis

We can use symbols to help describe events. This is especially useful when we are trying to describe a complicated event in English. By using these symbols we can break them down into simpler event using these constructors.



A ⋃ B = A or B

A ⋂ B = A and B

A - B = A and NOT B

A ⊂ B = Every element of A is a subset of B

à = Not A



Example

A = It will snow tomorrow and it will rain the day after

B = It will snow tomorrow

C = It will rain two days from now

D = It will snow tomorrow or it will rain the next two days



D = B ⋃ C


~B = It will not snow tomorrow



Or lets say that our event (E) = “it will snow tomorrow but will not rain the next day”

E = B - C

Introduction To Probability - 1.2

May 19th, 2009 by reddavis

Hey. This post is going to be about probability distribution on problem with a finite sample space. In other words: Discrete probability distribution.

By saying the sample space is finite means that, for example, we have a die, we know that the different outcomes go from 1 to 6. The math lingo for this is Finite


Lingo

Sample Space: A sample space is a set of all the possible outcomes. It us usually assigned to the Ohm symbol

Outcome: Elements of a sample space - usually assigned to a lower case letter

Event: A subset of a sample space i.e. sample_space = {1,2,3} event = {2,3} - usually assigned to a capital letter


OK, so lets go back the good old dice example and assign these new names…


OHM = {1,2,3,4,5,6}


i = 1..6


E = {2,4,6}


So, OHM is the sample space, i is the outcome (elements of our sample space) and E is our event

Event can be described, so this event can be described as the outcome being even.

Therefore we can give each outcome a probability of 1/6 and the probability of our event as…



P(E) = m(2) + m(4) + m(6) = 1/6 + 1/6 + 1/6 = 1/2



Distribution functions are the assignment of probability. They have to follow 2 rules:

  1. Each probability must be greater than 0 — m(w) > 0 for all w E OHM –
  2. Sum of all the probabilities must equal 1

If we go back to our dice example. The die has 6 sides, each side has a probability of 1/6, therefore 6 * 1/6 = 1

A coin example

We are going to toss the coin twice. Now, we have several ways we can display the sample space…

  1. Record the toss in the order it occured - OHM = {HH, TH, HT, TT}
  2. Record number of header occured - OHM = {0,1,2}
  3. Have no regard for the order - OHM = {HH, HT, TT}

For this example we’ll use the first one.

Therefore…



m(HH) = m(HT) = m(TH) = m(TT) = 1/4



Following the rules? Check! The probability of all outcomes is equal to 1

So lets start working out the probability of different events

An event of at least ONE head comes up



E = {HH,HT,TH}



The probability of this event is…



P(E) = m(HH) + m(HT) + m(TH) = 1/4 + 1/4 + 1/4 = 3/4



Another event could be…



E = {TH, TT}



An event where a tails comes up first



P(E) = m(HH) + m(HT) = 1/4 + 1/4 = 1/2



But what if our outcomes aren’t equal?

Imagine this scenario:

  • 3 people (A,B,C) are running a race
  • Only one person can win
  • A and B have the same change of winning
  • C has only half the chance of A or B



OHM = {A,B,C}



So, A = (2*C) and so does B = (2*C)



m(A) = m(B) = 2m(C)



If we remember our second rule, then…



m(A) + m(B) + m(C) = 1



So…



2m(C) + 2m(C) + m(C) = 1

5m(C) = 1



Sooooo….



m(A) = 2/5 m(B) = 2/5 m(C) = 1/5



Let try another event to smooth any rough edges



E = {A,C}

P(E) = m(A) + m(C) = 2/5 + 1/5 = 3/5

Introduction To Probability - 1.1

May 16th, 2009 by reddavis

The first book I’m going to be working from is from here.

The book is released under the FDL license.

Discrete Probability Distributions

1.1 - Simulation of Discrete Probabilities


Ok. So this chapter is about chance experiments with a set number of outcomes.


Lingo:

Chance experiment -  Examples would be: throwing a dice, pulling numbered balls out of a bag, flipping a coin etc…

Random Variable - Math expression for outcome to an experiment, will probably be displayed by me as an X

Distribution function - Used to diagram the probabilities to all of the possible outcomes. m(wj)

In the rolling of the dice experiment, the assignment of probabilities would look like this:

m(w1) + m(w2) +…+ m(w6) = 1


Probability is ranked between 0 and 1. 1 means certainty and 0 means impossible. There are 6 sides to a dice, since this is a fair dice the distribution of probability to all the probabilities is 1/6. So the possibility of the dice landing on a number from 1 to 6 is certain.

Also the possibility of a roll landing on a 4 or less is 2/3. The math looks like this…


P(X <= 4) = 4/6 = 2/3


Cool, nice and easy. The dice example gives each outcome the same probability. If we were to say that from past experiments the chance of me scoring a shot in basket from the half way line was 20%, therefore the change of me not scoring is 80%. In probability this would be 0.2 = I score, 0.8 = I miss. To check that this is correct we would have to perform the experiment as many times as possible to get an accurate idea of the true probability.

If we wanted to find the probability that we could roll a 6 in four rolls we would calculate


1 - (5/6)4 = 0.518


The 4 changes depending on how many throws. Now to work out the probability that I can roll at least two dice that land on a pair of sixes in 20 throws. Having two dice increases the number of combination’s we can have. The calculation looks like…


1 - (35/36)20 = 0.431


The rest of this section talks about random number generation and some other cool stuff.