Now we are ready to write the likelihood function. As usual, I
define a new class that extends
class Price(thinkbayes.Suite): def __init__(self, pmf, player): thinkbayes.Suite.__init__(self, pmf) self.player = player
pmf represents the prior
player is a Player
object as described in the previous section. Here’s
def Likelihood(self, data, hypo): price = hypo guess = data error = price - guess like = self.player.ErrorDensity(error) return like
hypo is the hypothetical price of
data is the contestant’s
best guess at the price.
error is the
like is the likelihood
of the data, given the hypothesis.
ErrorDensity is defined in
# class Player: def ErrorDensity(self, error): return self.pdf_error.Density(error)
ErrorDensity works by evaluating
pdf_error at the given
error. The result is a
probability density, so it is not really a probability. But remember that
Likelihood doesn’t need to compute a
probability; it only has to compute something
proportional to a probability. As long as the
constant of proportionality is the same for all likelihoods, it gets
canceled out when we normalize the posterior distribution.
And therefore, a probability density is a perfectly good likelihood.