<jupyter_start><jupyter_text>1.3 The cookie problem<jupyter_code>cookie_data = make_cookies_observations()
cookie_data
cookie_data.value_counts().rename('count').reset_index()
cookies = Discrete.from_observations(cookie_data)
cookies.data.reset_index()<jupyter_output><empty_output><jupyter_text>p(vanilla | bowl 1)<jupyter_code>vanilla__bowl_1 = cookies.given(bowl='bowl 1').p(flavor='vanilla')
vanilla__bowl_1<jupyter_output><empty_output><jupyter_text>1.4 Bayes's theorem  p(vanilla)<jupyter_code>vanilla = cookies.p(flavor='vanilla')
vanilla<jupyter_output><empty_output><jupyter_text>p(bowl)<jupyter_code>bowl = Discrete.from_probs({'bowl 1': 0.5, 'bowl 2': 0.5}, variables=['bowl'])
bowl.data.reset_index()<jupyter_output><empty_output><jupyter_text>p(bowl 1)<jupyter_code>bowl_1 = bowl.p(bowl='bowl 1')
bowl_1<jupyter_output><empty_output><jupyter_text>p(bowl 1 | vanilla)<jupyter_code>bowl_1__vanilla = bowl_1 * vanilla__bowl_1 / vanilla
bowl_1__vanilla<jupyter_output><empty_output><jupyter_text>check<jupyter_code>cookies.given(flavor='vanilla').p(bowl='bowl 1')<jupyter_output><empty_output><jupyter_text>1.5 The diachronic interpretation  p(bowl 2)<jupyter_code>bowl_2 = bowl.p(bowl='bowl 2')
bowl_2<jupyter_output><empty_output><jupyter_text>p(vanilla | bowl 2)<jupyter_code>vanilla__bowl_2 = cookies.given(bowl='bowl 2').p(flavor='vanilla')
vanilla__bowl_2<jupyter_output><empty_output><jupyter_text>p(vanilla)<jupyter_code>bowl_1 * vanilla__bowl_1 + bowl_2 * vanilla__bowl_2
vanilla
cookies.data.reset_index()<jupyter_output><empty_output><jupyter_text>1.6 The M & M problem<jupyter_code>mix_1994 = Discrete.from_probs({
    'brown': 0.3, 'yellow': 0.2, 'red': 0.2,
    'green': 0.1, 'orange': 0.1, 'tan': 0.1
}, variables='color')
mix_1994.data.reset_index()
mix_1996 = Discrete.from_probs({
    'blue': 0.24, 'green': 0.2, 'orange': 0.16,
    'yellow': 0.14, 'red': 0.13, 'brown': 0.13
}, variables='color')
mix_1996.data.reset_index()
bag = Discrete.from_probs({1994: 0.5, 1996: 0.5}, variables='bag')
bag.data.reset_index()
yellow__1994 = mix_1994.p(color='yellow')
yellow__1996 = mix_1996.p(color='yellow')
green__1994 = mix_1994.p(color='green')
green__1996 = mix_1996.p(color='green')
likelihood_a = yellow__1994 * green__1996
likelihood_b = yellow__1996 * green__1994
prior_likelihood_a = bag.p(bag=1994) * likelihood_a
prior_likelihood_b = bag.p(bag=1996) * likelihood_b
evidence = prior_likelihood_a + prior_likelihood_b
prior_likelihood_a / evidence
prior_likelihood_b / evidence<jupyter_output><empty_output><jupyter_text>using BayesRule class<jupyter_code>priors = {'a': 0.5, 'b': 0.5}
likelihoods = {
    'a': yellow__1994 * green__1996,
    'b': yellow__1996 * green__1994
}
bayes_rule = MultipleBayesRule(
    prior=priors, likelihood=likelihoods
)
bayes_rule.posterior()<jupyter_output><empty_output><jupyter_text>1.7 The Monty Hall problem<jupyter_code>priors = {'a': 1 / 3, 'b': 1 / 3, 'c': 1 / 3}
likelihoods = {'a': 1 / 2, 'b': 0, 'c': 1}
MultipleBayesRule(prior=priors, likelihood=likelihoods).posterior()<jupyter_output><empty_output><jupyter_text>variation<jupyter_code>likelihoods = {'a': 1, 'b': 0, 'c': 1}
MultipleBayesRule(prior=priors, likelihood=likelihoods).posterior()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15531587057010784, 'fraction_numerical': 0.05793528505392912, 'mean_word_length': 8.926605504587156, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '106115', 'license': 'MIT', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1327, 'n_words': 175, 'path': 'examples/notebooks/tb/chapter_01__bayes_theorem.ipynb', 'repo_name': 'vahndi/probability', 'size': '3245'}