Home / Week 10 Exercises / Probability Distributions in Python / DDist Practice Problems

DDist Practice Problems

You are not logged in.

If you are a current student, please Log In for full access to this page.
Note that these problems are for your practice, and will not affect your grade. These problems are intended to be worked by hand, to help you familiarize yourself with the processes you will implement in Python in the DDist exercise.

1) Joint Distributions

Tutor Problem If pr_A = DDist({0 : .7, 1: .3}) and
def pr_B_given_A(a):
    assert a in (0, 1)
    if a == 1:
        return DDist({6 : .9, 7 : .1})
    else:
        return DDist({6 : .2, 7 : .8})
what is the value of make_joint_distribution(pr_A, pr_B_given_A)? Enter a legal Python DDist instance.

Note that the statement assert a in (0, 1) is there so that the conditional probability distribution procedure will generate an error if we try to condition it on a value that is not in the domain of A which is, in this case the set \{0, 1\}.

2) Projection

If

pr_X = DDist({-2:0.1, 2:0.3, -1:0.4, 1:0.1, 3: 0.1})
what is the value of this projection (Enter a valid DDist instance.)?
pr_X.project(lambda x: abs(x))

We can also project a distribution into a completely different domain. For example, if we had a list L, we could project \Pr(X) onto a drastically different domain to find the distribution over L[X]. So, if

pr_X = DDist({-2:0.1, 2:0.3, -1:0.4, 1:0.1, 3: 0.1})
L = ['dog', 'cat', 'ferret', 'tomato']
what is the value of this projection (Enter a valid DDist instance.)?
pr_X.project(lambda x: L[x])
Note: this involves sneaky list indexing from the end....

3) Conditioning

If

pr_X = DDist({-2:0.1, 2:0.3, -1:0.4, 1:0.1, 3: 0.1})
what is the value of the following distribution (Enter a valid DDist instance.)?
pr_X.condition(lambda x: x < 0)

4) Total Probability

Tutor Problem If pr_A = DDist({0 : .7, 1: .3}) and
def pr_B_given_A(a):
    assert a in (0, 1)
    if a == 1:
        return DDist({6 : .9, 7: .1})
    else:
        return DDist({6 : .2, 7 : .8})
what is the value of total_probability(pr_A, pr_B_given_A)? Enter a legal Python DDist instance.

5) Manipulation of Probabilities and Distributions

Consider two random variables, E and S.

Imagine that we have defined the following quantities, which may be distributions, conditional distributions, joint distributions, or numbers:

  • \(X: \Pr(E)\)
  • \(Y: \Pr(S)\)
  • \(Z: \Pr(E~|~S)\)
  • \(W: \Pr(S~|~E)\)
  • \(V: \Pr(S,~E)\)
  • \(U: \Pr(S=\text{True},~E=\text{True})\)
  • \(A: \Pr(E=\text{True})\)
  • \(B: \Pr(E~|~S=\text{False})\)

For each quantity, how could it be computed from the others? For each expression below, enter the letter corresponding to its result (one of X, Y, Z, W, V, U, A, or B).

    

total_probability(Y, Z)
V.project(lambda x: x[1])
lambda c: bayes_rule(X, W, c)
make_joint_distribution(Y, Z)
V.prob((True, True))
X.prob(True)
bayes_rule(X, W, False)