Spaces:
Running
Running
<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, "dataframes": "rich", "theme": "light", "cell_output": "above", "default_width": "medium"}, "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": "compact"}' hidden></marimo-app-config> | |
<marimo-server-token data-token='123' hidden></marimo-server-token> | |
<title>05 independence</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 ; | |
} | |
#filename-input { | |
display: none ; | |
} | |
</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()%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%20%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Independence%20in%20Probability%20Theory%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%2Findependence%2F)%2C%20by%20Stanford%20professor%20Chris%20Piech._%0A%0A%20%20%20%20%20%20%20%20In%20probability%20theory%2C%20independence%20is%20a%20fundamental%20concept%20that%20helps%20us%20understand%20%0A%20%20%20%20%20%20%20%20when%20events%20don't%20influence%20each%20other.%20Two%20events%20are%20independent%20if%20knowing%20the%20%0A%20%20%20%20%20%20%20%20outcome%20of%20one%20event%20doesn't%20change%20our%20belief%20about%20the%20other%20event%20occurring.%0A%0A%20%20%20%20%20%20%20%20%23%23%20Definition%20of%20Independence%0A%0A%20%20%20%20%20%20%20%20Two%20events%20%24E%24%20and%20%24F%24%20are%20independent%20if%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(E%7CF)%20%3D%20P(E)%24%24%0A%0A%20%20%20%20%20%20%20%20This%20means%20that%20knowing%20%24F%24%20occurred%20doesn't%20change%20the%20probability%20of%20%24E%24%20occurring.%0A%0A%20%20%20%20%20%20%20%20%23%23%23%20_Alternative%20Definition_%0A%0A%20%20%20%20%20%20%20%20Using%20the%20chain%20rule%2C%20we%20can%20derive%20another%20equivalent%20definition%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(E%20%5Ccap%20F)%20%3D%20P(E)%20%5Ccdot%20P(F)%24%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%20Independence%20is%20Symmetric%0A%0A%20%20%20%20%20%20%20%20This%20property%20is%20symmetric%3A%20if%20%24E%24%20is%20independent%20of%20%24F%24%2C%20then%20%24F%24%20is%20independent%20of%20%24E%24.%20%0A%20%20%20%20%20%20%20%20We%20can%20prove%20this%20using%20Bayes'%20Theorem%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(E%7CF)%20%3D%20%5Cfrac%7BP(F%7CE)P(E)%7D%7BP(F)%7D%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20%5Cfrac%7BP(F)P(E)%7D%7BP(F)%7D%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20P(E)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%23%23%20Independence%20and%20Complements%0A%0A%20%20%20%20%20%20%20%20Given%20independent%20events%20%24A%24%20and%20%24B%24%2C%20we%20can%20prove%20that%20%24A%24%20and%20%24B%5EC%24%20are%20also%20independent%3A%0A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(AB%5EC)%20%3D%20P(A)%20-%20P(AB)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20P(A)%20-%20P(A)P(B)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20P(A)(1%20-%20P(B))%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20P(A)P(B%5EC)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%23%23%20Generalized%20Independence%0A%0A%20%20%20%20%20%20%20%20Events%20%24E_1%2C%20E_2%2C%20%5Cldots%2C%20E_n%24%20are%20independent%20if%20for%20every%20subset%20with%20%24r%24%20elements%20(where%20%24r%20%5Cleq%20n%24)%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(E_1%2C%20E_2%2C%20%5Cldots%2C%20E_r)%20%3D%20%5Cprod_%7Bi%3D1%7D%5Er%20P(E_i)%5C%5D%0A%0A%20%20%20%20%20%20%20%20For%20example%2C%20consider%20getting%205%20heads%20on%205%20coin%20flips.%20Let%20%24H_i%24%20be%20the%20event%20that%20the%20%24i%24th%20flip%20is%20heads%3A%0A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(H_1%2C%20H_2%2C%20H_3%2C%20H_4%2C%20H_5)%20%3D%20P(H_1)P(H_2)P(H_3)P(H_4)P(H_5)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20%5Cprod_%7Bi%3D1%7D%5E5%20P(H_i)%5C%5D%0A%0A%20%20%20%20%20%20%20%20%5C%5B%3D%20%5Cleft(%5Cfrac%7B1%7D%7B2%7D%5Cright)%5E5%20%3D%200.03125%5C%5D%0A%0A%20%20%20%20%20%20%20%20%23%23%20Conditional%20Independence%0A%0A%20%20%20%20%20%20%20%20Events%20%24E_1%2C%20E_2%2C%20E_3%24%20are%20conditionally%20independent%20given%20event%20%24F%24%20if%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(E_1%2C%20E_2%2C%20E_3%20%7C%20F)%20%3D%20P(E_1%7CF)P(E_2%7CF)P(E_3%7CF)%5C%5D%0A%0A%20%20%20%20%20%20%20%20This%20can%20be%20written%20more%20succinctly%20using%20product%20notation%3A%0A%0A%20%20%20%20%20%20%20%20%5C%5BP(E_1%2C%20E_2%2C%20E_3%20%7C%20F)%20%3D%20%5Cprod_%7Bi%3D1%7D%5E3%20P(E_i%7CF)%5C%5D%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%20callout_text%20%3D%20mo.md(r%22%22%22While%20the%20rules%20of%20probability%20stay%20the%20same%20when%20conditioning%20on%20an%20event%2C%20the%20independence%20%0A%20%20%20%20%20%20%20%20property%20between%20events%20might%20change.%20Events%20that%20were%20dependent%20can%20become%20independent%20when%20%0A%20%20%20%20%20%20%20%20conditioning%20on%20an%20event.%20Events%20that%20were%20independent%20can%20become%20dependent.%0A%0A%20%20%20%20%20%20%20%20For%20example%2C%20if%20events%20%24E_1%2C%20E_2%2C%20E_3%24%20are%20conditionally%20independent%20given%20event%20%24F%24%2C%20%0A%20%20%20%20%20%20%20%20it%20is%20not%20necessarily%20true%20that%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(E_1%2CE_2%2CE_3)%20%3D%20%5Cprod_%7Bi%3D1%7D%5E3%20P(E_i)%24%24%0A%0A%20%20%20%20%20%20%20%20as%20we%20are%20no%20longer%20conditioning%20on%20%24F%24.%0A%20%20%20%20%20%20%20%20%22%22%22)%0A%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20callout_text%2C%0A%20%20%20%20%20%20%20%20kind%3D%22warn%22%0A%20%20%20%20)%0A%20%20%20%20return%20(callout_text%2C)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20check_independence(p_e%2C%20p_f%2C%20p_intersection)%3A%0A%20%20%20%20%20%20%20%20expected%20%3D%20p_e%20*%20p_f%0A%20%20%20%20%20%20%20%20tolerance%20%3D%201e-5%20%20%23%20Stricter%20tolerance%20for%20comparison%0A%0A%20%20%20%20%20%20%20%20return%20abs(p_intersection%20-%20expected)%20%3C%20tolerance%0A%20%20%20%20return%20(check_independence%2C)%0A%0A%0A%40app.cell%0Adef%20_(check_independence%2C%20mo)%3A%0A%20%20%20%20%23%20Example%201%3A%20Rolling%20dice%0A%20%20%20%20p_first_even%20%3D%200.5%20%20%20%20%20%20%23%20P(First%20die%20is%20even)%0A%20%20%20%20p_second_six%20%3D%201%2F6%20%20%20%20%20%20%23%20P(Second%20die%20is%206)%0A%20%20%20%20p_both%20%3D%201%2F12%20%20%20%20%20%20%20%20%20%20%20%23%20P(First%20even%20AND%20second%20is%206)%0A%20%20%20%20dice_independent%20%3D%20check_independence(p_first_even%2C%20p_second_six%2C%20p_both)%0A%20%20%20%20example1%20%3D%20f%22%22%22%0A%20%20%20%20%23%23%23%23%201.%20Rolling%20Two%20Dice%20%F0%9F%8E%B2%0A%0A%20%20%20%20-%20P(First%20die%20is%20even)%20%3D%20%7Bp_first_even%3A.3f%7D%0A%20%20%20%20-%20P(Second%20die%20shows%206)%20%3D%20%7Bp_second_six%3A.3f%7D%0A%20%20%20%20-%20P(Both%20events%20occur)%20%3D%20%7Bp_both%3A.3f%7D%0A%0A%20%20%20%20**Result**%3A%20Events%20are%20%7B'independent'%20if%20dice_independent%20else%20'dependent'%7D%0A%0A%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%3Csummary%3EWhy%3F%3C%2Fsummary%3E%0A%20%20%20%20Rolling%20dice%20are%20independent%20events%20because%20the%20outcome%20of%20one%20die%20doesn't%20affect%20the%20other.%20%0A%20%20%20%20The%20probability%20of%20getting%20a%206%20on%20the%20second%20die%20(1%2F6)%20remains%20the%20same%20regardless%20of%20what%20shows%20on%20the%20first%20die.%20This%20is%20why%20P(Both)%20%3D%201%2F12%2C%20which%20equals%20P(First%20even)%20*%20P(Second%20is%206)%20%3D%200.5%20*%201%2F6.%0A%20%20%20%20%3C%2Fdetails%3E%0A%20%20%20%20%22%22%22%0A%20%20%20%20mo.md(example1)%0A%20%20%20%20return%20dice_independent%2C%20example1%2C%20p_both%2C%20p_first_even%2C%20p_second_six%0A%0A%0A%40app.cell%0Adef%20_(check_independence%2C%20mo)%3A%0A%20%20%20%20%23%20Example%202%3A%20Drawing%20cards%20(dependent%20events)%0A%20%20%20%20p_first_heart%20%3D%2013%2F52%20%20%20%20%23%20P(First%20card%20is%20heart)%0A%20%20%20%20p_second_heart%20%3D%2012%2F51%20%20%20%23%20P(Second%20card%20is%20heart%20%7C%20First%20was%20heart)%0A%0A%20%20%20%20%23%20For%20dependent%20events%2C%20P(A%E2%88%A9B)%20%3D%20P(A)%20*%20P(B%7CA)%0A%20%20%20%20p_both_hearts%20%3D%20(13%2F52)%20*%20(12%2F51)%20%20%23%20Joint%20probability%20%3D%200.059%0A%0A%20%20%20%20%23%20If%20events%20were%20independent%2C%20we'd%20expect%3A%0A%20%20%20%20theoretical_if_independent%20%3D%20(13%2F52)%20*%20(13%2F52)%20%20%23%20%3D%200.0625%0A%0A%20%20%20%20%23%20Test%20independence%20by%20comparing%20actual%20joint%20probability%20with%20theoretical%20independent%20probability%0A%20%20%20%20cards_independent%20%3D%20check_independence(13%2F52%2C%2013%2F52%2C%20p_both_hearts)%0A%0A%20%20%20%20example2%20%3D%20f%22%22%22%0A%20%20%20%20%23%23%23%23%202.%20Drawing%20Cards%20Without%20Replacement%20%E2%99%A5%EF%B8%8F%0A%20%20%20%20-%20P(First%20card%20is%20heart)%20%3D%20%7Bp_first_heart%3A.3f%7D%0A%20%20%20%20-%20P(Second%20card%20is%20heart%20%7C%20First%20was%20heart)%20%3D%20%7Bp_second_heart%3A.3f%7D%0A%20%20%20%20-%20P(Both%20cards%20are%20hearts)%20%3D%20%7Bp_both_hearts%3A.3f%7D%0A%20%20%20%20-%20If%20independent%2C%20P(Both%20hearts)%20would%20be%20%3D%20%7Btheoretical_if_independent%3A.3f%7D%0A%0A%20%20%20%20**Result**%3A%20Events%20are%20%7B'independent'%20if%20cards_independent%20else%20'dependent'%7D%0A%0A%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%3Csummary%3EWhy%3F%3C%2Fsummary%3E%0A%20%20%20%20Drawing%20cards%20without%20replacement%20makes%20events%20dependent.%20The%20probability%20of%20getting%20%0A%20%20%20%20a%20second%20heart%20(12%2F51%20%E2%89%88%200.235)%20is%20less%20than%20the%20first%20(13%2F52%20%3D%200.25)%20because%20there's%20one%20fewer%20heart%20available.%20This%20makes%20the%20actual%20probability%20of%20both%20hearts%20(0.059)%20less%20than%20what%20we'd%20%0A%20%20%20%20expect%20if%20the%20events%20were%20independent%20(0.063).%0A%20%20%20%20%3C%2Fdetails%3E%0A%20%20%20%20%22%22%22%0A%20%20%20%20mo.md(example2)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20cards_independent%2C%0A%20%20%20%20%20%20%20%20example2%2C%0A%20%20%20%20%20%20%20%20p_both_hearts%2C%0A%20%20%20%20%20%20%20%20p_first_heart%2C%0A%20%20%20%20%20%20%20%20p_second_heart%2C%0A%20%20%20%20%20%20%20%20theoretical_if_independent%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell%0Adef%20_(check_independence%2C%20mo)%3A%0A%20%20%20%20%23%20Example%203%3A%20Computer%20system%0A%20%20%20%20p_hardware%20%3D%200.02%20%20%20%20%20%20%20%23%20P(Hardware%20failure)%0A%20%20%20%20p_software%20%3D%200.03%20%20%20%20%20%20%20%23%20P(Software%20crash)%0A%20%20%20%20p_both_failure%20%3D%200.0006%20%23%20P(Both%20failures)%0A%20%20%20%20system_independent%20%3D%20check_independence(p_hardware%2C%20p_software%2C%20p_both_failure)%0A%20%20%20%20example3%20%3D%20f%22%22%22%0A%20%20%20%20%23%23%23%23%203.%20Computer%20System%20Failures%20%F0%9F%92%BB%0A%0A%20%20%20%20-%20P(Hardware%20failure)%20%3D%20%7Bp_hardware%3A.3f%7D%0A%20%20%20%20-%20P(Software%20crash)%20%3D%20%7Bp_software%3A.3f%7D%0A%20%20%20%20-%20P(Both%20failures%20occur)%20%3D%20%7Bp_both_failure%3A.3f%7D%0A%0A%20%20%20%20**Result**%3A%20Events%20are%20%7B'independent'%20if%20system_independent%20else%20'dependent'%7D%0A%0A%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%3Csummary%3EWhy%3F%3C%2Fsummary%3E%0A%20%20%20%20Computer%20hardware%20and%20software%20failures%20are%20typically%20independent%20because%20they%20often%20have%20different%20root%20causes.%20Hardware%20failures%20might%20be%20due%20to%20physical%20issues%20(heat%2C%20power)%2C%20while%20software%20crashes%20come%20from%20programming%20bugs.%20This%20is%20why%20P(Both)%20%3D%200.0006%2C%20which%20equals%20P(Hardware)%20*%20P(Software)%20%3D%200.02%20*%200.03.%0A%20%20%20%20%3C%2Fdetails%3E%0A%20%20%20%20%22%22%22%0A%20%20%20%20mo.md(example3)%0A%20%20%20%20return%20example3%2C%20p_both_failure%2C%20p_hardware%2C%20p_software%2C%20system_independent%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%20Establishing%20Independence%0A%0A%20%20%20%20%20%20%20%20In%20practice%2C%20we%20can%20establish%20independence%20through%3A%0A%0A%20%20%20%20%20%20%20%201.%20**Mathematical%20Verification**%3A%20Show%20that%20P(E%E2%88%A9F)%20%3D%20P(E)P(F)%0A%20%20%20%20%20%20%20%202.%20**Empirical%20Testing**%3A%20Analyze%20data%20to%20check%20if%20events%20appear%20independent%0A%20%20%20%20%20%20%20%203.%20**Domain%20Knowledge**%3A%20Use%20understanding%20of%20the%20system%20to%20justify%20independence%0A%0A%20%20%20%20%20%20%20%20%3E%20**Note**%3A%20Perfect%20independence%20is%20rare%20in%20real%20data.%20We%20often%20make%20independence%20assumptions%20%0A%20%20%20%20%20%20%20%20when%20dependencies%20are%20negligible%20and%20the%20simplification%20is%20useful.%0A%0A%20%20%20%20%20%20%20%20%23%23%20Backup%20Systems%20in%20Space%20Missions%0A%0A%20%20%20%20%20%20%20%20Consider%20a%20space%20mission%20with%20two%20backup%20life%20support%20systems%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(%5Ctext%7BPrimary%20fails%7D)%20%3D%20p_1%24%24%0A%0A%20%20%20%20%20%20%20%20%24%24P(%5Ctext%7BSecondary%20fails%7D)%20%3D%20p_2%24%24%0A%0A%20%20%20%20%20%20%20%20If%20the%20systems%20are%20truly%20independent%20(different%20power%20sources%2C%20separate%20locations%2C%20distinct%20technologies)%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(%5Ctext%7BLife%20support%20fails%7D)%20%3D%20p_1p_2%24%24%0A%0A%20%20%20%20%20%20%20%20For%20example%3A%0A%0A%20%20%20%20%20%20%20%20-%20If%20%24p_1%20%3D%200.01%24%20and%20%24p_2%20%3D%200.02%24%20(99%25%20and%2098%25%20reliable)%0A%20%20%20%20%20%20%20%20-%20Then%20%24P(%5Ctext%7BTotal%20failure%7D)%20%3D%200.0002%24%20(99.98%25%20reliable)%0A%0A%20%20%20%20%20%20%20%20However%2C%20if%20both%20systems%20share%20vulnerabilities%20(same%20radiation%20exposure%2C%20temperature%20extremes)%3A%0A%0A%20%20%20%20%20%20%20%20%24%24P(%5Ctext%7BLife%20support%20fails%7D)%20%3E%20p_1p_2%24%24%0A%0A%20%20%20%20%20%20%20%20This%20example%20shows%20why%20space%20agencies%20invest%20heavily%20in%20ensuring%20true%20independence%20of%20backup%20systems.%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(r%22%22%22%23%23%20Interactive%20Example%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(flip_button%2C%20mo%2C%20reset_button)%3A%0A%20%20%20%20mo.hstack(%5Bflip_button%2C%20reset_button%5D%2C%20justify%3D'center')%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20flip_button%20%3D%20mo.ui.run_button(label%3D%22Flip%20Coins!%22%2C%20kind%3D%22info%22)%0A%20%20%20%20reset_button%20%3D%20mo.ui.run_button(label%3D%22Reset%22%2C%20kind%3D%22danger%22)%0A%20%20%20%20stats_display%20%3D%20mo.md(%22*Click%20'Flip%20Coins!'%20to%20start%20simulation*%22)%0A%20%20%20%20return%20flip_button%2C%20reset_button%2C%20stats_display%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(flip_button%2C%20mo%2C%20np%2C%20reset_button)%3A%0A%20%20%20%20if%20reset_button.value%20or%20not%20flip_button.value%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.md(%22*Click%20'Flip%20Coins!'%20to%20start%20simulation*%22)%0A%20%20%20%20if%20flip_button.value%3A%0A%20%20%20%20%20%20%20%20coin1%20%3D%20%22H%22%20if%20np.random.random()%20%3C%200.5%20else%20%22T%22%0A%20%20%20%20%20%20%20%20coin2%20%3D%20%22H%22%20if%20np.random.random()%20%3C%200.5%20else%20%22T%22%0A%0A%20%20%20%20%20%20%20%20%23%20Calculate%20probabilities%20for%20this%20flip%0A%20%20%20%20%20%20%20%20p_h1%20%3D%201%20if%20coin1%20%3D%3D%20%22H%22%20else%200%0A%20%20%20%20%20%20%20%20p_h2%20%3D%201%20if%20coin2%20%3D%3D%20%22H%22%20else%200%0A%20%20%20%20%20%20%20%20p_both_h%20%3D%201%20if%20(coin1%20%3D%3D%20%22H%22%20and%20coin2%20%3D%3D%20%22H%22)%20else%200%0A%20%20%20%20%20%20%20%20p_product%20%3D%20p_h1%20*%20p_h2%0A%0A%20%20%20%20%20%20%20%20stats%20%3D%20f%22%22%22%0A%20%20%20%20%20%20%20%20%23%20Current%20Flip%20Results%0A%0A%20%20%20%20%20%20%20%20**Individual%20Probabilities%3A**%0A%0A%20%20%20%20%20%20%20%20-%20P(Heads%20on%20Coin%201)%20%3D%20%7Bp_h1%3A.3f%7D%0A%20%20%20%20%20%20%20%20-%20P(Heads%20on%20Coin%202)%20%3D%20%7Bp_h2%3A.3f%7D%0A%0A%20%20%20%20%20%20%20%20**Testing%20Independence%3A**%0A%0A%20%20%20%20%20%20%20%20-%20P(Both%20Heads)%20%3D%20%7Bp_both_h%3A.3f%7D%0A%20%20%20%20%20%20%20%20-%20P(H%E2%82%81)P(H%E2%82%82)%20%3D%20%7Bp_product%3A.3f%7D%0A%0A%20%20%20%20%20%20%20%20**Are%20they%20independent%3F**%0A%20%20%20%20%20%20%20%20The%20events%20appear%20%7B'independent'%20if%20abs(p_both_h%20-%20p_product)%20%3C%200.1%20else%20'dependent'%7D%0A%20%20%20%20%20%20%20%20(difference%3A%20%7Babs(p_both_h%20-%20p_product)%3A.3f%7D)%0A%0A%20%20%20%20%20%20%20%20**Current%20Flip%3A**%0A%0A%20%20%20%20%20%20%20%20%7C%20Coin%201%20%7C%20Coin%202%20%7C%0A%20%20%20%20%20%20%20%20%7C--------%7C--------%7C%0A%20%20%20%20%20%20%20%20%7C%20%7Bcoin1%7D%20%7C%20%7Bcoin2%7D%20%7C%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20stats%20%3D%20%22*Click%20'Flip%20Coins!'%20to%20start%20simulation*%22%0A%0A%20%20%20%20new_stats_display%20%3D%20mo.md(stats)%0A%20%20%20%20new_stats_display%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20coin1%2C%0A%20%20%20%20%20%20%20%20coin2%2C%0A%20%20%20%20%20%20%20%20new_stats_display%2C%0A%20%20%20%20%20%20%20%20p_both_h%2C%0A%20%20%20%20%20%20%20%20p_h1%2C%0A%20%20%20%20%20%20%20%20p_h2%2C%0A%20%20%20%20%20%20%20%20p_product%2C%0A%20%20%20%20%20%20%20%20stats%2C%0A%20%20%20%20)%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%20Understanding%20the%20Simulation%0A%0A%20%20%20%20%20%20%20%20This%20simulation%20demonstrates%20independence%20using%20coin%20flips%2C%20where%20each%20coin's%20outcome%20is%20unaffected%20by%20the%20other.%0A%0A%20%20%20%20%20%20%20%20%23%23%23%20Reading%20the%20Results%0A%0A%20%20%20%20%20%20%20%201.%20**Individual%20Probabilities%3A**%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20P(H%E2%82%81)%3A%201%20if%20heads%2C%200%20if%20tails%20on%20first%20coin%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20P(H%E2%82%82)%3A%201%20if%20heads%2C%200%20if%20tails%20on%20second%20coin%0A%0A%20%20%20%20%20%20%20%202.%20**Testing%20Independence%3A**%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20P(Both%20Heads)%3A%201%20if%20both%20show%20heads%2C%200%20otherwise%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20P(H%E2%82%81)P(H%E2%82%82)%3A%20Product%20of%20individual%20results%0A%0A%20%20%20%20%20%20%20%20%3E%20**Note**%3A%20Each%20click%20performs%20a%20new%20independent%20trial.%20While%20a%20single%20flip%20shows%20binary%20outcomes%20(0%20or%201)%2C%20%0A%20%20%20%20%20%20%20%20the%20theoretical%20probability%20is%200.5%20for%20each%20coin%20and%200.25%20for%20both%20heads.%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%20%F0%9F%A4%94%20Test%20Your%20Understanding%0A%0A%20%20%20%20%20%20%20%20Which%20of%20these%20statements%20about%20independence%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%3EIf%20P(E%7CF)%20%3D%20P(E)%2C%20then%20E%20and%20F%20are%20independent%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9C%85%20True!%20This%20is%20one%20definition%20of%20independence%20-%20knowing%20F%20occurred%20doesn't%20change%20the%20probability%20of%20E.%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%3EIndependent%20events%20cannot%20occur%20simultaneously%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20False!%20Independent%20events%20can%20and%20do%20occur%20together%20-%20their%20joint%20probability%20is%20just%20the%20product%20of%20their%20individual%20probabilities.%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%E2%88%A9F)%20%3D%20P(E)P(F)%2C%20then%20E%20and%20F%20are%20independent%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9C%85%20True!%20This%20is%20the%20multiplicative%20definition%20of%20independence.%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%3EIndependence%20is%20symmetric%3A%20if%20E%20is%20independent%20of%20F%2C%20then%20F%20is%20independent%20of%20E%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9C%85%20True!%20The%20definition%20P(E%E2%88%A9F)%20%3D%20P(E)P(F)%20is%20symmetric%20in%20E%20and%20F.%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%3EThree%20events%20being%20pairwise%20independent%20means%20they%20are%20mutually%20independent%3C%2Fsummary%3E%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20False!%20Pairwise%20independence%20doesn't%20guarantee%20mutual%20independence%20-%20we%20need%20to%20check%20all%20combinations.%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%20In%20this%20exploration%20of%20probability%20independence%2C%20we've%20discovered%20how%20to%20recognize%20when%20events%20truly%20don't%20influence%20each%20other.%20Through%20the%20lens%20of%20both%20mathematical%20definitions%20and%20interactive%20examples%2C%20we've%20seen%20how%20independence%20manifests%20in%20scenarios%20ranging%20from%20simple%20coin%20flips%20to%20critical%20system%20designs.%0A%0A%20%20%20%20%20%20%20%20The%20power%20of%20independence%20lies%20in%20its%20simplicity%3A%20when%20events%20are%20independent%2C%20we%20can%20multiply%20their%20individual%20probabilities%20to%20understand%20their%20joint%20behavior.%20Yet%2C%20as%20our%20examples%20showed%2C%20true%20independence%20is%20often%20more%20nuanced%20than%20it%20first%20appears.%20What%20seems%20independent%20might%20harbor%20hidden%20dependencies%2C%20and%20what%20appears%20dependent%20might%20be%20independent%20under%20certain%20conditions.%0A%0A%20%20%20%20%20%20%20%20_The%20art%20lies%20not%20just%20in%20calculating%20probabilities%2C%20but%20in%20developing%20the%20intuition%20to%20recognize%20independence%20in%20real-world%20scenarios%E2%80%94a%20skill%20essential%20for%20making%20informed%20decisions%20in%20uncertain%20situations._%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%20numpy%20as%20np%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20return%20np%2C%20pd%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> | |