Home / Week 10 Exercises / Great Expectations

Great Expectations

The questions below are due on Sunday April 21, 2019; 11:00:00 PM.
 
You are not logged in.

If you are a current student, please Log In for full access to this page.
Music for this Problem
 

In the previous exercise, we introduced the concept of the expected value of a random variable. In this exercise, we will take that concept one step further, and explore the idea of the expected value of a function with respect to a random variable.

Consider a random variable X, with support elements x_0,x_1,\ldots,x_N. We will denote and define the expected value of a function f with respect to a random variable X as follows:

E_X[f(X)] = \sum_{i=0}^N \left(f(x_i)\cdot \Pr(X=x_i)\right)

For example, consider a random variable A described by the following instance of dist.DDist:

a = dist.DDist({2: 0.5, -2: 0.3, 1: 0.1, 0: 0.1})

Then we could find E_A[A^2] as follows:

E_A[A^2] = \sum_{i=0}^N \left(a_i^2\cdot \Pr(A=a_i)\right) = 4\cdot0.5 + 4\cdot 0.3+ 1\cdot 0.1 + 0\cdot 0.1 = 3.3

1) Expected Value

Define a Python function expectation which takes two arguments:

  • a DDist representing a random variable
  • a function f that takes elements of that distribution's support as input, and returns a number

expectation should return a number that represents the expected value of f with respect to the random variable described by the distribution passed in as the first argument.

Enter your code below. Assume that all the classes and functions from lib601.dist have been imported with:

import lib601.dist as dist

2) Mean

The mean of a random variable X is defined as:

E_X[X]

Write a Python function mean that uses expectation to determine the mean of a random variable represented by a DDist that is passed as an argument.

Enter your code below. Assume that expectation is defined for you, and that all the classes and functions from lib601.dist have been imported with:

import lib601.dist as dist

3) Variance

The variance of a random variable X is a measure of how "spread out" a distribution is; it is defined as follows:

E_X[(X-\mu)^2]

where \mu is the mean of X.

Write a Python function variance that uses expectation to determine the mean of a random variable represented by a DDist that is passed as an argument.

Enter your code below. Assume that expectation and mean are defined for you, and that all the classes and functions from lib601.dist have been imported with: