marimo-learn / _site /probability /04_conditional_probability.html
Haleshot's picture
relevant assets and workflow
1cce1df unverified
raw
history blame
23.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="./favicon.ico" />
<!-- Preload is necessary because we show these images when we disconnect from the server,
but at that point we cannot load these images from the server -->
<link rel="preload" href="./assets/gradient-yHQUC_QB.png" as="image" />
<link rel="preload" href="./assets/noise-60BoTA8O.png" as="image" />
<!-- Preload the fonts -->
<link rel="preload" href="./assets/Lora-VariableFont_wght-B2ootaw-.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/PTSans-Regular-CxL0S8W7.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/PTSans-Bold-D9fedIX3.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Regular-BTCkDNvf.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Medium-DU3aDxX5.ttf" as="font" crossorigin="anonymous" />
<link rel="preload" href="./assets/FiraMono-Bold-CLVRCuM9.ttf" as="font" crossorigin="anonymous" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="a marimo app" />
<link rel="apple-touch-icon" href="./apple-touch-icon.png" />
<link rel="manifest" href="./manifest.json" />
<script data-marimo="true">
function __resizeIframe(obj) {
var scrollbarHeight = 20; // Max between windows, mac, and linux
function setHeight() {
var element = obj.contentWindow.document.documentElement;
// If there is no vertical scrollbar, we don't need to resize the iframe
if (element.scrollHeight === element.clientHeight) {
return;
}
// Create a new height that includes the scrollbar height if it's visible
var hasHorizontalScrollbar = element.scrollWidth > element.clientWidth;
var newHeight = element.scrollHeight + (hasHorizontalScrollbar ? scrollbarHeight : 0);
// Only update the height if it's different from the current height
if (obj.style.height !== `${newHeight}px`) {
obj.style.height = `${newHeight}px`;
}
}
// Resize the iframe to the height of the content and bottom scrollbar height
setHeight();
// Resize the iframe when the content changes
const resizeObserver = new ResizeObserver((entries) => {
setHeight();
});
resizeObserver.observe(obj.contentWindow.document.body);
}
</script>
<marimo-filename hidden>notebook.py</marimo-filename>
<marimo-mode data-mode='edit' hidden></marimo-mode>
<marimo-version data-version='0.11.9' hidden></marimo-version>
<marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"code_editor_font_size": 14, "theme": "light", "cell_output": "above", "default_width": "medium", "dataframes": "rich"}, "formatting": {"line_length": 79}, "keymap": {"preset": "default", "overrides": {}}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun", "watcher_on_save": "lazy", "output_max_bytes": 8000000, "std_stream_max_bytes": 1000000}, "save": {"autosave": "off", "autosave_delay": 1000, "format_on_save": false}, "package_management": {"manager": "pip"}, "server": {"browser": "default", "follow_symlink": false}, "snippets": {"custom_paths": [], "include_default_snippets": true}}' data-overrides='{}' hidden></marimo-user-config>
<marimo-app-config data-config='{"width": "medium", "app_title": "Conditional Probability"}' hidden></marimo-app-config>
<marimo-server-token data-token='123' hidden></marimo-server-token>
<title>Conditional Probability</title>
<script type="module" crossorigin src="./assets/index-BiV-b1K2.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-DkqMrX_B.css">
<marimo-wasm hidden=""></marimo-wasm>
<script>
if (window.location.protocol === 'file:') {
alert('Warning: This file must be served by an HTTP server to function correctly.');
}
</script>
<style>
#save-button {
display: none !important;
}
#filename-input {
display: none !important;
}
</style>
<marimo-code hidden="" data-show-code="false">import%20marimo%0A%0A__generated_with%20%3D%20%220.11.9%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20app_title%3D%22Conditional%20Probability%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Conditional%20Probability%0A%0A%20%20%20%20%20%20%20%20_This%20notebook%20is%20a%20computational%20companion%20to%20the%20book%20%5B%22Probability%20for%20Computer%20Scientists%22%5D(https%3A%2F%2Fchrispiech.github.io%2FprobabilityForComputerScientists%2Fen%2Fpart1%2Fcond_prob%2F)%2C%20by%20Stanford%20professor%20Chris%20Piech._%0A%0A%20%20%20%20%20%20%20%20In%20probability%20theory%2C%20we%20often%20want%20to%20update%20our%20beliefs%20when%20we%20receive%20new%20information.%20%0A%20%20%20%20%20%20%20%20Conditional%20probability%20helps%20us%20formalize%20this%20process%20by%20calculating%20%22_what%20is%20the%20chance%20of%20%0A%20%20%20%20%20%20%20%20event%20%24E%24%20happening%20given%20that%20we%20have%20already%20observed%20some%20other%20event%20%24F%24%3F_%22%5B%3Csup%3E1%3C%2Fsup%3E%5D(https%3A%2F%2Fchrispiech.github.io%2FprobabilityForComputerScientists%2Fen%2Fpart1%2Fcond_prob%2F)%0A%0A%20%20%20%20%20%20%20%20When%20we%20condition%20on%20an%20event%20%24F%24%3A%0A%0A%20%20%20%20%20%20%20%20-%20We%20enter%20the%20universe%20where%20%24F%24%20has%20occurred%0A%20%20%20%20%20%20%20%20-%20Only%20outcomes%20consistent%20with%20%24F%24%20are%20possible%0A%20%20%20%20%20%20%20%20-%20Our%20sample%20space%20reduces%20to%20%24F%24%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Definition%20of%20Conditional%20Probability%0A%0A%20%20%20%20%20%20%20%20The%20probability%20of%20event%20%24E%24%20given%20that%20event%20%24F%24%20has%20occurred%20is%20denoted%20as%20%24P(E%20%5Cmid%20F)%24%20and%20is%20defined%20as%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(E%20%5Cmid%20F)%20%3D%20%5Cfrac%7BP(E%20%5Ccap%20F)%7D%7BP(F)%7D%24%24%0A%0A%20%20%20%20%20%20%20%20This%20formula%20tells%20us%20that%20the%20conditional%20probability%20is%20the%20probability%20of%20both%20events%20occurring%20%0A%20%20%20%20%20%20%20%20divided%20by%20the%20probability%20of%20the%20conditioning%20event.%0A%0A%20%20%20%20%20%20%20%20Let's%20start%20with%20a%20visual%20example.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20matplotlib_venn%20import%20venn3%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20return%20np%2C%20plt%2C%20venn3%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20plt%2C%20venn3)%3A%0A%20%20%20%20%23%20Create%20figure%20with%20square%20boundaries%0A%20%20%20%20plt.figure(figsize%3D(10%2C%203))%0A%0A%20%20%20%20%23%20Draw%20square%20sample%20space%20first%0A%20%20%20%20rect%20%3D%20plt.Rectangle((-2%2C%20-2)%2C%204%2C%204%2C%20fill%3DFalse%2C%20color%3D%22gray%22%2C%20linestyle%3D%22--%22)%0A%20%20%20%20plt.gca().add_patch(rect)%0A%0A%20%20%20%20%23%20Set%20the%20axis%20limits%20to%20show%20the%20full%20rectangle%0A%20%20%20%20plt.xlim(-2.5%2C%202.5)%0A%20%20%20%20plt.ylim(-2.5%2C%202.5)%0A%0A%20%20%20%20%23%20Create%20Venn%20diagram%20showing%20E%20and%20F%0A%20%20%20%20%23%20For%20venn3%2C%20subsets%20order%20is%3A%20(100%2C%20010%2C%20110%2C%20001%2C%20101%2C%20011%2C%20111)%0A%20%20%20%20%23%20Representing%3A%20(A%2C%20B%2C%20AB%2C%20C%2C%20AC%2C%20BC%2C%20ABC)%0A%20%20%20%20v%20%3D%20venn3(subsets%3D(30%2C%2020%2C%2010%2C%2040%2C%200%2C%200%2C%200)%2C%20set_labels%3D(%22E%22%2C%20%22F%22%2C%20%22Rest%22))%0A%0A%20%20%20%20%23%20Customize%20colors%0A%20%20%20%20if%20v%3A%0A%20%20%20%20%20%20%20%20for%20id%20in%20%5B%22100%22%2C%20%22010%22%2C%20%22110%22%2C%20%22001%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20v.get_patch_by_id(id)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20id%20%3D%3D%20%22100%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v.get_patch_by_id(id).set_color(%22%23ffcccc%22)%20%20%23%20Light%20red%20for%20E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20id%20%3D%3D%20%22010%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v.get_patch_by_id(id).set_color(%22%23ccffcc%22)%20%20%23%20Light%20green%20for%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20id%20%3D%3D%20%22110%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v.get_patch_by_id(id).set_color(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%23e6ffe6%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%20%20%23%20Lighter%20green%20for%20intersection%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20id%20%3D%3D%20%22001%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20v.get_patch_by_id(id).set_color(%22white%22)%20%20%23%20White%20for%20rest%0A%0A%20%20%20%20plt.title(%22Conditional%20Probability%20in%20Sample%20Space%22)%0A%0A%20%20%20%20%23%20Remove%20ticks%20but%20keep%20the%20box%20visible%0A%20%20%20%20plt.gca().set_yticks(%5B%5D)%0A%20%20%20%20plt.gca().set_xticks(%5B%5D)%0A%20%20%20%20plt.axis(%22on%22)%0A%0A%20%20%20%20%23%20Add%20sample%20space%20annotation%20with%20arrow%0A%20%20%20%20plt.annotate(%0A%20%20%20%20%20%20%20%20%22Sample%20Space%20(100)%22%2C%0A%20%20%20%20%20%20%20%20xy%3D(-1.5%2C%201.5)%2C%0A%20%20%20%20%20%20%20%20xytext%3D(-2.2%2C%202)%2C%0A%20%20%20%20%20%20%20%20bbox%3Ddict(boxstyle%3D%22round%2Cpad%3D0.5%22%2C%20fc%3D%22white%22%2C%20ec%3D%22gray%22)%2C%0A%20%20%20%20%20%20%20%20arrowprops%3Ddict(arrowstyle%3D%22-%3E%22)%2C%0A%20%20%20%20)%0A%0A%20%20%20%20%23%20Add%20explanation%0A%20%20%20%20explanation%20%3D%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Visual%20Intuition%0A%0A%20%20%20%20In%20our%20sample%20space%20of%20100%20outcomes%3A%0A%0A%20%20%20%20-%20Event%20%24E%24%20occurs%20in%2040%20cases%20(red%20region%3A%2030%20%2B%2010)%0A%20%20%20%20-%20Event%20%24F%24%20occurs%20in%2030%20cases%20(green%20region%3A%2020%20%2B%2010)%0A%20%20%20%20-%20Both%20events%20occur%20together%20in%2010%20cases%20(overlap)%0A%20%20%20%20-%20Remaining%20cases%3A%2040%20(to%20complete%20sample%20space%20of%20100)%0A%0A%20%20%20%20When%20we%20condition%20on%20%24F%24%3A%0A%20%20%20%20%24%24P(E%20%5Cmid%20F)%20%3D%20%5Cfrac%7BP(E%20%5Ccap%20F)%7D%7BP(F)%7D%20%3D%20%5Cfrac%7B10%7D%7B30%7D%20%3D%20%5Cfrac%7B1%7D%7B3%7D%20%5Capprox%200.33%24%24%0A%0A%20%20%20%20This%20means%3A%20When%20we%20know%20%24F%24%20has%20occurred%20(restricting%20ourselves%20to%20the%20green%20region)%2C%0A%20%20%20%20the%20probability%20of%20%24E%24%20also%20occurring%20is%20%24%5Cfrac%7B1%7D%7B3%7D%24%20-%20as%2010%20out%20of%20the%2030%20cases%20in%20the%20%0A%20%20%20%20green%20region%20also%20belong%20to%20the%20red%20region.%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20mo.vstack(%5Bmo.center(plt.gcf())%2C%20explanation%5D)%0A%20%20%20%20return%20explanation%2C%20id%2C%20rect%2C%20v%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22Next%2C%20here's%20a%20function%20that%20computes%20%24P(E%20%5Cmid%20F)%24%2C%20given%20%24P(%20E%20%5Ccap%20F)%24%20and%20%24P(F)%24%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20conditional_probability(p_intersection%2C%20p_condition)%3A%0A%20%20%20%20%20%20%20%20if%20p_condition%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Cannot%20condition%20on%20an%20impossible%20event%22)%0A%20%20%20%20%20%20%20%20if%20p_intersection%20%3E%20p_condition%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22P(E%E2%88%A9F)%20cannot%20be%20greater%20than%20P(F)%22)%0A%0A%20%20%20%20%20%20%20%20return%20p_intersection%20%2F%20p_condition%0A%20%20%20%20return%20(conditional_probability%2C)%0A%0A%0A%40app.cell%0Adef%20_(conditional_probability)%3A%0A%20%20%20%20%23%20Example%201%3A%20Rolling%20a%20die%0A%20%20%20%20%23%20E%3A%20Rolling%20an%20even%20number%20(2%2C4%2C6)%0A%20%20%20%20%23%20F%3A%20Rolling%20a%20number%20greater%20than%203%20(4%2C5%2C6)%0A%20%20%20%20p_even_given_greater_than_3%20%3D%20conditional_probability(2%20%2F%206%2C%203%20%2F%206)%0A%20%20%20%20print(%22Example%201%3A%20Rolling%20a%20die%22)%0A%20%20%20%20print(f%22P(Even%20%7C%20%3E3)%20%3D%20%7Bp_even_given_greater_than_3%7D%22)%20%20%23%20Should%20be%202%2F3%0A%20%20%20%20return%20(p_even_given_greater_than_3%2C)%0A%0A%0A%40app.cell%0Adef%20_(conditional_probability)%3A%0A%20%20%20%20%23%20Example%202%3A%20Cards%0A%20%20%20%20%23%20E%3A%20Drawing%20a%20Heart%0A%20%20%20%20%23%20F%3A%20Drawing%20a%20Face%20card%20(J%2CQ%2CK)%0A%20%20%20%20p_heart_given_face%20%3D%20conditional_probability(3%20%2F%2052%2C%2012%20%2F%2052)%0A%20%20%20%20print(%22%5CnExample%202%3A%20Drawing%20cards%22)%0A%20%20%20%20print(f%22P(Heart%20%7C%20Face%20card)%20%3D%20%7Bp_heart_given_face%7D%22)%20%20%23%20Should%20be%201%2F4%0A%20%20%20%20return%20(p_heart_given_face%2C)%0A%0A%0A%40app.cell%0Adef%20_(conditional_probability)%3A%0A%20%20%20%20%23%20Example%203%3A%20Student%20grades%0A%20%20%20%20%23%20E%3A%20Getting%20an%20A%0A%20%20%20%20%23%20F%3A%20Studying%20more%20than%203%20hours%0A%20%20%20%20p_a_given_study%20%3D%20conditional_probability(0.24%2C%200.40)%0A%20%20%20%20print(%22%5CnExample%203%3A%20Student%20grades%22)%0A%20%20%20%20print(f%22P(A%20%7C%20Studied%20%3E3hrs)%20%3D%20%7Bp_a_given_study%7D%22)%20%20%23%20Should%20be%200.6%0A%20%20%20%20return%20(p_a_given_study%2C)%0A%0A%0A%40app.cell%0Adef%20_(conditional_probability)%3A%0A%20%20%20%20%23%20Example%204%3A%20Weather%0A%20%20%20%20%23%20E%3A%20Raining%0A%20%20%20%20%23%20F%3A%20Cloudy%0A%20%20%20%20p_rain_given_cloudy%20%3D%20conditional_probability(0.15%2C%200.30)%0A%20%20%20%20print(%22%5CnExample%204%3A%20Weather%22)%0A%20%20%20%20print(f%22P(Rain%20%7C%20Cloudy)%20%3D%20%7Bp_rain_given_cloudy%7D%22)%20%20%23%20Should%20be%200.5%0A%20%20%20%20return%20(p_rain_given_cloudy%2C)%0A%0A%0A%40app.cell%0Adef%20_(conditional_probability)%3A%0A%20%20%20%20%23%20Example%205%3A%20Error%20cases%0A%20%20%20%20print(%22%5CnExample%205%3A%20Error%20cases%22)%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%23%20Cannot%20condition%20on%20impossible%20event%0A%20%20%20%20%20%20%20%20conditional_probability(0.5%2C%200)%0A%20%20%20%20except%20ValueError%20as%20e%3A%0A%20%20%20%20%20%20%20%20print(f%22Error%201%3A%20%7Be%7D%22)%0A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%23%20Intersection%20cannot%20be%20larger%20than%20condition%0A%20%20%20%20%20%20%20%20conditional_probability(0.7%2C%200.5)%0A%20%20%20%20except%20ValueError%20as%20e%3A%0A%20%20%20%20%20%20%20%20print(f%22Error%202%3A%20%7Be%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20The%20Conditional%20Paradigm%0A%0A%20%20%20%20%20%20%20%20When%20we%20condition%20on%20an%20event%2C%20we%20enter%20a%20new%20probability%20universe.%20In%20this%20universe%3A%0A%0A%20%20%20%20%20%20%20%201.%20All%20probability%20axioms%20still%20hold%0A%20%20%20%20%20%20%20%202.%20We%20must%20consistently%20condition%20on%20the%20same%20event%0A%20%20%20%20%20%20%20%203.%20Our%20sample%20space%20becomes%20the%20conditioning%20event%0A%0A%20%20%20%20%20%20%20%20Here's%20how%20our%20familiar%20probability%20rules%20look%20when%20conditioned%20on%20event%20%24G%24%3A%0A%0A%20%20%20%20%20%20%20%20%7C%20Rule%20%7C%20Original%20%7C%20Conditioned%20on%20%24G%24%20%7C%0A%20%20%20%20%20%20%20%20%7C------%7C----------%7C-------------------%7C%0A%20%20%20%20%20%20%20%20%7C%20Axiom%201%20%7C%20%240%20%5Cleq%20P(E)%20%5Cleq%201%24%20%7C%20%240%20%5Cleq%20P(E%20%5Cmid%20G)%20%5Cleq%201%24%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Axiom%202%20%7C%20%24P(S)%20%3D%201%24%20%7C%20%24P(S%20%5Cmid%20G)%20%3D%201%24%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Axiom%203*%20%7C%20%24P(E%20%5Ccup%20F)%20%3D%20P(E)%20%2B%20P(F)%24%20%7C%20%24P(E%20%5Ccup%20F%20%5Cmid%20G)%20%3D%20P(E%20%5Cmid%20G)%20%2B%20P(F%20%5Cmid%20G)%24%20%7C%0A%20%20%20%20%20%20%20%20%7C%20Complement%20%7C%20%24P(E%5EC)%20%3D%201%20-%20P(E)%24%20%7C%20%24P(E%5EC%20%5Cmid%20G)%20%3D%201%20-%20P(E%20%5Cmid%20G)%24%20%7C%0A%0A%20%20%20%20%20%20%20%20*_For%20mutually%20exclusive%20events_%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Multiple%20Conditions%0A%0A%20%20%20%20%20%20%20%20We%20can%20condition%20on%20multiple%20events.%20The%20notation%20%24P(E%20%5Cmid%20F%2CG)%24%20means%20%22_the%20probability%20of%20%24E%24%20%0A%20%20%20%20%20%20%20%20occurring%2C%20given%20that%20both%20%24F%24%20and%20%24G%24%20have%20occurred._%22%0A%0A%20%20%20%20%20%20%20%20The%20conditional%20probability%20formula%20still%20holds%20in%20the%20universe%20where%20%24G%24%20has%20occurred%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(E%20%5Cmid%20F%2CG)%20%3D%20%5Cfrac%7BP(E%20%5Ccap%20F%20%5Cmid%20G)%7D%7BP(F%20%5Cmid%20G)%7D%24%24%0A%0A%20%20%20%20%20%20%20%20This%20is%20a%20powerful%20extension%20that%20allows%20us%20to%20update%20our%20probabilities%20as%20we%20receive%20%0A%20%20%20%20%20%20%20%20multiple%20pieces%20of%20information.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20multiple_conditional_probability(%0A%20%20%20%20%20%20%20%20p_intersection_all%2C%20p_intersection_conditions%2C%20p_condition%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Calculate%20P(E%7CF%2CG)%20%3D%20P(E%E2%88%A9F%7CG)%2FP(F%7CG)%20%3D%20P(E%E2%88%A9F%E2%88%A9G)%2FP(F%E2%88%A9G)%22%22%22%0A%20%20%20%20%20%20%20%20if%20p_condition%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Cannot%20condition%20on%20an%20impossible%20event%22)%0A%20%20%20%20%20%20%20%20if%20p_intersection_conditions%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22Cannot%20condition%20on%20an%20impossible%20combination%20of%20events%22%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20if%20p_intersection_all%20%3E%20p_intersection_conditions%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22P(E%E2%88%A9F%E2%88%A9G)%20cannot%20be%20greater%20than%20P(F%E2%88%A9G)%22)%0A%0A%20%20%20%20%20%20%20%20return%20p_intersection_all%20%2F%20p_intersection_conditions%0A%20%20%20%20return%20(multiple_conditional_probability%2C)%0A%0A%0A%40app.cell%0Adef%20_(multiple_conditional_probability)%3A%0A%20%20%20%20%23%20Example%3A%20College%20admissions%0A%20%20%20%20%23%20E%3A%20Getting%20admitted%0A%20%20%20%20%23%20F%3A%20High%20GPA%0A%20%20%20%20%23%20G%3A%20Good%20test%20scores%0A%0A%20%20%20%20%23%20P(E%E2%88%A9F%E2%88%A9G)%20%3D%20P(Admitted%20%E2%88%A9%20HighGPA%20%E2%88%A9%20GoodScore)%20%3D%200.15%0A%20%20%20%20%23%20P(F%E2%88%A9G)%20%3D%20P(HighGPA%20%E2%88%A9%20GoodScore)%20%3D%200.25%0A%0A%20%20%20%20p_admit_given_both%20%3D%20multiple_conditional_probability(0.15%2C%200.25%2C%200.25)%0A%20%20%20%20print(%22College%20Admissions%20Example%3A%22)%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20f%22P(Admitted%20%7C%20High%20GPA%2C%20Good%20Scores)%20%3D%20%7Bp_admit_given_both%7D%22%0A%20%20%20%20)%20%20%23%20Should%20be%200.6%0A%0A%20%20%20%20%23%20Error%20case%3A%20impossible%20condition%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20multiple_conditional_probability(0.3%2C%200.2%2C%200.2)%0A%20%20%20%20except%20ValueError%20as%20e%3A%0A%20%20%20%20%20%20%20%20print(f%22%5CnError%20case%3A%20%7Be%7D%22)%0A%20%20%20%20return%20(p_admit_given_both%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20%F0%9F%A4%94%20Test%20Your%20Understanding%0A%0A%20%20%20%20%20%20%20%20Which%20of%20these%20statements%20about%20conditional%20probability%20are%20true%3F%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3EKnowing%20F%20occurred%20always%20decreases%20the%20probability%20of%20E%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20False!%20Conditioning%20on%20F%20can%20either%20increase%20or%20decrease%20P(E)%2C%20depending%20on%20how%20E%20and%20F%20are%20related.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3EP(E%7CF)%20represents%20entering%20a%20new%20probability%20universe%20where%20F%20has%20occurred%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9C%85%20True!%20We%20restrict%20ourselves%20to%20only%20the%20outcomes%20where%20F%20occurred%2C%20making%20F%20our%20new%20sample%20space.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3EIf%20P(E%7CF)%20%3D%20P(E)%2C%20then%20E%20and%20F%20must%20be%20the%20same%20event%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20False!%20This%20actually%20means%20E%20and%20F%20are%20independent%20-%20knowing%20one%20doesn't%20affect%20the%20other.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3EP(E%7CF)%20can%20be%20calculated%20by%20dividing%20P(E%E2%88%A9F)%20by%20P(F)%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9C%85%20True!%20This%20is%20the%20fundamental%20definition%20of%20conditional%20probability.%0A%20%20%20%20%20%20%20%20%3C%2Fdetails%3E%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%23%20Summary%0A%0A%20%20%20%20%20%20%20%20You've%20learned%3A%0A%0A%20%20%20%20%20%20%20%20-%20How%20conditional%20probability%20updates%20our%20beliefs%20with%20new%20information%0A%20%20%20%20%20%20%20%20-%20The%20formula%20%24P(E%20%5Cmid%20F)%20%3D%20P(E%20%5Ccap%20F)%2FP(F)%24%20and%20its%20intuition%0A%20%20%20%20%20%20%20%20-%20How%20probability%20rules%20work%20in%20conditional%20universes%0A%20%20%20%20%20%20%20%20-%20How%20to%20handle%20multiple%20conditions%0A%0A%20%20%20%20%20%20%20%20In%20the%20next%20lesson%2C%20we'll%20explore%20**independence**%20-%20when%20knowing%20about%20one%20event%20%0A%20%20%20%20%20%20%20%20tells%20us%20nothing%20about%20another.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A</marimo-code></head>
<body>
<div id="root"></div>
</body>
</html>