DDist Practice Problems
1) Joint Distributions
Tutor Problem If pr_A = DDist({0 : .7, 1: .3}) anddef 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}) anddef 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).