Bayes Theorem can be derived from the condition probability principles stated in Part 1 below.
⁃ Pr(A|B) = Pr(A and B)/Pr(B), if Pr(B) not = 0
⁃ Pr(B|A) = Pr(A and B)/Pr(A), if Pr(A) not = 0
⁃ Pr(A and B) = Pr(A|B)*Pr(B) = Pr(B|A)*Pr(A)
⁃ Pr(A|B) = Pr(B|A)*Pr(A)/Pr(B)
**Note: Pr(A and B) can be visualised with a Venn Diagram. The set that is common to two or more sets overlap, the overlapping set is the and space. Example: of 10 people that like fruit, five people like apples and four people like oranges. Two people like apples and oranges. In this case, one person likes neither apples or oranges, three people like apples but not oranges and two people like oranges but not apples.
Example: Quality and Control with Software
Suppose you have 7 programmers at your company developing Java classes. The following table describes their track record with quality:
Programmer | Proportion of development | Probability of defective class (code)
1 .10 .03
2 .05 .03
3 .20 .02
4 .15 .02
5 .25 .01
6 .15 .02
7 .10 .03
Suppose that the Quality and Assurance department (Q&A) reviewed classes at random and found them to be defective. What is the probability that Programmer 1 developed this defective code?
If Programming is an event, then these are seven mutually exclusive events and their union is the entire sample space. A class was only developed by one and only one of the Programmers. (We’re assuming in this case that one programmer develops one class, which usually isn’t the case since programmers work in teams, however, this example may be extrapolated to groups, i.e. group 1 develops 10% of the code with a quality rate of 97%).
Let Bi (i = 1,2, … 7) be the event that the class was developed by programmer i, and let A be the event that the class is defective. Then, for example:
Pr(B1) = .10 and Pr(A|B1) = .03
In this case we have to calculate the reversed conditional probability. That is, we need to calculate the probability that the event, B1 (probability of Programmer 1 developing the code) is from the sample space A (probability of defective code). By applying Bayes’ Theorem the formula would be:
Pr (B1|A) = Pr(A|B1)*Pr(B1) / Pr(A|B1)*Pr(B1) + Pr(A|B2)*Pr(B2) + … + Pr(A|B7)*Pr(B7)
Pr(B1|A) = (.10)(.03) / (.10)(.03) + (.05)(.03) + (.20)(.02) + (.15)(.02) + (.25)(.01) + (.15)(.02) + (.10)(.03)
Pr(B1|A) = .15
So there is a 15% probability that the defective code is from Programmer 1.
I found these notes for finite math principles to be helpful. They have to do with combinations and permutations…there are plenty of resources on the web but you may find these useful. I personally learned this stuff a long time ago but it’s always helpful to brush up on the basics. Enjoy!
Combinations and Permutations
- If the order doesn’t matter it’s a combination.
- If the order does matter it’s a permutations.
Two types of Permutations (order does matter):
- Repetition is allowed:
- Formula: n^r
- Example: a lock with ten numbers to choose from (0, 1…9) numbers with three to choose from. This would equate to 10^3 = 1,000.
- Repetition is not allowed
- Formula: n! / (n – r)!
- Example: if you were to figure out how to order 16 pool balls, the result would be 16! = 20,922,789,888,000. If however you only wanted to calculate the number of permutations required to choose 3 out of the 16 pool balls then you would have 16! / (16-3)! = 16! / 13! = 3,360
Two types of Combinations (order doesn’t matter):
* Note there will always be more permutations than combinations
- Repetition is allowed:
- Formula: (n + r -1)! / r!(n-1)!
- Example: choose three scoops of ice-cream out of five possible flavours. In this case, the result would be (5+3-1)! / 3!(5-1)! = 7! / 3!*4! = 35.
- Repetition is not allowed:
- Formula: n! / r!(n-r)! . Also known as the binomial coefficient, also known as saying, for example 16 choose 3 (choose 3 pool balls out of the 16 available).
- Example: choose 3 pool balls out of the available 16, but in this case the order does not matter. The result would be 16! / 3! X (16-3)! = 16! / 3! X (13)! = 16! / 3! X (13)! = 560.
Number of probabilities in an Event
The number of probabilities in an event is:
Pr(E) = [Number of outcomes in E] / N
Where E is the event and N is the sample space.
Example: there are 8 white balls and two green balls in an urn. If you were to choose 3 balls out of the urn, what are the chances that they are all white balls?
Solution: number of white balls are 8. Since order doesn’t matter and repetition is not allowed, the formula would be for a combination without repetition: C(8,3) = 56. The probability that this event would occur would have to be divided by the sample space, which is C(10,3). So the result would be C(8,3) / C(10,3) = 7/15.
Calculating ‘at least’ questions (these are always on quizzes and tests and are brain teasers)
Two possible ways may be used to calculate ‘at least’ questions. For example, what is the probability of selecting one green ball out of three selected from an urn that has 2 green balls and 8 white balls.
One: use the multiplication and addition principles
- Event for first green ball is C(2,1) X C(8,2).
- Event for second green ball is C(2,2) X C(8,1).
- Probability for both events are added: C(2,1) X C(8,2) + C(2,2) X C(8,1).
- Divide by sample space using probability of an event formula: C(2,1) X C(8,2) + C(2,2) X C(8,1) / C(10,3) = 8/15
Two: use the complement rule
- Complement rule: Pr(E) = 1 – Pr(E’)
- Since the probability of selecting ‘all three balls are white’ = C(8,3) / C(10,3) = 7/15.
- The event ‘at least one ball is green’, is F.
- The complement of F, F’, is equal to E. Therefore E = F’.
- So by the complement rule, Pr(F) = 1 – Pr(F’) = 1 – Pr(E) = 1 – 7/15 = 8/15.
Conditional Probability
Pr(E|F). Sample space, F, is restricted. Written as Pr(E|F) = P(E and F) / Pr (F)
If E and F are independent, then Pr(E and F) = Pr(E) * Pr(F). Example: rolling dice, one roll has no affect on the other.
May also be expressed as Pr(E|F) = Pr(E) and Pr(F|E) = P(F). This is obtained from the above by: Pr(E|F) = Pr(E and F)/Pr(F) = Pr(E)*Pr(F)/Pr(F), so Pr(F) cancels out leaving Pr(E|F) = Pr(E)
A set of events are independent from each other if Pr(E1 and E2 and E3 and … En) = Pr(E1 * E2 * E3 … En). For example, a stereo has the probability of 2% of having a defective CD, 3% of having defective amplifier and 7% of defective speakers. Let these be events E, F and S^2, respectively. Then the chance of the system not being defective is E’, F’, S’^2. So the result would be Pr(E’) * Pr(F’) * Pr(S’)^2 = .98*.97*.93^2 = .822.
Hi everyone,
I have been playing around with Python on my Mac OSX Lion, version 2.7. (If you need to confirm the version just type using your Terminal:
$ Python -version
I came up with this handy script to check the ABV (alcohol percentage) for Beer or Wine. It’s a handy script if you’re into home brewing. It also helped get me going on how simple it is to use Python and it’s also handy for prototyping different algorithms before getting to some serious coding in another language!
By the way, you may use this script without restrictions, but if I ever meet you buy me a beer, preferably a DIPA :=)).
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
* ----------------------------------------------------------------------------
*/
# Program used to calculate the alcohol percentage by volume in beer.
# @ Greg Werner
# Variable definitions for command prompt inputs. Includes conversion from strings to floats
og = raw_input('Please enter your Original Gravity reading: ')
o = float(og)
tempog = raw_input('Please enter the temperature, in F, when obtaining your Original Gravity: ')
tempOG = float(tempog)
fg = raw_input('Please enter your Final Gravity reading: ')
f = float(fg)
tempfg = raw_input('Please enter the temperature, in F, when obtaining your Final Gravity: ')
tempFG = float(tempog)
# Function definition for original gravity and final gravity parameters with three floating point positions.
def abv(o, f):
x = '%.3f' % (o)
y = '%.3f' % (f)
og = float(x)
fg = float(y)
# Conditions for adjusting original y final gravity readings according to temperature in F.
if tempFG <= 69:
fg = fg + 0
elif tempFG >= 70 and tempFG <= 76:
fg = fg + 0.001
elif tempFG >= 77 and tempFG <= 83:
fg = fg + 0.002
elif tempFG >= 84 and tempFG <= 94:
fg = fg + 0.003
elif tempFG >= 95 and tempFG <= 104:
fg = fg + 0.004
else:
fg == 105
fg = tempFG + 0.007
if tempOG <= 69:
og = og + 0
elif tempOG >= 70 and tempOG <= 76:
og = og + 0.001
elif tempOG >= 77 and tempOG <= 83:
og = og + 0.002
elif tempOG >= 84 and tempOG <= 94:
og = og + 0.003
elif tempOG >= 95 and tempOG <= 104:
og = og + 0.004
else:
og == 105
og = og + 0.007
abv = ((1.05 * (og - fg))/ fg) / 0.79 * 100
return '%.3f' % abv
ABV = float(abv(o, f))
# Print results for ABV calculation.
if ABV <= 5.00:
print ('Your beer has an alcohol content of ' + str(ABV) +'. You have a low alcohol beer.')
elif ABV >= 5.01 and ABV <= 8.00:
print ('Your beer has an alcohol content of ' + str(ABV) +'. Drink in moderation, you have a medium alcohol beer.')
else:
print ('Your beer has an alcohol content of ' + str(ABV) +'. Be careful, you have yourself a bomb!')
Ok! Internet is misson critical and TV sucks.
I moved during November and lost my Internet for about a month. I did have Internet at work, but needless to say it didn’t feel right to work on my personal stuff at work…but wow was I impressed with how much we rely on the Internet! Some of the things that really caught me off guard:
- Had to have my wife pay my bills remotely, she turned into my virtual private assistant (straight from the 4 hour work week – thanks Ferris). Except I could understand her and was fully audited on all my transactions…
- Could only check my emails on my clunky 3G phone. Blah.
- Getting home at night and watching junk on TV is WAY worse that surfing on the web, even if your not surfing for anything in particular. At least you can read, watch videos, virtually socialize, man TV is such a dud. SUCH A DUD.
- Not being able to work at night stinks. When else can you catch up on all those ignored emails? During the day in the middle of meetings? Don’t think so.
- Missed out on Cyber Monday, dang.
- Couldn’t write in this blog, aggh!
- Couldn’t conference with family and co-workers in other time zones
And the list goes on.
Maybe Santa Clause can bring my a redundant fiber link and perma Internet connection LTE chip embedded in my nose.
A few weeks ago I published an article in Spanish about how much revenue large tech companies have in comparison to some of the countries around the world. To make a long story short, just two to three of the big tech companies put together have more revenue than the Gross Domestic Product (GDP) of many countries around the world. And with money comes power.
But how liquid are these companies, i.e. how much do they have in cash and other short term investments, i.e. current assets? As the old saying goes, cash is king, and boy do these tech juggernauts hold the crown. After a few minutes on Google Finance, Wikipedia and some other sites, I found some information, when compared to several governments, helps put things into perspective.
Cash and short term assets on some of the big tech companies balance sheets
- Microsoft has about 75 billion dollars in current assets. It’s not uncommon for them to add between 1-4 billion dollars in cash per quarter.
- Apple has about 47 billion dollars in current assets. They are also generating cash on a quarterly basis at an insane level.
- IBM also has about 47 billion in current assets. Do they generate cash every quarter? Just about, say a billion here, a billion there.
- Google is no slouch either and is in good company, they hold about 47 billion in current assets as well. They hold about 39 billion dollars in cash and short term investments.
- HP surprised me. Even with all their troubles of late they “only” have about 56 billion dollars in current assets.
- Cisco is also insane. They have about 57 billion in current assets.
- Let’s add EMC2 into the mix as well. They have about 10.2 billion dollars in current assets. Their operating cash flow is also solid.
- Dell…. about 30 billion in current assets. Not bad huh?
Cash balances for some governments
