# Bayesian Formula - probability calculation

Discussion in 'NZ Computing' started by will, Jan 25, 2004.

1. ### willGuest

hi,

can i please have some pointers to calculate the 'spamicity'?

i've read a couple of websites, but most of them are using it in a
programming language way, rather than a formulae.

eg this from www.paulgraham.com

(let ((g (* 2 (or (gethash word good) 0)))
(b (or (gethash word bad) 0)))
(unless (< (+ g b) 5)
(max .01
(min .99 (float (/ (min 1 (/ b nbad))
(+ (min 1 (/ g ngood))

what does it mean in simple english?

thanks

will.

will, Jan 25, 2004

2. ### WarwickGuest

Byes formaula calculates the new probability of something being true (p')
given an old probability (p) + some new new evidence. The new evidence is
expressed as a probability as well. In the formula it is expressed as Py
and Pn - probability of yes and probabilty of no.

the formula is p' = 100 * Py * p / Py * p + Pn(100-p).

worked example. Probability of Mainlander being a miserable bastard is
estimated at 10% (p).
10 new posts then suggest the odds of Mainlander being a miserable bastard
are 90%.
Therefore Py = 90 and Pn = 10.

Our revised probablity of our hypothesis is then
100 * 90 * 10 / 90 * 10 + 10*(100-10) = 50

If you had another indicator you would make p' p and do it again.

HTH

Warwick

Warwick, Jan 25, 2004

3. Hi will,
Will, that is an extract of Common Lisp. (gethash word good) is looking up
the word in the group of good words. If it's not found the second part of
the OR is computed which then returns 0. Ditto for (gethash word bad) except
the word is looked up in the group of bad words.

UNLESS means to do something unless the test is true.

MAX and MIN find the maximum or minimum of a set of numbers.

FLOAT converts a number into a floating point representation.

/ is division.

Everything is in prefix format, e.g. (+ 1 (* 2 3)) = (+ 1 6) = 7. It's like
function calls where the opening bracket is before the function name instead
of directly after the function name, e.g. sqrt(x) in many other languages
would be written as (sqrt x) in Lisp.

This pseudocode translation may help:

let good-entry = is the word in the group of good words?
g = if good-entry then choose the good-entry else 0
unless (g+b) < 5
max(0.01
--------------------------------
min(1 g/ngood) + min(1 b/nbad) ]))

Regards,

4. ### willGuest

#### hmmm.. thanks. so how is the result related to the Bayesian
formula? is the above code doing the same job as the Bayesian formula?

thanks

will.

will, Jan 25, 2004
5. ### Julian VischGuest

P(a|b)=P(b|a)P(a) is the bayesian formula in its simplest form, gets a
----------
P(b)

lot more complicated.

Julian Visch, Jan 25, 2004