Bayesian inference is a method of statistical inference in which Bayes' theorem is used to update the probability for a hypothesis as more evidence or information becomes available.
The Core Equation
P(A|B) = [ P(B|A) * P(A) ] / P(B)
Where:
- P(A) is the Prior probability.
- P(B|A) is the Likelihood.
- P(A|B) is the Posterior probability.
Code Implementation
bayes.py
import numpy as np
# 1. Define Prior
prior = np.ones(100) / 100
def update(prior, heads, total):
likelihood = p_grid**heads * (1 - p_grid)**(total - heads)
posterior = likelihood * prior
return posterior / posterior.sum()