Search⌘ K

Expected Value of a Discrete Distribution

Explore how to calculate the expected value of discrete distributions in C#, including both fair and weighted cases. Understand the mathematical basis and practical applications with examples, and prepare to address challenges in estimating averages in probabilistic programming.

In the previous lesson, we saw that we could compute a continuous posterior distribution when given a continuous prior and a discrete likelihood function; we hope it is clear how that is useful, but we’d like to switch gears for a moment and look at a different (but also extremely useful) computation: the expected value.


Computing the Expected Value

We’ll start with a quick refresher on how to compute the expected value of a discrete distribution.

You probably already know what expected value of a discrete distribution is; we’ve seen it before in this series. But in case you don’t recall, the basic idea is: suppose we have a distribution of values of a type where we can meaningfully take an average; the “expected value” is the average value of a set of samples as the number of samples gets very large.

A simple example is: what’s the expected value of rolling a standard, fair six-sided die? You could compute it empirically by rolling 6000d66000d6 and dividing by 60006000, but that would take a while.

Again, recall that in Dungeons and Dragons, XdYXdY is “roll a fair YsidedY-sided die XX times and take the sum”.

We could also compute this without doing any rolling; we’d expect that about 10001000 of those rolls would be 11, 10001000 ...