liveBook · Manning

Probability distribution

As explained in Fabulous Adventures in Data Structures and Algorithms

A probability distribution specifies the probabilities assigned to the possible values of a random quantity.

A probability distribution assigns probabilities to the possible outcomes of a random quantity. Its support is the set of those outcomes, and its probability mass function (PMF) gives each outcome’s probability. Discrete distributions use countable outcomes such as die values, coin sides, or marble colors; continuous distributions use ranges such as real numbers between 0 and 1. section 12.2

A discrete distribution becomes useful in a program when it provides:

  • A finite support, such as {1, 2, 3, 4, 5, 6} for a die. section 12.2
  • A PMF that may be uniform or weighted, such as red = 0.5, blue = 0.3, and green = 0.2. section 12.2
  • A sampling operation that returns an outcome according to those probabilities, replacing direct manipulation of low-level random integers. section 12.2 section 12.3

An unfair coin

Model tails as 0 and heads as 1. A 30%-tails, 70%-heads coin uses weights 3 and 7, samples uniformly from 0 through 9, and maps 0–2 to tails and 3–9 to heads. The weights are reduced by their greatest common divisor, so the C# expression Bernoulli.Distribution(5, 7) describes five tails for every seven heads. section 12.5

var coin = Bernoulli.Distribution(5, 7);
int flip = coin.Sample();

A compact C# call shows the distribution abstraction in use: construct weighted odds once, then obtain outcomes with Sample(). section 12.5

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines support and PMFs, develops finite discrete sampling, and implements weighted Bernoulli distributions while deferring continuous distributions.
Examples
Uses dice, coins, colored marbles, card and song selection, and weighted Bernoulli coin flips.
What you can do after
Build it from scratch as a C# distribution abstraction and sample uniform or weighted discrete outcomes.
How it connects
Connects support and PMFs to discrete uniform distributions, Bernoulli distributions, and Bayesian priors, likelihoods, and posteriors.

Also explained in

Compare how 27 books explain probability distribution →

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.