def main(): n = 101 low = 0.0 high = 1.0 step = (high - low) / (n - 1) suite = coin._make_uniform_suite(low, high, n) evidence = 140, 110 likelihood_biased = _integrate_likelihood(evidence, suite, step) print(likelihood_biased) likelihood_unbiased = coin._likelihood(evidence, 0.5) print(likelihood_unbiased) ratio = likelihood_biased / likelihood_unbiased print(ratio)
def _integrate_likelihood(evidence, suite, step): """ Computes the integral of the likelihood over all hypothesis in suite. Args: evidence: some representation of the evidence suite: Pmf object that maps possible parameters to their probabilities step: float step size between parameters in the suite Returns: float """ total = 0.0 for hypo in suite._values(): likelihood = coin._likelihood(evidence, hypo) total += likelihood * suite._prob(hypo) return total