<jupyter_start><jupyter_text>Homework Ice Cream Sales in InferencevilleYou have been hired to investigate a disturbing connection between ice cream sales and crime in Inferenceville. You are given a report that describes the joint distribution over random variable $S$, representing ice cream sales, and random variable $C$, representing crime. Each variable takes on a value of “low" or “high", which we'll represent with $0$ and $1$ respectively. The joint distribution (estimated from data) is as follows:(a) Are random variables $S$ and $C$ independent?[$\times    $] Yes [$\checkmark$] No<jupyter_code>def is_independent(p_X_Y):
    """
    Returns true if the given join prbability distribution is independet.
    
    >>> import numpy as np
    >>> p_X_Y = np.array([[0.4, 0.1], [0.25, 0.25]])
    >>> is_independent(p_X_Y)
    False
    
    >>> p_X_Y = np.array([[0.72, 0.08], [0.18, 0.02]])
    >>> is_independent(p_X_Y)
    True
    """

    import numpy as np
    p_X = p_X_Y.sum(axis=1)
    p_Y = p_X_Y.sum(axis=0)
    Δ = np.outer(p_X, p_Y) - p_X_Y
    return (np.linalg.norm(Δ, np.inf) - 0.00001) < 0

if __name__ == "__main__":
    import doctest
    doctest.testmod()
from sympy import init_printing
init_printing()
import numpy as np
p_S_C = np.array([[0.4, 0.1], [0.25, 0.25]])
is_independent(p_S_C)<jupyter_output><empty_output><jupyter_text>(b) After further investigation, you discover information about the temperature, represented by $T$. This random variable also takes on values $0$ or $1$ corresponding again to “low" and “high". You are able to obtain the conditional distribution $p_{S,C \mid T}(s,c \mid t)$, shown below.Are random variables $S$ and $C$ conditionally independent given $T$?[$\checkmark$] Yes [$\times    $] No<jupyter_code>import numpy as np
p_T_1 = np.array([[0.72, 0.08], [0.18, 0.02]])
p_T_2 = np.array([[0.08, 0.12], [0.32, 0.48]])
is_independent(p_T_1) and is_independent(p_T_2)<jupyter_output><empty_output><jupyter_text>(c) Determine the distribution $p_T$ from the tables above. Express your answer as a Python dictionary. The keys should be the Python integers $0$ and $1$. Assuming $p_T(0) = p$ then $p_T(1) = (1-p)$. Now by the law of total probability, $$\begin{align}p_{S,C}(0,0) &= p_{S,C\mid T}(0,0 | 0)p_T(0) + p_{S,C\mid T}(0,0 | 1)p_T(1) \\         0.4 &= 0.72p + 0.08(1-p)\\ \end{align}$$<jupyter_code>from sympy.solvers import solve
from sympy import Symbol
p = Symbol('p')
p = solve(0.08*(1-p) + 0.72*p - 0.4, p)[0]; p
p_T = {0: p, 1: 1-p}; p_T<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14830841856805665, 'fraction_numerical': 0.043273013375295044, 'mean_word_length': 4.16869918699187, 'pattern_counts': {'":': 1, '<': 14, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '434886', 'license': 'MIT', 'n_tokens_mistral': 999, 'n_tokens_neox': 937, 'n_words': 291, 'path': 'week03/04 Homework.ipynb', 'repo_name': 'infimath/Computational-Probability-and-Inference', 'size': '2542'}