## Homework Problem: Alice Hunts Dragons

When she is not calculating marginal distributions, Alice spends her time hunting dragons. For every dragon she encounters, Alice measures its fire power $X$ (measured on a scale from $1$ to $4$) and its roar volume $Y$ (measured on a scale from $1$ to $3$). She notices that the proportion of dragons with certain fire power and roar volume in the population behaves as the following function:

$$\begin{eqnarray}
f(x,y) = \begin{cases} x^2+y^2 &\text{if } x \in \{1,2,4\} \text{ and } y \in \{1,3\} \\
0 &\text{otherwise}. \end{cases}
\end{eqnarray}$$

In other words, the joint probability table $p_{X,Y}$ is of the form

$$p_{X,Y}(x,y) = c f(x, y) \qquad \text {for }x \in \{ 1, 2, 3, 4\} , y \in \{ 1, 2, 3\} ,$$
 
for some constant $c>0$ that you will determine.

**Question:** Determine the constant $c$, which ensures that $p_{X,Y}$ is a valid probability distribution. (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)


```python
Ω = {(i, j) for i in range(1, 5) for j in range(1, 4)}
from fractions import Fraction
joint_X_Y = {(i, j): (i**2 + j**2) for i in {1, 2, 4} for j in {1, 3}}
c = 1/sum(joint_X_Y.values())
print(Fraction(c).limit_denominator())
```

    1/72


**Question:** Determine $P(Y<X)$. (Note that $\{Y<X\}$ is an event. Think about what outcomes are in it.)

(Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)


```python
Y_lt_X = {x for x in joint_X_Y if x[1] < x[0]}
prob_Y_lt_X = sum([joint_X_Y[x] for x in Y_lt_X]) * c
print(Fraction(prob_Y_lt_X).limit_denominator())
```

    47/72


**Question:** Determine $P(X<Y)$. (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)


```python
X_lt_Y = {x for x in joint_X_Y if x[1] > x[0]}
prob_X_lt_Y = sum([joint_X_Y[x] for x in X_lt_Y]) * c
print(Fraction(prob_X_lt_Y).limit_denominator())
```

    23/72


**Question:** Determine $P(Y=X)$. (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)


```python
X_eq_Y = {x for x in joint_X_Y if x[1] == x[0]}
prob_X_eq_Y = sum([joint_X_Y[x] for x in X_eq_Y]) * c
print(Fraction(prob_X_eq_Y).limit_denominator())
```

    1/36


**Question:** Determine $P(Y=3)$. (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)


```python
Y_eq_3 = {x for x in joint_X_Y if x[1] == 3}
prob_Y_eq_3 = sum([joint_X_Y[x] for x in Y_eq_3]) * c
print(Fraction(prob_Y_eq_3).limit_denominator())
```

    2/3


**Question:** Find the probability tables for $p_X$ and $p_Y$. Express your answers as Python dictionaries. (Your answer should be the Python dictionary itself, and not the dictionary assigned to a variable, so please do not include, for instance, “prob_table =" before specifying your answer. You can use fractions. If you use decimals instead, please be accurate and use at least 5 decimal places.)

$p_X$ probability table (the dictionary keys should be the Python integers 1, 2, 3, 4): 


```python
prob_X = {i: 0 for i in range(1, 5)} # initialize the dictionary with 0 
for key, values in joint_X_Y.items():
    if key[0] in prob_X:
        prob_X[key[0]] += values * c
        
prob_X        
```




    {1: 0.16666666666666669, 2: 0.25, 3: 0, 4: 0.5833333333333333}



$p_Y$ probability table (the dictionary keys should be the Python integers 1, 2, 3): 


```python
prob_Y = {i: 0 for i in range(1, 4)} # initialize the dictionary with 0 
for key, values in joint_X_Y.items():
    if key[1] in prob_Y:
        prob_Y[key[1]] += values * c
        
prob_Y
```




    {1: 0.33333333333333337, 2: 0, 3: 0.6666666666666666}



## Homework Problem: Alice's Coins

Alice has five coins in a bag: two coins are normal, two are double-headed, and the last one is double-tailed. She reaches into the bag and randomly pulls out a coin. Without looking at the coin she drew, she tosses it.

**Question:** What is the probability that once the coin lands, the side of the coin that is face-down is heads? (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)

**Answer:** Let $X$ is the random variable for selecting the coin. Let $X = \{F, H, T\}$ takes values $F$ for fair coin, $H$ for double-headed coin and $T$ for double-tailed coin. Also $Y = \{h, t\}$ is the random variable for getting $h$ for face down head and $t$ for face down tail. Then the joint probability distribution is given by 

|                      | Y=h | Y=t | X<sub>marginal</sub> |
|----------------------|-----|-----|----------------------|
| X=F                  | 1/5 | 1/5 | 2/5                  |
| X=H                  | 2/5 | 0   | 2/5                  |
| X=T                  | 0   | 1/5 | 1/5                  |
| Y<sub>marginal</sub> | 3/5 | 2/5 |                      |

The probability of getting face down head is given by marginal probibility $\mathbb{P}(Y=h) = 3/5$.

**Question:** The coin lands and shows heads face-up. What is the probability that the face-down side is heads? (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)

**Answer:** This question asking about conditional probability 
$$\mathbb{P}(X=H|Y=h) = \frac{\mathbb{P}(X=H, Y=h)}{\mathbb{P}(Y=h) } = \frac{2/5}{3/5} = \frac{2}{3} $$

Alice discards the first coin (the one from part (b) that landed and showed heads face-up), reaches again into the bag and draws out a random coin. Again, without looking at it, she tosses it.

**Question:** What is the probability that the coin shows heads face-up? (Please be precise with at least 3 decimal places, unless of course the answer doesn't need that many decimal places. You could also put a fraction.)

**Answer:** Let $Z$ is the random varable for getting second coin face-up heads or tails. Also note that the first coin with face-up heads is discarded. There are two possibiliy of getting heads on face-up if $X=F$ or $X=H$. Let $W$ is the random variable for withdrawing second coin. 

The joint probability distribution of $W$ and $Z$ given $X=F$, $i.e.$, $P(W,Z|X=F)$

|                      | Z=h | Z=t | W<sub>marginal</sub> |
|----------------------|-----|-----|:--------------------:|
| W=F                  | 1/8 | 1/8 | 1/4                  |
| W=H                  | 1/2 | 0   | 1/2                  |
| W=T                  | 0   | 1/4 | 1/4                  |
| Z<sub>marginal</sub> | 5/8 | 3/8 |                      |

The joint probability distribution of $W$ and $Z$ given $X=H$, $i.e.$, $P(W,Z|X=H)$

|                      | Z=h | Z=t | W<sub>marginal</sub> |
|----------------------|-----|-----|:--------------------:|
| W=F                  | 1/4 | 1/4 | 1/2                  |
| W=H                  | 1/4 | 0   | 1/4                  |
| W=T                  | 0   | 1/4 | 1/4                  |
| Z<sub>marginal</sub> | 1/2 | 1/2 |                      |

Hence the probability of getting heads in face-up is given by

$$
\begin{align}
\mathbb{P}(Z=h|Y=h) 
&= \mathbb{P}(Z=h|X=F) \times \mathbb{P}(X=F|Y=h) + \mathbb{P}(Z=h|X=H) \times \mathbb{P}(X=H|Y=h) \\
&= \mathbb{P}(Z=h|X=F) \times \frac{\mathbb{P}(X=F, Y=h)}{ \mathbb{P}(Y=h)} + \mathbb{P}(Z=h|X=H) \times \frac{\mathbb{P}(X=H, Y=h)}{ \mathbb{P}(Y=h)} \\
&= \frac{5}{8} \times \frac{1/5}{3/5} + \frac{1}{2} \times \frac{2/5}{3/5}\\
&= \frac{13}{24}
\end{align}
$$


```python

```

29ea1e7d58626e43c6f66eeece370ad4261982a6
ipynb
Jupyter Notebook
week02/06 Homework.ipynb
infimath/Computational-Probability-and-Inference
e48cd52c45ffd9458383ba0f77468d31f781dc77
MIT
2019-04-04T03:07:47.000Z
2019-04-04T03:07:47.000Z
week02/06 Homework.ipynb
infimath/Computational-Probability-and-Inference
e48cd52c45ffd9458383ba0f77468d31f781dc77
MIT
week02/06 Homework.ipynb
infimath/Computational-Probability-and-Inference
e48cd52c45ffd9458383ba0f77468d31f781dc77
MIT
2021-02-27T05:33:49.000Z
2021-02-27T05:33:49.000Z
Qwen/Qwen-72B
1. YES
2. YES