marimo-learn / _site /probability /02_axioms.html
Haleshot's picture
relevant assets and workflow
1cce1df unverified
raw
history blame
14.4 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": {"dataframes": "rich", "cell_output": "above", "code_editor_font_size": 14, "theme": "light", "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": "medium"}' hidden></marimo-app-config>
<marimo-server-token data-token='123' hidden></marimo-server-token>
<title>02 axioms</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)%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%20Axioms%20of%20Probability%0A%0A%20%20%20%20%20%20%20%20Probability%20theory%20is%20built%20on%20three%20fundamental%20axioms%2C%20known%20as%20the%20%5BKolmogorov%20axioms%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FProbability_axioms).%20These%20axioms%20form%20%0A%20%20%20%20%20%20%20%20the%20mathematical%20foundation%20for%20all%20of%20probability%20theory%5B%3Csup%3E1%3C%2Fsup%3E%5D(https%3A%2F%2Fchrispiech.github.io%2FprobabilityForComputerScientists%2Fen%2Fpart1%2Fprobability).%0A%0A%20%20%20%20%20%20%20%20Let's%20explore%20each%20axiom%20and%20understand%20why%20they%20make%20intuitive%20sense%3A%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%20The%20Three%20Axioms%0A%0A%20%20%20%20%20%20%20%20%7C%20Axiom%20%7C%20Mathematical%20Form%20%7C%20Meaning%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%20**Axiom%201**%20%7C%20%240%20%5Cleq%20P(E)%20%5Cleq%201%24%20%7C%20All%20probabilities%20are%20between%200%20and%201%20%7C%0A%20%20%20%20%20%20%20%20%7C%20**Axiom%202**%20%7C%20%24P(S)%20%3D%201%24%20%7C%20The%20probability%20of%20the%20sample%20space%20is%201%20%7C%0A%20%20%20%20%20%20%20%20%7C%20**Axiom%203**%20%7C%20%24P(E%20%5Ccup%20F)%20%3D%20P(E)%20%2B%20P(F)%24%20%7C%20For%20mutually%20exclusive%20events%2C%20probabilities%20add%20%7C%0A%0A%20%20%20%20%20%20%20%20where%20the%20set%20%24S%24%20is%20the%20sample%20space%20(all%20possible%20outcomes)%2C%20and%20%24E%24%20and%20%24F%24%20are%20sets%20that%20represent%20events.%20The%20notation%20%24P(E)%24%20denotes%20the%20probability%20of%20%24E%24%2C%20which%20you%20can%20interpret%20as%20the%20chance%20that%20something%20happens.%20%24P(E)%20%3D%200%24%20means%20that%20the%20event%20cannot%20happen%2C%20while%20%24P(E)%20%3D%201%24%20means%20the%20event%20will%20happen%20no%20matter%20what%3B%20%24P(E)%20%3D%200.5%24%20means%20that%20%24E%24%20has%20a%2050%25%20chance%20of%20happening.%0A%0A%20%20%20%20%20%20%20%20For%20an%20example%2C%20when%20rolling%20a%20fair%20six-sided%20die%20once%2C%20the%20sample%20space%20%24S%24%20is%20the%20set%20of%20die%20faces%20%24%7B1%2C%202%2C%203%2C%204%2C%205%2C%206%7D%24%2C%20and%20there%20are%20many%20possible%20events%3B%20we'll%20see%20some%20examples%20below.%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%20Understanding%20Through%20Examples%0A%0A%20%20%20%20%20%20%20%20Let's%20explore%20these%20axioms%20using%20a%20simple%20experiment%3A%20rolling%20a%20fair%20six-sided%20die.%0A%20%20%20%20%20%20%20%20We'll%20use%20this%20to%20demonstrate%20why%20each%20axiom%20makes%20intuitive%20sense.%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_(event)%3A%0A%20%20%20%20event%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Create%20an%20interactive%20widget%20to%20explore%20different%20events%0A%0A%20%20%20%20event%20%3D%20mo.ui.dropdown(%0A%0A%20%20%20%20%20%20%20%20options%3D%5B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Rolling%20an%20even%20number%20(2%2C4%2C6)%22%2C%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Rolling%20an%20odd%20number%20(1%2C3%2C5)%22%2C%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Rolling%20a%20prime%20number%20(2%2C3%2C5)%22%2C%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Rolling%20less%20than%204%20(1%2C2%2C3)%22%2C%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Any%20possible%20roll%20(1%2C2%2C3%2C4%2C5%2C6)%22%2C%0A%0A%20%20%20%20%20%20%20%20%5D%2C%0A%0A%20%20%20%20%20%20%20%20value%3D%22Rolling%20an%20even%20number%20(2%2C4%2C6)%22%2C%0A%0A%20%20%20%20%20%20%20%20label%3D%22Select%20an%20event%22%0A%0A%20%20%20%20)%0A%20%20%20%20return%20(event%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(event%2C%20mo%2C%20np%2C%20plt)%3A%0A%20%20%20%20%23%20Define%20the%20probabilities%20for%20each%20event%0A%20%20%20%20event_map%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22Rolling%20an%20even%20number%20(2%2C4%2C6)%22%3A%20%5B2%2C%204%2C%206%5D%2C%0A%20%20%20%20%20%20%20%20%22Rolling%20an%20odd%20number%20(1%2C3%2C5)%22%3A%20%5B1%2C%203%2C%205%5D%2C%0A%20%20%20%20%20%20%20%20%22Rolling%20a%20prime%20number%20(2%2C3%2C5)%22%3A%20%5B2%2C%203%2C%205%5D%2C%0A%20%20%20%20%20%20%20%20%22Rolling%20less%20than%204%20(1%2C2%2C3)%22%3A%20%5B1%2C%202%2C%203%5D%2C%0A%20%20%20%20%20%20%20%20%22Any%20possible%20roll%20(1%2C2%2C3%2C4%2C5%2C6)%22%3A%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D%2C%0A%20%20%20%20%7D%0A%0A%20%20%20%20%23%20Get%20outcomes%20directly%20from%20the%20event%20value%0A%20%20%20%20outcomes%20%3D%20event_map%5Bevent.value%5D%0A%20%20%20%20prob%20%3D%20len(outcomes)%20%2F%206%0A%0A%20%20%20%20%23%20Visualize%20the%20probability%0A%20%20%20%20dice%20%3D%20np.arange(1%2C%207)%0A%20%20%20%20colors%20%3D%20%5B'%231f77b4'%20if%20d%20in%20outcomes%20else%20'%23d3d3d3'%20for%20d%20in%20dice%5D%0A%0A%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots(figsize%3D(8%2C%202))%0A%20%20%20%20ax.bar(dice%2C%20np.ones_like(dice)%2C%20color%3Dcolors)%0A%20%20%20%20ax.set_xticks(dice)%0A%20%20%20%20ax.set_yticks(%5B%5D)%0A%20%20%20%20ax.set_title(f%22P(Event)%20%3D%20%7Bprob%3A.2f%7D%22)%0A%0A%20%20%20%20%23%20Add%20explanation%0A%20%20%20%20explanation%20%3D%20mo.md(f%22%22%22%0A%20%20%20%20**Event**%3A%20%7Bevent.value%7D%0A%0A%20%20%20%20**Probability**%3A%20%7Bprob%3A.2f%7D%0A%0A%20%20%20%20**Favorable%20outcomes**%3A%20%7Boutcomes%7D%0A%0A%20%20%20%20This%20example%20demonstrates%3A%0A%0A%20%20%20%20-%20Axiom%201%3A%20The%20probability%20is%20between%200%20and%201%0A%0A%20%20%20%20-%20Axiom%202%3A%20For%20the%20sample%20space%2C%20P(S)%20%3D%201%0A%0A%20%20%20%20-%20Axiom%203%3A%20The%20probability%20is%20the%20sum%20of%20individual%20outcome%20probabilities%0A%20%20%20%20%22%22%22)%0A%0A%20%20%20%20mo.hstack(%5Bplt.gcf()%2C%20explanation%5D)%0A%20%20%20%20return%20ax%2C%20colors%2C%20dice%2C%20event_map%2C%20explanation%2C%20fig%2C%20outcomes%2C%20prob%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%20Why%20These%20Axioms%20Matter%0A%0A%20%20%20%20%20%20%20%20These%20axioms%20are%20more%20than%20just%20rules%20-%20they%20provide%20the%20foundation%20for%20all%20of%20probability%20theory%3A%0A%0A%20%20%20%20%20%20%20%201.%20**Non-negativity**%20(Axiom%201)%20makes%20intuitive%20sense%3A%20you%20can't%20have%20a%20negative%20number%20of%20occurrences%20%0A%20%20%20%20%20%20%20%20%20%20%20in%20any%20experiment.%0A%0A%20%20%20%20%20%20%20%202.%20**Normalization**%20(Axiom%202)%20ensures%20that%20something%20must%20happen%20-%20the%20total%20probability%20must%20be%201.%0A%0A%20%20%20%20%20%20%20%203.%20**Additivity**%20(Axiom%203)%20lets%20us%20build%20complex%20probabilities%20from%20simple%20ones%2C%20but%20only%20for%20events%20%0A%20%20%20%20%20%20%20%20%20%20%20that%20can't%20happen%20together%20(mutually%20exclusive%20events).%0A%0A%20%20%20%20%20%20%20%20From%20these%20simple%20rules%2C%20we%20can%20derive%20all%20the%20powerful%20tools%20of%20probability%20theory%20that%20are%20used%20in%20%0A%20%20%20%20%20%20%20%20statistics%2C%20machine%20learning%2C%20and%20other%20fields.%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%20Consider%20rolling%20two%20dice.%20Which%20of%20these%20statements%20follow%20from%20the%20axioms%3F%0A%0A%20%20%20%20%20%20%20%20%3Cdetails%3E%0A%20%20%20%20%20%20%20%20%3Csummary%3E1.%20P(sum%20is%2013)%20%3D%200%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9C%85%20Correct!%20This%20follows%20from%20Axiom%201.%20Since%20no%20combination%20of%20dice%20can%20sum%20to%2013%2C%20%0A%20%20%20%20%20%20%20%20the%20probability%20must%20be%20non-negative%20but%20can%20be%200.%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%3E2.%20P(sum%20is%207)%20%2B%20P(sum%20is%20not%207)%20%3D%201%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9C%85%20Correct!%20This%20follows%20from%20Axioms%202%20and%203.%20These%20events%20are%20mutually%20exclusive%20and%20cover%20%0A%20%20%20%20%20%20%20%20the%20entire%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%3E3.%20P(first%20die%20is%206%20or%20second%20die%20is%206)%20%3D%20P(first%20die%20is%206)%20%2B%20P(second%20die%20is%206)%3C%2Fsummary%3E%0A%0A%20%20%20%20%20%20%20%20%E2%9D%8C%20Incorrect!%20This%20doesn't%20follow%20from%20Axiom%203%20because%20the%20events%20are%20not%20mutually%20exclusive%20-%20%0A%20%20%20%20%20%20%20%20you%20could%20roll%20(6%2C6).%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%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20return%20np%2C%20plt%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>