chapter twelve

12 A better abstraction for randomness

 

In my university days, I paid little attention to my only required statistics class. I found the jargon confusing and foresaw little use for statistical reasoning in my future career. I was half right: the jargon is confusing. But because I ended up implementing programming tools for data scientists, my weak knowledge of probabilistic reasoning needed fixing in a hurry.

In this chapter, we’ll start with a refresher on statistics jargon. If you already have a solid background in probability and statistics, much of this material will be review. Then we’ll come up with a better way to represent randomness than standard random number generating functions. We’ll use high-level methods such as Where, SelectMany, Join, and GroupBy to manipulate sequences without writing tedious loops. We could similarly benefit from manipulating random quantities at a higher level of abstraction.

12.1 What are probabilities?

12.2 What are discrete probability distributions?

12.3 Generating uniform samples with Random

12.4 IDistribution<T> and IDiscreteDistribution<T>

12.5 Flipping an unfair coin with Bernoulli

12.6 Improving the ecosystem with extension methods

12.7 Representing unfair die rolls by adding a projection

12.8 Categorical algorithm 1: Make a big list

12.9 Categorical algorithm 2: Climb a ladder

12.10 Categorical algorithm 3: Rejecting rejection sampling

12.11 Categorical algorithm 4: The alias algorithm

12.12 Filtering out a category

Summary