liveBook · Manning

Bayes' theorem

As explained in Fabulous Adventures in Data Structures and Algorithms

Bayes' theorem is a probability rule that computes a conditional probability by combining prior probabilities with the likelihood of observed evidence.

Bayes' theorem updates a belief about a cause after observing an effect. It combines a prior probability with a likelihood, then normalizes the resulting joint probability to obtain a posterior probability. section 13.0 section 13.3

Written for events A and B, P(A|B) = P(A)P(B|A) / P(B) = P(A&B) / P(B). The theorem reverses the direction of reasoning: evidence about an effect updates confidence in its possible cause. section 13.1 section 13.3

Sneezing and colds

A survey of 10,000 people finds 1,000 with colds, establishing a 10% prior probability. Among 1,000 people with colds, 860 sneezed, giving an 86% likelihood of sneezing given a cold. Reversing the question, 860 of the 1,130 people who sneezed had colds, so the posterior probability is 860/1,130. section 13.1

A generic implementation represents the prior as IDiscreteDistribution<A> and the likelihood as Func<A, IDiscreteDistribution<B>>. It forms a joint distribution, filters it to the observed evidence, and projects the remaining causes into the posterior. section 13.3

Computing the posterior in C#

With a prior assigning weights 90 and 10 to no cold and cold, Posterior(SneezedGivenCold) produces the observed-sneeze weights No:27 and Yes:86, matching the survey ratio 270:860.

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Develops the formula through a survey table and maps each probability term to joint-distribution, filtering, and projection operations.
Examples
Uses a 10,000-person cold-and-sneeze survey and a C# categorical-distribution example producing posterior weights.
What it assumes
Assumes discrete distributions and develops prior, likelihood, joint, conditional, and posterior probabilities through a concrete table.
What you can do after
Build it from scratch as a generic C# posterior function using joint distributions, filters, and projections.
How it connects
Connects prior probability, likelihood functions, conditional probability, joint probability distributions, posterior probability, filtering, and projection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.