<jupyter_start><jupyter_text>1. Probability and Inference  1.12 Exercises  1a) Marginal probability density:$$ \sum_{\theta}{p(\theta, y) d\theta} = \sum_{\theta}{p(\theta)p(y|\theta) d\theta} $$$$ 0.5 \mathcal{N}(1,\,\sigma^{2}) + 0.5 \mathcal{N}(2,\,\sigma^{2}) $$<jupyter_code>nm = pm.NormalMixture.dist(w=np.array([0.5, 0.5]), mu=np.array([1, 2]), sigma=np.array([2, 2]))
nm_data = pd.DataFrame(nm.random(size=10000))
#nm_data.plot(kind='hist')
sns.displot(data=nm_data, kde=True)<jupyter_output><empty_output><jupyter_text>b) $$ Pr(\theta=1 | y=1) $$Posterior probability that $ \theta $ = 1, given observed data $ y = 1 $.$$ Pr(\theta=1 | y=1) = \frac{p(y=1|\theta=1)p(\theta=1)}{p(y=1|\theta=1)p(\theta=1) + p(y=1|\theta=2)p(\theta=2)} = $$<jupyter_code>nm1 = pm.Normal.dist(mu=1, sigma=2)
nm2 = pm.Normal.dist(mu=2, sigma=2)
nm1v = np.exp(nm1.logp(1).eval())
nm2v = np.exp(nm2.logp(1).eval())
display(nm1v)
display(nm2v)<jupyter_output><empty_output><jupyter_text>$$ \frac{0.2*0.5}{0.2*0.5 + 0.176*0.5} $$<jupyter_code>(0.2*0.5)/(0.2*0.5 + 0.176*0.5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2610294117647059, 'fraction_numerical': 0.07628676470588236, 'mean_word_length': 6.117647058823529, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '318050', 'license': 'Apache-2.0', 'n_tokens_mistral': 538, 'n_tokens_neox': 509, 'n_words': 63, 'path': 'BayesianDataAnalysis/Ch1.ipynb', 'repo_name': 'MikaelUmaN/Books', 'size': '1088'}