 bondscell_results 5$9b92fc89-2036-4525-979b-d296ab29329cqueued¤logsrunning¦outputbody:<div class="markdown"><h1 id="Summary">Summary</h1>
</div>mimetext/htmlrootassigneelast_run_timestampA})B#persist_js_state·has_pluto_hook_features§cell_id$9b92fc89-2036-4525-979b-d296ab29329cdepends_on_disabled_cells§runtime #published_object_keysdepends_on_skipped_cells§errored$b305a905-06c2-4a15-8042-72ef6375720fqueued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})3persist_js_state·has_pluto_hook_features§cell_id$b305a905-06c2-4a15-8042-72ef6375720fdepends_on_disabled_cells§runtime
J:Dpublished_object_keysdepends_on_skipped_cells§errored$3e1b7d14-d294-11ef-0d10-1148a928dd57queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Marginalization">Marginalization</h2>
<p>Let <span class="tex">$A$</span> and <span class="tex">$B_1,B_2,\ldots,B_n$</span> be events, where <span class="tex">$B_1,B_2,\ldots,B_n$</span> partitions the universe. Then</p>
<p class="tex">$$\sum_&#123;i&#61;1&#125;^n p&#40;A,B_i&#41; &#61; p&#40;A&#41; \,.$$</p>
<p>This rule is called the <a href="https://en.wikipedia.org/wiki/Law_of_total_probability">law of total probability</a>. </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})8opersist_js_state·has_pluto_hook_features§cell_id$3e1b7d14-d294-11ef-0d10-1148a928dd57depends_on_disabled_cells§runtime 3opublished_object_keysdepends_on_skipped_cells§errored$5377c5a4-77c4-4fa7-9f84-0c511e3bf708queued¤logsrunning¦outputbody<details>
	<summary>Click to see proof</summary>
	<div class="details-content">
		<plutoui-detail><div class="markdown"><p class="tex">$$\begin&#123;align*&#125;
  \sum_i p&#40;A,B_i&#41; &amp;&#61; p\big&#40;\sum_i AB_i\big&#41;  &amp;&amp;\quad \text&#123;&#40;since all &#36;AB_i&#36; are disjoint&#41;&#125;\\
  &amp;&#61; p\big&#40;A,\sum_i B_i\big&#41; \\
  &amp;&#61; p&#40;A,\Omega&#41; &amp;&amp;\quad \text&#123;&#40;&#36;\Omega&#36; is true event, since &#36;B_i&#36; are exhaustive&#41;&#125; \\
  &amp;&#61; p&#40;A&#41;
  \end&#123;align*&#125;$$</p>
</div></plutoui-detail>
	</div>
</details>
<style type="text/css">
plutoui-detail {
	display: block;
	margin-block-end: var(--pluto-cell-spacing);
}

plutoui-detail:last-child {
	margin-block-end: 0;
}

pluto-output div.summary-title-outer {
	display: inline-flex;
	vertical-align: text-top;
	width: calc(100% - 1em);
	margin-left: -1em;
	padding-left: 1em;
}

pluto-output div.summary-title-outer > div.summary-title-inner {
	display: inline-block;
}
</style>

mimetext/htmlrootassigneelast_run_timestampA})	persist_js_state·has_pluto_hook_features§cell_id$5377c5a4-77c4-4fa7-9f84-0c511e3bf708depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$3e1b8bf4-d294-11ef-04cc-6364e46fdd64queued¤logsrunning¦outputbodyw<div class="markdown"><p>A very practical application of this law is to get rid of a variable that we are not interested in. For instance, if <span class="tex">$X$</span> and <span class="tex">$Y \in \&#123;y_1,y_2,\ldots,y_n\&#125;$</span> are discrete variables, then</p>
<p class="tex">$$p&#40;X&#41; &#61; \sum_&#123;i&#61;1&#125;^n p&#40;X,Y&#61;y_i&#41;\,.$$</p>
</div>mimetext/htmlrootassigneelast_run_timestampA}):`Jpersist_js_state·has_pluto_hook_features§cell_id$3e1b8bf4-d294-11ef-04cc-6364e46fdd64depends_on_disabled_cells§runtime ̵published_object_keysdepends_on_skipped_cells§errored$3e1de32c-d294-11ef-1f63-f190c8361404queued¤logsrunning¦outputbodyC<div class="markdown"><h5 id="Problem">Problem</h5>
<ul>
<li><p>A bag contains one ball, known to be either white or black. A white ball is put in , and the bag is shaken. Next, a ball is drawn out, which proves to be white. If we now take out another ball, what is the probability it will be white? </p>
</li>
</ul>
</div>mimetext/htmlrootassigneelast_run_timestampA})@Xpersist_js_state·has_pluto_hook_features§cell_id$3e1de32c-d294-11ef-1f63-f190c8361404depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$3e185ab0-d294-11ef-3f7d-9bd465518274queued¤logsrunning¦outputbody%<div class="markdown"><h5 id="Problem">Problem</h5>
<ul>
<li><p>Given is a disease with a prevalence of <bond def="prevalence" unique_id="zavbxcwzncaq"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.01</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.01)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.01)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond> and a test procedure with sensitivity &#40;&#39;true positive&#39; rate&#41; of <bond def="sensitivity" unique_id="amkygsvdhecm"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.95</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.95)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.95)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond>, and specificity &#40;&#39;true negative&#39; rate&#41; of <bond def="specificity" unique_id="ihwxzwilfvrj"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.85</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.85)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.85)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond>. What is the chance that somebody who tests positive actually has the disease?</p>
</li>
</ul>
<h5 id="Solution">Solution</h5>
<ul>
<li><p><a href="#Challenge-Revisited:-Disease-Diagnosis">Later in this lecture</a>, making use &#40;only&#41; of the sum and product rules of probability theory. </p>
</li>
</ul>
</div>mimetext/htmlrootassigneelast_run_timestampA})}Jpersist_js_state·has_pluto_hook_features§cell_id$3e185ab0-d294-11ef-3f7d-9bd465518274depends_on_disabled_cells§runtime w޵published_object_keysdepends_on_skipped_cells§errored$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4queued¤logsrunning¦outputbody<details>
	<summary>Click for the solution</summary>
	<div class="details-content">
		<plutoui-detail><div class="markdown"><p>There are two hypotheses: let <span class="tex">$H &#61; 0$</span> mean that the original ball in the bag was white and <span class="tex">$H &#61; 1$</span> that it was black. Assume the prior probabilities are equal, i.e.,</p>
<p class="tex">$$		P&#40;H &#61;0&#41; &#61; 1/2, \quad P&#40;H &#61;1&#41; &#61; 1/2 \,.$$</p>
<p>The data is that when a randomly selected ball was drawn from the bag, which contained a white one and the unknown one, it turned out to be white. The probability of this result according to each hypothesis is:</p>
<p class="tex">$$		P&#40;D|H &#61;0&#41; &#61; 1, \quad P&#40;D|H &#61;1&#41; &#61; 1/2 \,.$$</p>
<p>So by Bayes theorem, </p>
<p class="tex">$$\begin&#123;align&#125;
P&#40;H&#61;0|D&#41; &amp;&#61; \frac&#123;P&#40;H&#61;0,D&#41;&#125;&#123;P&#40;D&#41;&#125; \\
    &amp;&#61; \frac&#123;P&#40;D|H&#61;0&#41; P&#40;H&#61;0&#41;&#125;&#123;P&#40;D|H&#61;0&#41; P&#40;H&#61;0&#41; &#43; P&#40;D|H&#61;1&#41; P&#40;H&#61;1&#41;&#125; \\
    &amp;&#61; \frac&#123;1 \cdot \frac&#123;1&#125;&#123;2&#125;&#125;&#123;1 \cdot \frac&#123;1&#125;&#123;2&#125; &#43; \frac&#123;1&#125;&#123;2&#125; \cdot \frac&#123;1&#125;&#123;2&#125;&#125; \\
    &amp;&#61; \frac&#123;2&#125;&#123;3&#125; 
\end&#123;align&#125;$$</p>
<p>and consequently,  		</p>
<p class="tex">$$	P&#40;H &#61;1|D&#41; &#61; 1 - P&#40;H &#61;0|D&#41; &#61; \frac&#123;1&#125;&#123;3&#125;$$</p>
</div></plutoui-detail>
	</div>
</details>
<style type="text/css">
plutoui-detail {
	display: block;
	margin-block-end: var(--pluto-cell-spacing);
}

plutoui-detail:last-child {
	margin-block-end: 0;
}

pluto-output div.summary-title-outer {
	display: inline-flex;
	vertical-align: text-top;
	width: calc(100% - 1em);
	margin-left: -1em;
	padding-left: 1em;
}

pluto-output div.summary-title-outer > div.summary-title-inner {
	display: inline-block;
}
</style>

mimetext/htmlrootassigneelast_run_timestampA})persist_js_state·has_pluto_hook_features§cell_id$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4depends_on_disabled_cells§runtimeMpublished_object_keysdepends_on_skipped_cells§errored$4a81342c-17c7-4eb9-933b-edb98df7b9c4queued¤logsrunning¦outputbody"n (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampA})persist_js_state·has_pluto_hook_features§cell_id$4a81342c-17c7-4eb9-933b-edb98df7b9c4depends_on_disabled_cells§runtime{published_object_keysdepends_on_skipped_cells§errored$3e1bcb00-d294-11ef-2795-bd225bd00496queued¤logsrunning¦outputbodye<div class="markdown"><h2 id=""><span id='Bayes-rule'>Bayes Rule</span></h2>
<p>Consider two variables <span class="tex">$D$</span> and <span class="tex">$\theta$</span>. It follows from symmetry arguments that </p>
<p class="tex">$$p&#40;D,\theta&#41;&#61;p&#40;\theta,D&#41;\,,$$</p>
<p>and hence that</p>
<p class="tex">$$p&#40;D|\theta&#41;p&#40;\theta&#41;&#61;p&#40;\theta|D&#41;p&#40;D&#41;\,,$$</p>
<p>or equivalently,</p>
<p class="tex">$$ p&#40;\theta|D&#41; &#61; \frac&#123;p&#40;D|\theta&#41; &#125;&#123;p&#40;D&#41;&#125;p&#40;\theta&#41;\,.\qquad \text&#123;&#40;Bayes rule&#41;&#125;$$</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})#Ͱpersist_js_state·has_pluto_hook_features§cell_id$3e1bcb00-d294-11ef-2795-bd225bd00496depends_on_disabled_cells§runtime Ppublished_object_keysdepends_on_skipped_cells§errored$70d79732-0f55-40ba-929d-fba431318848queued¤logsrunning¦outputbodyl<div class="markdown"><h5 id="Disease-diagnosis-implementation">Disease diagnosis implementation</h5>
</div>mimetext/htmlrootassigneelast_run_timestampA})persist_js_state·has_pluto_hook_features§cell_id$70d79732-0f55-40ba-929d-fba431318848depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$922770f4-ddc8-4089-b378-f14088276b43queued¤logsrunning¦outputbody)<div class="markdown"><h2 id='Inference-Exercise:-Which-color-does-the-ball-have?' class="ptt-section " style="--ptt-accent: yellow;"><span>Inference Exercise:</span> Which color does the ball have?</h2>
	
<style>
.ptt-section::before {
	content: "";
	display: block;
	position: absolute;
	left: -25px;
	right: -6px;
	top: -4px;
	height: 200px;
	border: 4px solid salmon;
	border-bottom: none;
	border-image-source: linear-gradient(to bottom, var(--ptt-accent), transparent);
	border-image-slice: 1;
	opacity: .7;
	pointer-events: none;
}

.big.ptt-section::before {
	height: 500px;
}
	

.ptt-section > span {
	color: color-mix(in hwb, var(--ptt-accent) 60%, black);
	@media (prefers-color-scheme: dark) {
		color: color-mix(in hwb, var(--ptt-accent) 30%, white);
	}
	font-style: italic;
}

	
</style>

</div>mimetext/htmlrootassigneelast_run_timestampA})X?persist_js_state·has_pluto_hook_features§cell_id$922770f4-ddc8-4089-b378-f14088276b43depends_on_disabled_cells§runtimehpublished_object_keysdepends_on_skipped_cells§errored$3e027ede-4ac1-4521-a026-dc00bfca4adfqueued¤logsrunning¦outputbody<div class="markdown"><h2 id='Inference-Exercise:-Causality?' class="ptt-section " style="--ptt-accent: yellow;"><span>Inference Exercise:</span> Causality?</h2>
	
<style>
.ptt-section::before {
	content: "";
	display: block;
	position: absolute;
	left: -25px;
	right: -6px;
	top: -4px;
	height: 200px;
	border: 4px solid salmon;
	border-bottom: none;
	border-image-source: linear-gradient(to bottom, var(--ptt-accent), transparent);
	border-image-slice: 1;
	opacity: .7;
	pointer-events: none;
}

.big.ptt-section::before {
	height: 500px;
}
	

.ptt-section > span {
	color: color-mix(in hwb, var(--ptt-accent) 60%, black);
	@media (prefers-color-scheme: dark) {
		color: color-mix(in hwb, var(--ptt-accent) 30%, white);
	}
	font-style: italic;
}

	
</style>

</div>mimetext/htmlrootassigneelast_run_timestampA})&persist_js_state·has_pluto_hook_features§cell_id$3e027ede-4ac1-4521-a026-dc00bfca4adfdepends_on_disabled_cells§runtime!published_object_keysdepends_on_skipped_cells§errored$a66ab9df-897c-42e5-8b0f-c520ceaffa23queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})!persist_js_state·has_pluto_hook_features§cell_id$a66ab9df-897c-42e5-8b0f-c520ceaffa23depends_on_disabled_cells§runtime 囵published_object_keysdepends_on_skipped_cells§errored$ea803646-b18e-4f13-ab6a-fc5080d44e92queued¤logsrunning¦outputbody<div class="markdown"><h1 id='Challenge-Revisited:-Disease-Diagnosis' class="ptt-section " style="--ptt-accent: red;"><span>Challenge Revisited:</span> Disease Diagnosis</h1>
	
<style>
.ptt-section::before {
	content: "";
	display: block;
	position: absolute;
	left: -25px;
	right: -6px;
	top: -4px;
	height: 200px;
	border: 4px solid salmon;
	border-bottom: none;
	border-image-source: linear-gradient(to bottom, var(--ptt-accent), transparent);
	border-image-slice: 1;
	opacity: .7;
	pointer-events: none;
}

.big.ptt-section::before {
	height: 500px;
}
	

.ptt-section > span {
	color: color-mix(in hwb, var(--ptt-accent) 60%, black);
	@media (prefers-color-scheme: dark) {
		color: color-mix(in hwb, var(--ptt-accent) 30%, white);
	}
	font-style: italic;
}

	
</style>

</div>mimetext/htmlrootassigneelast_run_timestampA})!persist_js_state·has_pluto_hook_features§cell_id$ea803646-b18e-4f13-ab6a-fc5080d44e92depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$16c2eb59-16b8-4347-9aab-6e4b99016c79queued¤logsrunning¦outputbody<div class="markdown"><div class="admonition key-concept"><p class="admonition-title">🎯 Key concept</p><p><strong></strong></p>

<p>Bayes rule is the fundamental rule for learning from data&#33;</p>

</div>
</div>mimetext/htmlrootassigneelast_run_timestampA})rpersist_js_state·has_pluto_hook_features§cell_id$16c2eb59-16b8-4347-9aab-6e4b99016c79depends_on_disabled_cells§runtime $published_object_keysdepends_on_skipped_cells§errored$3e1e2b96-d294-11ef-3a68-fdc78232142equeued¤logsrunning¦outputbody<div class="markdown"><h5 id="Problem">Problem</h5>
<ul>
<li><p>A dark bag contains five red balls and seven green ones. </p>
<ul>
<li><p>&#40;a&#41; What is the probability of drawing a red ball on the first draw? </p>
</li>
</ul>
</li>
<li><p>Balls are not returned to the bag after each draw. </p>
<ul>
<li><p>&#40;b&#41; If you know that on the second draw the ball was a green one, what is now the probability of drawing a red ball on the first draw?</p>
</li>
</ul>
</li>
</ul>
</div>mimetext/htmlrootassigneelast_run_timestampA})Aۜpersist_js_state·has_pluto_hook_features§cell_id$3e1e2b96-d294-11ef-3a68-fdc78232142edepends_on_disabled_cells§runtime 	9published_object_keysdepends_on_skipped_cells§errored$b176ceae-884e-4460-9f66-020c1ac447f1queued¤logsrunning¦outputbody<<div class="markdown"><h1 id="Examples">Examples</h1>
</div>mimetext/htmlrootassigneelast_run_timestampA})?_persist_js_state·has_pluto_hook_features§cell_id$b176ceae-884e-4460-9f66-020c1ac447f1depends_on_disabled_cells§runtime Mpublished_object_keysdepends_on_skipped_cells§errored$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4queued¤logsrunning¦outputbody<div class="markdown"><p>In this case, knowledge about the future influences our state of knowledge about the present. Once again, we see that conditional probabilities capture implications for a state of knowledge, not temporal causality.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})BFpersist_js_state·has_pluto_hook_features§cell_id$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4depends_on_disabled_cells§runtime Gpublished_object_keysdepends_on_skipped_cells§errored$3e1ab104-d294-11ef-1a98-412946949fbaqueued¤logsrunning¦outputbodye<div class="markdown"><h1 id=""><span id='PT-calculus'>Probability Theory Calculus</span></h1>
</div>mimetext/htmlrootassigneelast_run_timestampA})Ѱpersist_js_state·has_pluto_hook_features§cell_id$3e1ab104-d294-11ef-1a98-412946949fbadepends_on_disabled_cells§runtimeNRpublished_object_keysdepends_on_skipped_cells§errored$fea8ae4c-8ef9-4b74-ad13-1314afef97dequeued¤logsrunning¦outputbody<div class="markdown"><h2 id="True-and-False-Events">True and False Events</h2>
<p>In probability theory, events that are certainly true or certainly false are treated as special cases of general events, and they correspond to probabilities of <span class="tex">$1$</span> and <span class="tex">$0$</span>, respectively.</p>
<p>Let <span class="tex">$\Omega$</span> be the sample space, i.e., the set of all possible outcomes of an experiment. Then:</p>
<ul>
<li><p>The true event corresponds to the entire sample space <span class="tex">$\Omega$</span>.</p>
</li>
<li><p>It always happens, regardless of the outcome.</p>
<ul>
<li><p>For example, for the outcome of a throw of a dice, the sample space is <span class="tex">$\Omega &#61; \&#123;1,2,3,4,5,6\&#125;$</span>.</p>
</li>
</ul>
</li>
<li><p>Its probability is</p>
</li>
</ul>
<p class="tex">$$p&#40;\Omega&#41; &#61; 1\,.$$</p>
<p>The false event corresponds to the empty set <span class="tex">$\emptyset$</span>.</p>
<ul>
<li><p>It never happens &#40;no possible outcomes&#41;.</p>
</li>
<li><p>Its probability is</p>
</li>
</ul>
<p class="tex">$$p&#40;\emptyset&#41; &#61; 0 \,.$$</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})6persist_js_state·has_pluto_hook_features§cell_id$fea8ae4c-8ef9-4b74-ad13-1314afef97dedepends_on_disabled_cells§runtime յpublished_object_keysdepends_on_skipped_cells§errored$3e18d2ea-d294-11ef-35e9-2332dd31dbf0queued¤logsrunning¦outputbody<div class="markdown"><p>Under these assumptions, Cox showed that any consistent system of reasoning about uncertainty must obey the <strong>rules of probability theory</strong> &#40;see <a href="https://en.wikipedia.org/wiki/Cox&#37;27s_theorem">Cox theorem, 1946</a>, and <a href="https://github.com/bmlip/course/blob/main/assets/files/Caticha-2012-Entropic-Inference-and-the-Foundations-of-Physics.pdf">Caticha, 2012</a>, pp.7-26&#41;. These rules are the sum and product rules.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})31persist_js_state·has_pluto_hook_features§cell_id$3e18d2ea-d294-11ef-35e9-2332dd31dbf0depends_on_disabled_cells§runtime uopublished_object_keysdepends_on_skipped_cells§errored$42b47af6-b850-4987-a2d7-805a2cb64e43queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})$persist_js_state·has_pluto_hook_features§cell_id$42b47af6-b850-4987-a2d7-805a2cb64e43depends_on_disabled_cells§runtimeiDpublished_object_keysdepends_on_skipped_cells§errored$3e1bdd02-d294-11ef-19e8-2f44eccf58afqueued¤logsrunning¦outputbody<div class="markdown"><p>This last formula is called <strong>Bayes rule</strong>, named after its inventor <a href="https://en.wikipedia.org/wiki/Thomas_Bayes">Thomas Bayes</a> &#40;1701-1761&#41;. While Bayes rule is always true, a particularly useful application occurs when <span class="tex">$D$</span> refers to an observed data set and <span class="tex">$\theta$</span> is set of unobserved model parameters. In that case,</p>
<ul>
<li><p>the <strong>prior</strong> probability <span class="tex">$p&#40;\theta&#41;$</span> represents our <strong>state-of-knowledge</strong> about proper values for <span class="tex">$\theta$</span>, before seeing the data <span class="tex">$D$</span>.</p>
</li>
<li><p>the <strong>posterior</strong> probability <span class="tex">$p&#40;\theta|D&#41;$</span> represents our state-of-knowledge about <span class="tex">$\theta$</span> after we have seen the data.</p>
</li>
</ul>
</div>mimetext/htmlrootassigneelast_run_timestampA})><persist_js_state·has_pluto_hook_features§cell_id$3e1bdd02-d294-11ef-19e8-2f44eccf58afdepends_on_disabled_cells§runtime 
published_object_keysdepends_on_skipped_cells§errored$5da42e9a-4318-48ea-9f43-4c1e1c97bcebqueued¤logsrunning¦outputbodyK<div>


<div class="key-concepts-repeat">
</div>

<script>
const wrapper = currentScript.parentElement
const repeat = wrapper.querySelector(".key-concepts-repeat")




	const render = () => {
		
	const nodes = [...document.querySelectorAll("div.key-concept")].filter(n => n.closest(".key-concepts-repeat") == null)
	
	repeat.innerHTML= ""
	nodes.forEach((n) => {
		const div = document.createElement("div")
		div.style = "position: relative;    margin-block-end: 2em;"
		
		const a = document.createElement("a")
		a.href = "#" + n.closest("pluto-cell").id
		a.innerText = "↑ Jump to source"
		a.style = `
			position: absolute;
		    box-shadow: 0 0 10px #0000001a;
		    font-family: system-ui;
		    font-weight: 600;
		    text-decoration: none;
		    display: inline-flex;
		    background: var(--white);
		    border-radius: 10rem;
		    padding: 0.2em 0.8em;
		    right: 5px;
		    top: 5.5px;
		`
		div.appendChild(a)
		div.appendChild(n.cloneNode(true))
		repeat.appendChild(div)
	})

	}








	// This mutationObserver code is from PlutoUI.TableOfContents. Check that code for the latest version with comments.
const invalidated = { current: false }
	const updateCallback = () => setTimeout(render, 1000)
	render()
updateCallback()
const notebook = wrapper.closest("pluto-notebook")
const mut_observers = { current: [] }
const createCellObservers = () => {
	mut_observers.current.forEach((o) => o.disconnect())
	mut_observers.current = Array.from(notebook.querySelectorAll("pluto-cell")).map(el => {
		const o = new MutationObserver(updateCallback)
		o.observe(el, {attributeFilter: ["class"]})
		return o
	})
}
createCellObservers()
const notebookObserver = new MutationObserver(() => {
	updateCallback()
	createCellObservers()
})
notebookObserver.observe(notebook, {childList: true})

const bodyClassObserver = new MutationObserver(updateCallback)
bodyClassObserver.observe(document.body, {attributeFilter: ["class"]})

invalidation.then(() => {
	invalidated.current = true
	notebookObserver.disconnect()
	bodyClassObserver.disconnect()
	mut_observers.current.forEach((o) => o.disconnect())
})
	
</script>

mimetext/htmlrootassigneelast_run_timestampA})5persist_js_state·has_pluto_hook_features§cell_id$5da42e9a-4318-48ea-9f43-4c1e1c97bcebdepends_on_disabled_cells§runtimeApublished_object_keysdepends_on_skipped_cells§errored$dd31ec7c-708d-4fd7-958d-f9887798a5bcqueued¤logsrunning¦outputbody4<div class="markdown"><h1 id="Code">Code</h1>
</div>mimetext/htmlrootassigneelast_run_timestampA})Fްpersist_js_state·has_pluto_hook_features§cell_id$dd31ec7c-708d-4fd7-958d-f9887798a5bcdepends_on_disabled_cells§runtime Xpublished_object_keysdepends_on_skipped_cells§errored$bbce1c6f-6f13-4449-9215-bd8ed839a44bqueued¤logsrunning¦outputbodyI<div class="bmlip-nextprev">


<a>
← Previous lecture

</a>


<a href='https://bertdv.github.io/mlss-2026/lectures/Bayesian%20Machine%20Learning.html'>
Next lecture →
</a>



</div>

<style>


.bmlip-nextprev {
	font-family: system-ui;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	
    justify-content: space-between;
	gap: 1em;
}

.bmlip-nextprev a {
	flex: 0 0 auto;
	border: 2px solid #8886;
	border-radius: .5em;
	padding: 1em;
	display: grid;
	height: 5em;
	place-items: center;
}

.bmlip-nextprev a:not([href]) {
	cursor: not-allowed;
	opacity: .5;
}


</style>

mimetext/htmlrootassigneelast_run_timestampA})9Jpersist_js_state·has_pluto_hook_features§cell_id$bbce1c6f-6f13-4449-9215-bd8ed839a44bdepends_on_disabled_cells§runtimempublished_object_keysdepends_on_skipped_cells§errored$4abbb3de-3b21-4c31-b015-e16c466a20aaqueued¤logsrunning¦outputbody<div class="markdown"><h2 id="The-Sum-and-Product-Rules">The Sum and Product Rules</h2>
<h5 id="The-sum-rule">The sum rule</h5>
<ul>
<li><p>The degree of belief in the disjunction of two events <span class="tex">$A$</span> and <span class="tex">$B$</span>, with given background information <span class="tex">$I$</span>, is evaluated as</p>
</li>
</ul>
<p class="tex">$$ p&#40;A&#43;B|I&#41; &#61; p&#40;A|I&#41; &#43; p&#40;B|I&#41; - p&#40;A,B|I&#41;$$</p>
<h5 id="The-product-rule">The product rule</h5>
<ul>
<li><p>The degree of belief in the conjunction of two events <span class="tex">$A$</span> and <span class="tex">$B$</span>, with given background information <span class="tex">$I$</span>, is evaluated as</p>
</li>
</ul>
<p class="tex">$$ p&#40;A,B|I&#41; &#61; p&#40;A|B,I&#41;\,p&#40;B|I&#41;$$</p>
<p>Cox’s Theorem derives the rules of probability theory from first principles, not as arbitrary postulates but as consequences of rational reasoning.  In other words: <strong>probability theory &#61; extended logic</strong>.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})5\persist_js_state·has_pluto_hook_features§cell_id$4abbb3de-3b21-4c31-b015-e16c466a20aadepends_on_disabled_cells§runtime 
PDpublished_object_keysdepends_on_skipped_cells§errored$3e1d33c8-d294-11ef-0a08-bdc419949925queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Probabilistic-Inference">Probabilistic Inference</h2>
<p><strong>Probabilistic inference</strong> refers to computing</p>
<p class="tex">$$p&#40;\,\text&#123;whatever-we-want-to-know&#125;\, | \,\text&#123;whatever-we-already-know&#125;\,&#41;$$</p>
<p>For example: </p>
<p class="tex">$$\begin&#123;align*&#125;
 p&#40;\,\text&#123;Mr.S.-killed-Mrs.S.&#125; \;&amp;|\; \text&#123;he-has-her-blood-on-his-shirt&#125;\,&#41; \\
 p&#40;\,\text&#123;transmitted-codeword&#125; \;&amp;|\;\text&#123;received-codeword&#125;\,&#41; 
  \end&#123;align*&#125;$$</p>
<p>This can be accomplished by repeatedly applying the sum and product rules.</p>
<p>In particular, consider a joint distribution <span class="tex">$p&#40;X,Y,Z&#41;$</span>. Assume we are interested in <span class="tex">$p&#40;X|Z&#41;$</span>:</p>
<p class="tex">$$\begin&#123;align*&#125;
p&#40;X|Z&#41; \stackrel&#123;p&#125;&#123;&#61;&#125; \frac&#123;p&#40;X,Z&#41;&#125;&#123;p&#40;Z&#41;&#125; \stackrel&#123;s&#125;&#123;&#61;&#125; \frac&#123;\sum_Y p&#40;X,Y,Z&#41;&#125;&#123;\sum_&#123;X,Y&#125; p&#40;X,Y,Z&#41;&#125; \,,
\end&#123;align*&#125;$$</p>
<p>where the <span class="tex">$s$</span> and <span class="tex">$p$</span> above the equality sign indicate whether the sum or product rule was used. </p>
<p>In the rest of this course, we&#39;ll encounter many lengthy probabilistic derivations. For each manipulation, you should be able to associate an &#39;s&#39; &#40;for sum rule&#41;, a &#39;p&#39; &#40;for product or Bayes rule&#41; or an &#39;m&#39; &#40;for a simplifying model assumption like conditional independency&#41; above any equality sign.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})?_persist_js_state·has_pluto_hook_features§cell_id$3e1d33c8-d294-11ef-0a08-bdc419949925depends_on_disabled_cells§runtime Ipublished_object_keysdepends_on_skipped_cells§errored$4f6dd225-c64d-4b76-b075-0bf71c863b5aqueued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})L%Spersist_js_state·has_pluto_hook_features§cell_id$4f6dd225-c64d-4b76-b075-0bf71c863b5adepends_on_disabled_cells§runtimeUpublished_object_keysdepends_on_skipped_cells§errored$a8046381-ff11-40af-ae2b-078d71c586e7queued¤logsrunning¦outputbody0.060126582278481mimetext/plainrootassigneeresultlast_run_timestampA})얈Upersist_js_state·has_pluto_hook_features§cell_id$a8046381-ff11-40af-ae2b-078d71c586e7depends_on_disabled_cells§runtimeppublished_object_keysdepends_on_skipped_cells§errored$3e18c25c-d294-11ef-11bc-a93c2572b107queued¤logsrunning¦outputbody<div class="markdown"><p>In developing this calculus, only some very agreeable assumptions were made, including:</p>
<ul>
<li><p>Degrees of belief are represented by real numbers.</p>
</li>
<li><p>Plausibility assessments are consistent, e.g.,</p>
<ul>
<li><p>if <span class="tex">$A$</span> becomes more plausible under new information <span class="tex">$B$</span>, the assigned degree-of-belief should increase accordingly.</p>
</li>
<li><p>If the belief in <span class="tex">$A$</span> is greater than the belief in <span class="tex">$B$</span>, and the belief in <span class="tex">$B$</span> is greater than the belief in <span class="tex">$C$</span>, then the belief in <span class="tex">$A$</span> must be greater than the belief in <span class="tex">$C$</span>.</p>
</li>
</ul>
</li>
<li><p>Logical equivalences are preserved, e.g., </p>
<ul>
<li><p>If the belief in an event can be inferred in two different ways, for example, either by first updating on information <span class="tex">$I_1$</span> and then <span class="tex">$I_2$</span> or the other way around, then the two ways must agree on the resulting belief.</p>
</li>
</ul>
</li>
</ul>
</div>mimetext/htmlrootassigneelast_run_timestampA}),&persist_js_state·has_pluto_hook_features§cell_id$3e18c25c-d294-11ef-11bc-a93c2572b107depends_on_disabled_cells§runtime %}published_object_keysdepends_on_skipped_cells§errored$3e1b05ee-d294-11ef-33de-efed64d01c0dqueued¤logsrunning¦outputbody<div class="markdown"><div class="admonition key-concept"><p class="admonition-title">🎯 Key concept</p><p><strong></strong></p>

<p>All valid probabilistic relations can be derived from just two fundamental principles: the <strong>sum rule</strong> and the <strong>product rule</strong>. These two rules form the foundation of probability theory, from which more complex constructs such as conditional probabilities, Bayes’ theorem, and marginalization naturally follow.</p>

</div>
</div>mimetext/htmlrootassigneelast_run_timestampA})߰persist_js_state·has_pluto_hook_features§cell_id$3e1b05ee-d294-11ef-33de-efed64d01c0ddepends_on_disabled_cells§runtime Dpublished_object_keysdepends_on_skipped_cells§errored$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafqueued¤logsrunning¦outputbody|<div class="markdown"><h1 id="Probability-Theory-as-Rational-Reasoning">Probability Theory as Rational Reasoning</h1>
</div>mimetext/htmlrootassigneelast_run_timestampA})persist_js_state·has_pluto_hook_features§cell_id$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafdepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$2156f96e-eebe-4190-8ce9-c76825c6da71queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})-^persist_js_state·has_pluto_hook_features§cell_id$2156f96e-eebe-4190-8ce9-c76825c6da71depends_on_disabled_cells§runtimeγq%published_object_keysdepends_on_skipped_cells§errored$3e1bf116-d294-11ef-148b-f7a1ca3f3badqueued¤logsrunning¦outputbodyو<div class="markdown"><p>Bayes rule tells us how to update our knowledge about model parameters when facing new data. Hence, </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})>ύpersist_js_state·has_pluto_hook_features§cell_id$3e1bf116-d294-11ef-148b-f7a1ca3f3baddepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0queued¤logsrunning¦outputbodyX<div class="markdown"><p>Summing <span class="tex">$Y$</span> out of a joint distribution <span class="tex">$p&#40;X,Y&#41;$</span> is called <strong>marginalization</strong> and the result <span class="tex">$p&#40;X&#41;$</span> is sometimes referred to as the <strong>marginal probability</strong> of <span class="tex">$X$</span>. </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})= persist_js_state·has_pluto_hook_features§cell_id$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0depends_on_disabled_cells§runtime :published_object_keysdepends_on_skipped_cells§errored$3e1889b8-d294-11ef-17bb-496655fbd618queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Probability-as-a-Degree-of-Belief">Probability as a Degree-of-Belief</h2>
<p>In the real world, we are rarely completely certain about anything. Rather than assigning a binary truth value to a proposition <span class="tex">$A$</span>, we associate it with a degree of belief </p>
<p class="tex">$$0 \leq p&#40;A&#41; \leq 1 \,,$$</p>
<p>which quantifies how likely we believe <span class="tex">$A$</span> is to be true.</p>
<p>Consider the truth value of the proposition </p>
<p class="tex">$$A &#61; \texttt&#123;&#96;&#96;there is life on Mars&#39;&#39;&#125;$$</p>
<p>with </p>
<p class="tex">$$I &#61; \texttt&#123;&#96;&#96;All known life forms require water&#39;&#39;&#125;$$</p>
<p>as background information. Now, assume that a new piece of information </p>
<p class="tex">$$B &#61; \texttt&#123;&#96;&#96;There is water on Mars&#39;&#39;&#125;$$</p>
<p>becomes available, how <strong>should</strong> our degree of belief in event <span class="tex">$A$</span> be affected <em>if we were rational</em>? </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})*Tpersist_js_state·has_pluto_hook_features§cell_id$3e1889b8-d294-11ef-17bb-496655fbd618depends_on_disabled_cells§runtime ֵpublished_object_keysdepends_on_skipped_cells§errored$3e17df5e-d294-11ef-38c7-f573724871d8queued¤logsrunning¦outputbody<secret-h1 style="
font-size: 3rem; 
border-bottom: none; 
text-shadow: -3px 3px #a2d4ff5c;
font-family: 'Vollkorn', Palatino, Georgia, serif;
color: var(--pluto-output-h-color);
font-weight: 700;
">Probability Theory Review</secret-sh1>mimetext/htmlrootassigneelast_run_timestampA})ة persist_js_state·has_pluto_hook_features§cell_id$3e17df5e-d294-11ef-38c7-f573724871d8depends_on_disabled_cells§runtimeVpublished_object_keysdepends_on_skipped_cells§errored$ff9142ba-3a85-48cf-8b78-07e0b554e280queued¤logsrunning¦outputbody<div class="markdown"><p>Note that the physical state of the bag—either containing one black ball or one white ball—remains unchanged after the “put one in, take one out” procedure. Yet, the probability we assign to the color of the ball in the bag changes. This illustrates a key point: probabilities describe a person’s state of knowledge, not an intrinsic property of nature.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})A9*persist_js_state·has_pluto_hook_features§cell_id$ff9142ba-3a85-48cf-8b78-07e0b554e280depends_on_disabled_cells§runtime apublished_object_keysdepends_on_skipped_cells§errored$61713e1c-8e37-45d9-9f58-c3db69e15b66queued¤logsrunning¦outputbody<div class="markdown"><h1 id='Challenge:-Disease-Diagnosis' class="ptt-section " style="--ptt-accent: red;"><span>Challenge:</span> Disease Diagnosis</h1>
	
<style>
.ptt-section::before {
	content: "";
	display: block;
	position: absolute;
	left: -25px;
	right: -6px;
	top: -4px;
	height: 200px;
	border: 4px solid salmon;
	border-bottom: none;
	border-image-source: linear-gradient(to bottom, var(--ptt-accent), transparent);
	border-image-slice: 1;
	opacity: .7;
	pointer-events: none;
}

.big.ptt-section::before {
	height: 500px;
}
	

.ptt-section > span {
	color: color-mix(in hwb, var(--ptt-accent) 60%, black);
	@media (prefers-color-scheme: dark) {
		color: color-mix(in hwb, var(--ptt-accent) 30%, white);
	}
	font-style: italic;
}

	
</style>

</div>mimetext/htmlrootassigneelast_run_timestampA})persist_js_state·has_pluto_hook_features§cell_id$61713e1c-8e37-45d9-9f58-c3db69e15b66depends_on_disabled_cells§runtime'hApublished_object_keysdepends_on_skipped_cells§errored$41bee964-a0a9-4a7f-8505-54a9ee12ef0dqueued¤logsrunning¦outputbody	<div class="markdown"><h2 id="Propositional-&#40;Boolean&#41;-Logic">Propositional &#40;Boolean&#41; Logic</h2>
<p>Define an <strong>event</strong> &#40;or &quot;proposition&quot;&#41; <span class="tex">$A$</span> as a statement that can be considered for its truth by a person. For instance, </p>
<p class="tex">$$𝐴&#61; \texttt&#123;&#96;&#96;there is life on Mars&#39;&#39;&#125;$$</p>
<p>Boolean logic &#40;or propositional logic&#41; is a formal system of logic based on binary truth values: every proposition is either true &#40;with assigned value <span class="tex">$1$</span>&#41; or false &#40;with assigned value <span class="tex">$0$</span>&#41;. It is named after George Boole, who developed the algebraic formulation of logic in the mid-19th century.</p>
<p>With Boolean operators &#40;<span class="tex">$\lor$</span>, <span class="tex">$\land$</span>, <span class="tex">$\implies$</span>, etc.&#41;, we can create and evaluate compound propositions, e.g.,</p>
<ul>
<li><p>Given two events <span class="tex">$A$</span> and <span class="tex">$B$</span>, the <strong>conjunction</strong> &#40;logical-and&#41; </p>
</li>
</ul>
<p class="tex">$$A \land B$$</p>
<p>is true if-and-only-if both <span class="tex">$A$</span> and <span class="tex">$B$</span> are true. We write <span class="tex">$A \land B$</span> also shortly as <span class="tex">$AB$</span> &#40;or use a comma as in a joint probability distribution <span class="tex">$p&#40;A,B&#41;$</span>&#41;. </p>
<ul>
<li><p>The <strong>disjunction</strong> &#40;logical-or&#41; </p>
</li>
</ul>
<p class="tex">$$A \lor B$$</p>
<p>is true if either <span class="tex">$A$</span> or <span class="tex">$B$</span> is true or both <span class="tex">$A$</span> and <span class="tex">$B$</span> are true. We write <span class="tex">$A \lor B$</span> also as <span class="tex">$A &#43; B$</span> &#40;Note that the plus-sign is here not an arithmetic operator, but rather a logical operator to process truth values.&#41;</p>
<ul>
<li><p>The denial of <span class="tex">$A$</span>, i.e., the event <strong>not</strong>-A, is written as </p>
</li>
</ul>
<p class="tex">$$\bar&#123;A&#125;\,.$$</p>
<p>Boolean logic provides the rules of inference for <strong>deductive reasoning</strong> and underpins all formal reasoning systems in mathematics and philosophy. </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})Ppersist_js_state·has_pluto_hook_features§cell_id$41bee964-a0a9-4a7f-8505-54a9ee12ef0ddepends_on_disabled_cells§runtime Pfpublished_object_keysdepends_on_skipped_cells§errored$3e1d6d00-d294-11ef-1081-e11b8397eb91queued¤logsrunning¦outputbody%<div class="markdown"><h5 id="Problem">Problem</h5>
<ul>
<li><p>Given a disease <span class="tex">$D \in \&#123;0, 1\&#125;$</span> with prevalence &#40;overall occurence percentage&#41; of <bond def="prevalence" unique_id="zavbxcwzncaq"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.01</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.01)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.01)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond> and a test procedure <span class="tex">$T  \in \&#123;0, 1\&#125;$</span> with sensitivity &#40;true positive rate&#41; of <bond def="sensitivity" unique_id="amkygsvdhecm"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.95</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.95)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.95)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond> and specificity &#40;true negative&#39; rate&#41; of <bond def="specificity" unique_id="ihwxzwilfvrj"><script>
			// weird import to make it faster. The `await import` can still delay execution by one frame if it is already loaded...
			window.d3format = window.d3format ?? await import("https://cdn.jsdelivr.net/npm/d3-format@2/+esm")

			const argmin = xs => xs.indexOf(Math.min(...xs))
			const closest_index = (xs, y) => argmin(xs.map(x => Math.abs(x-y)))

			const values = [0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6, 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7, 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8, 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9, 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1.0]

			const el = html`
			<span title="Click and drag this number left or right!" style="cursor: col-resize;
			touch-action: none;
			background: rgb(252, 209, 204);
			color: black;
			padding: 0em .2em;
			border-radius: .3em;
			font-weight: bold;
			font-family: system-ui, sans-serif;
    		font-variant-numeric: tabular-nums;
			">0.85</span>
			`



			let old_x = 0
			let old_index = 0
			const initial_index = closest_index(values, 0.85)
			let current_index = initial_index

			const formatter = s => "" + d3format.format(".0%")(s) + ""


			Object.defineProperty(el, 'value', {
				get: () => values[current_index],
				set: x => {
					current_index = closest_index(values, x)
					el.innerText = formatter(el.value)
				},
				configurable: true,
			});

			// initial value
			el.innerText = formatter(0.85)

			const onScrub = (e) => {
				const offset = e.clientX - old_x
				const new_index = Math.min(values.length-1, Math.max(0, 
					Math.round(offset/10) + old_index
				))

				if(new_index !== current_index) {
					current_index = new_index
					el.innerText = formatter(el.value)
					el.dispatchEvent(new CustomEvent("input"))
				}
			}

			const onpointerdown = (e) => {
				window.getSelection().empty()
				old_x = e.clientX
				old_index = current_index
				window.addEventListener("pointermove", onScrub)
			}
			el.addEventListener("pointerdown", onpointerdown)

			const ondblclick = (e) => {
				current_index = initial_index
				el.innerText = formatter(el.value)
				el.dispatchEvent(new CustomEvent("input"))
			}
			el.addEventListener("dblclick", ondblclick)

			const onpointerup = () => {
				window.removeEventListener("pointermove", onScrub)
			}
			window.addEventListener("pointerup", onpointerup)

			el.onselectstart = () => false

			invalidation.then(() => {
				el.removeEventListener("pointerdown", onpointerdown)
				el.removeEventListener("dblclick", ondblclick)
				window.removeEventListener("pointerup", onpointerup)
			})

			return el

			</script></bond>, what is the chance that somebody who tests positive actually has the disease?</p>
</li>
</ul>
<p><em>The percentages are interactive&#33; <strong>Click and drag</strong> to change the values.</em></p>
</div>mimetext/htmlrootassigneelast_run_timestampA})Ppersist_js_state·has_pluto_hook_features§cell_id$3e1d6d00-d294-11ef-1081-e11b8397eb91depends_on_disabled_cells§runtimeApublished_object_keysdepends_on_skipped_cells§errored$bcb4be20-0439-4809-a166-8c50b6b9206bqueued¤logsrunning¦outputbodyP<script>
	
// Load the library for consistent smooth scrolling
const {default: scrollIntoView} = await import("data:text/javascript;base64,dmFyIFE9ZT0+Im9iamVjdCI9PXR5cGVvZiBlJiZudWxsIT1lJiYxPT09ZS5ub2RlVHlwZSxVPShlLHQpPT4oIXR8fCJoaWRkZW4iIT09ZSkmJiJ2aXNpYmxlIiE9PWUmJiJjbGlwIiE9PWUsQT0oZSx0KT0+e2lmKGUuY2xpZW50SGVpZ2h0PGUuc2Nyb2xsSGVpZ2h0fHxlLmNsaWVudFdpZHRoPGUuc2Nyb2xsV2lkdGgpe2xldCBsPWdldENvbXB1dGVkU3R5bGUoZSxudWxsKTtyZXR1cm4gVShsLm92ZXJmbG93WSx0KXx8VShsLm92ZXJmbG93WCx0KXx8KGU9PntsZXQgdD0oZT0+e2lmKCFlLm93bmVyRG9jdW1lbnR8fCFlLm93bmVyRG9jdW1lbnQuZGVmYXVsdFZpZXcpcmV0dXJuIG51bGw7dHJ5e3JldHVybiBlLm93bmVyRG9jdW1lbnQuZGVmYXVsdFZpZXcuZnJhbWVFbGVtZW50fWNhdGNoe3JldHVybiBudWxsfX0pKGUpO3JldHVybiEhdCYmKHQuY2xpZW50SGVpZ2h0PGUuc2Nyb2xsSGVpZ2h0fHx0LmNsaWVudFdpZHRoPGUuc2Nyb2xsV2lkdGgpfSkoZSl9cmV0dXJuITF9LFg9KGUsdCxsLG8sbixyLGkscyk9PnI8ZSYmaT50fHxyPmUmJmk8dD8wOnI8PWUmJnM8PWx8fGk+PXQmJnM+PWw/ci1lLW86aT50JiZzPGx8fHI8ZSYmcz5sP2ktdCtuOjAsJD1lPT5lLnBhcmVudEVsZW1lbnQ/PyhlLmdldFJvb3ROb2RlKCkuaG9zdHx8bnVsbCksdHQ9KGUsdCk9Pnt2YXIgbCxvLG4scjtpZih0eXBlb2YgZG9jdW1lbnQ+InUiKXJldHVybltdO2xldHtzY3JvbGxNb2RlOmksYmxvY2s6cyxpbmxpbmU6YSxib3VuZGFyeTpoLHNraXBPdmVyZmxvd0hpZGRlbkVsZW1lbnRzOnV9PXQsZz0iZnVuY3Rpb24iPT10eXBlb2YgaD9oOmU9PmUhPT1oO2lmKCFRKGUpKXRocm93IFR5cGVFcnJvcigiSW52YWxpZCB0YXJnZXQiKTtsZXQgdj1kb2N1bWVudC5zY3JvbGxpbmdFbGVtZW50fHxkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQsbT1bXSx3PWU7Zm9yKDtRKHcpJiZnKHcpOyl7aWYoKHc9JCh3KSk9PT12KXttLnB1c2godyk7YnJlYWt9bnVsbCE9dyYmdz09PWRvY3VtZW50LmJvZHkmJkEodykmJiFBKGRvY3VtZW50LmRvY3VtZW50RWxlbWVudCl8fG51bGwhPXcmJkEodyx1KSYmbS5wdXNoKHcpfWxldCBXPW51bGwhPShvPW51bGw9PShsPXdpbmRvdy52aXN1YWxWaWV3cG9ydCk/dm9pZCAwOmwud2lkdGgpP286aW5uZXJXaWR0aCxIPW51bGwhPShyPW51bGw9PShuPXdpbmRvdy52aXN1YWxWaWV3cG9ydCk/dm9pZCAwOm4uaGVpZ2h0KT9yOmlubmVySGVpZ2h0LHtzY3JvbGxYOl8sc2Nyb2xsWTp4fT13aW5kb3cse2hlaWdodDpFLHdpZHRoOlQsdG9wOk4scmlnaHQ6TCxib3R0b206WSxsZWZ0OkN9PWUuZ2V0Qm91bmRpbmdDbGllbnRSZWN0KCksUj0ic3RhcnQiPT09c3x8Im5lYXJlc3QiPT09cz9OOiJlbmQiPT09cz9ZOk4rRS8yLFY9ImNlbnRlciI9PT1hP0MrVC8yOiJlbmQiPT09YT9MOkMsQj1bXTtmb3IobGV0IEQ9MDtEPG0ubGVuZ3RoO0QrKyl7bGV0IE89bVtEXSx7aGVpZ2h0Omosd2lkdGg6SSx0b3A6UyxyaWdodDpxLGJvdHRvbTp6LGxlZnQ6Rn09Ty5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTtpZigiaWYtbmVlZGVkIj09PWkmJk4+PTAmJkM+PTAmJlk8PUgmJkw8PVcmJk4+PVMmJlk8PXomJkM+PUYmJkw8PXEpYnJlYWs7bGV0IEc9Z2V0Q29tcHV0ZWRTdHlsZShPKSxKPXBhcnNlSW50KEcuYm9yZGVyTGVmdFdpZHRoLDEwKSxLPXBhcnNlSW50KEcuYm9yZGVyVG9wV2lkdGgsMTApLFA9cGFyc2VJbnQoRy5ib3JkZXJSaWdodFdpZHRoLDEwKSxaPXBhcnNlSW50KEcuYm9yZGVyQm90dG9tV2lkdGgsMTApLGVlPTAsZXQ9MCxlbD0ib2Zmc2V0V2lkdGgiaW4gTz9PLm9mZnNldFdpZHRoLU8uY2xpZW50V2lkdGgtSi1QOjAsZW89Im9mZnNldEhlaWdodCJpbiBPP08ub2Zmc2V0SGVpZ2h0LU8uY2xpZW50SGVpZ2h0LUstWjowLGVuPSJvZmZzZXRXaWR0aCJpbiBPPzA9PT1PLm9mZnNldFdpZHRoPzA6SS9PLm9mZnNldFdpZHRoOjAsZXI9Im9mZnNldEhlaWdodCJpbiBPPzA9PT1PLm9mZnNldEhlaWdodD8wOmovTy5vZmZzZXRIZWlnaHQ6MDtpZih2PT09TyllZT0ic3RhcnQiPT09cz9SOiJlbmQiPT09cz9SLUg6Im5lYXJlc3QiPT09cz9YKHgseCtILEgsSyxaLHgrUix4K1IrRSxFKTpSLUgvMixldD0ic3RhcnQiPT09YT9WOiJjZW50ZXIiPT09YT9WLVcvMjoiZW5kIj09PWE/Vi1XOlgoXyxfK1csVyxKLFAsXytWLF8rVitULFQpLGVlPU1hdGgubWF4KDAsZWUreCksZXQ9TWF0aC5tYXgoMCxldCtfKTtlbHNle2VlPSJzdGFydCI9PT1zP1ItUy1LOiJlbmQiPT09cz9SLXorWitlbzoibmVhcmVzdCI9PT1zP1goUyx6LGosSyxaK2VvLFIsUitFLEUpOlItKFMrai8yKStlby8yLGV0PSJzdGFydCI9PT1hP1YtRi1KOiJjZW50ZXIiPT09YT9WLShGK0kvMikrZWwvMjoiZW5kIj09PWE/Vi1xK1ArZWw6WChGLHEsSSxKLFArZWwsVixWK1QsVCk7bGV0e3Njcm9sbExlZnQ6ZWksc2Nyb2xsVG9wOmVkfT1PO2VlPU1hdGgubWF4KDAsTWF0aC5taW4oZWQrZWUvZXIsTy5zY3JvbGxIZWlnaHQtai9lcitlbykpLGV0PU1hdGgubWF4KDAsTWF0aC5taW4oZWkrZXQvZW4sTy5zY3JvbGxXaWR0aC1JL2VuK2VsKSksUis9ZWQtZWUsVis9ZWktZXR9Qi5wdXNoKHtlbDpPLHRvcDplZSxsZWZ0OmV0fSl9cmV0dXJuIEJ9LGY9ZT0+e3ZhciB0O3JldHVybiExPT09ZT97YmxvY2s6ImVuZCIsaW5saW5lOiJuZWFyZXN0In06KHQ9ZSk9PT1PYmplY3QodCkmJjAhPT1PYmplY3Qua2V5cyh0KS5sZW5ndGg/ZTp7YmxvY2s6InN0YXJ0IixpbmxpbmU6Im5lYXJlc3QifX07ZnVuY3Rpb24gYyhlLHQpe3ZhciBsO2lmKCFlLmlzQ29ubmVjdGVkfHwhKGU9PntsZXQgdD1lO2Zvcig7dCYmdC5wYXJlbnROb2RlOyl7aWYodC5wYXJlbnROb2RlPT09ZG9jdW1lbnQpcmV0dXJuITA7dD10LnBhcmVudE5vZGUgaW5zdGFuY2VvZiBTaGFkb3dSb290P3QucGFyZW50Tm9kZS5ob3N0OnQucGFyZW50Tm9kZX1yZXR1cm4hMX0pKGUpKXJldHVybjtpZigib2JqZWN0Ij09dHlwZW9mKGw9dCkmJiJmdW5jdGlvbiI9PXR5cGVvZiBsLmJlaGF2aW9yKXJldHVybiB0LmJlaGF2aW9yKHR0KGUsdCkpO2xldCBvPSJib29sZWFuIj09dHlwZW9mIHR8fG51bGw9PXQ/dm9pZCAwOnQuYmVoYXZpb3I7Zm9yKGxldHtlbDpuLHRvcDpyLGxlZnQ6aX1vZiB0dChlLGYodCkpKW4uc2Nyb2xsKHt0b3A6cixsZWZ0OmksYmVoYXZpb3I6b30pfXZhciBkLHA9KCk9PihkfHwoZD0icGVyZm9ybWFuY2UiaW4gd2luZG93P3BlcmZvcm1hbmNlLm5vdy5iaW5kKHBlcmZvcm1hbmNlKTpEYXRlLm5vdyksZCgpKTtmdW5jdGlvbiBiKGUpe2xldCB0PU1hdGgubWluKChwKCktZS5zdGFydFRpbWUpL2UuZHVyYXRpb24sMSksbD1lLmVhc2UodCksbz1lLnN0YXJ0WCsoZS54LWUuc3RhcnRYKSpsLG49ZS5zdGFydFkrKGUueS1lLnN0YXJ0WSkqbDtlLm1ldGhvZChvLG4sdCxsKSxvIT09ZS54fHxuIT09ZS55P3JlcXVlc3RBbmltYXRpb25GcmFtZSgoKT0+YihlKSk6ZS5jYigpfWZ1bmN0aW9uIHkoZSx0LGwpe2xldCBvPWFyZ3VtZW50cy5sZW5ndGg+MyYmdm9pZCAwIT09YXJndW1lbnRzWzNdP2FyZ3VtZW50c1szXTo2MDAsbj1hcmd1bWVudHMubGVuZ3RoPjQmJnZvaWQgMCE9PWFyZ3VtZW50c1s0XT9hcmd1bWVudHNbNF06ZT0+MSstLWUqZSplKmUqZSxyPWFyZ3VtZW50cy5sZW5ndGg+NT9hcmd1bWVudHNbNV06dm9pZCAwLGk9YXJndW1lbnRzLmxlbmd0aD42P2FyZ3VtZW50c1s2XTp2b2lkIDAscz1lLnNjcm9sbExlZnQsYT1lLnNjcm9sbFRvcDtiKHtzY3JvbGxhYmxlOmUsbWV0aG9kKHQsbCxvLG4pe2xldCByPU1hdGguY2VpbCh0KSxzPU1hdGguY2VpbChsKTtlLnNjcm9sbExlZnQ9cixlLnNjcm9sbFRvcD1zLGk/Lih7dGFyZ2V0OmUsZWxhcHNlZDpvLHZhbHVlOm4sbGVmdDpyLHRvcDpzfSl9LHN0YXJ0VGltZTpwKCksc3RhcnRYOnMsc3RhcnRZOmEseDp0LHk6bCxkdXJhdGlvbjpvLGVhc2U6bixjYjpyfSl9dmFyIE09ZT0+ZSYmIWUuYmVoYXZpb3J8fCJzbW9vdGgiPT09ZS5iZWhhdmlvcixrPWZ1bmN0aW9uKGUsdCl7bGV0IGw9dHx8e307cmV0dXJuIE0obCk/YyhlLHtibG9jazpsLmJsb2NrLGlubGluZTpsLmlubGluZSxzY3JvbGxNb2RlOmwuc2Nyb2xsTW9kZSxib3VuZGFyeTpsLmJvdW5kYXJ5LHNraXBPdmVyZmxvd0hpZGRlbkVsZW1lbnRzOmwuc2tpcE92ZXJmbG93SGlkZGVuRWxlbWVudHMsYmVoYXZpb3I6ZT0+UHJvbWlzZS5hbGwoZS5yZWR1Y2UoKGUsdCk9PntsZXR7ZWw6byxsZWZ0Om4sdG9wOnJ9PXQsaT1vLnNjcm9sbExlZnQscz1vLnNjcm9sbFRvcDtyZXR1cm4gaT09PW4mJnM9PT1yP2U6Wy4uLmUsbmV3IFByb21pc2UoZT0+eShvLG4scixsLmR1cmF0aW9uLGwuZWFzZSwoKT0+ZSh7ZWw6byxsZWZ0OltpLG5dLHRvcDpbcyxyXX0pLGwub25TY3JvbGxDaGFuZ2UpKV19LFtdKSl9KTpQcm9taXNlLnJlc29sdmUoYyhlLHQpKX07ZXhwb3J0e2sgYXMgZGVmYXVsdH07")

const indent = true
const aside = true
const title_text = "Table of Contents"
const include_definitions = false


const tocNode = html`<nav class="plutoui-toc">
	<header>
	 <span class="toc-toggle open-toc"></span>
	 <span class="toc-toggle closed-toc"></span>
	 ${title_text}
	</header>
	<section></section>
</nav>`

tocNode.classList.toggle("aside", aside)
tocNode.classList.toggle("indent", indent)


const getParentCell = el => el.closest("pluto-cell")

const getHeaders = () => {
	const depth = Math.max(1, Math.min(6, 3)) // should be in range 1:6
	const range = Array.from({length: depth}, (x, i) => i+1) // [1, ..., depth]
	
	const selector = [
		...(include_definitions ? [
			`pluto-notebook pluto-cell .pluto-docs-binding`, 
			`pluto-notebook pluto-cell assignee:not(:empty)`, 
		] : []),
		...range.map(i => `pluto-notebook pluto-cell h${i}`)
	].join(",")
	return Array.from(document.querySelectorAll(selector)).filter(el => 
		// exclude headers inside of a pluto-docs-binding block
		!(el.nodeName.startsWith("H") && el.closest(".pluto-docs-binding")) && !el.classList.contains("no-toc")
	)
}


const document_click_handler = (event) => {
	const path = (event.path || event.composedPath())
	const toc = path.find(elem => elem?.classList?.contains?.("toc-toggle"))
	if (toc) {
		event.stopImmediatePropagation()
		toc.closest(".plutoui-toc").classList.toggle("hide")
	}
}

document.addEventListener("click", document_click_handler)


const header_to_index_entry_map = new Map()
const currently_highlighted_set = new Set()

const last_toc_element_click_time = { current: 0 }

const intersection_callback = (ixs) => {
	let on_top = ixs.filter(ix => ix.intersectionRatio > 0 && ix.intersectionRect.y < ix.rootBounds.height / 2)
	if(on_top.length > 0){
		currently_highlighted_set.forEach(a => a.classList.remove("in-view"))
		currently_highlighted_set.clear()
		on_top.slice(0,1).forEach(i => {
			let div = header_to_index_entry_map.get(i.target)
			div.classList.add("in-view")
			currently_highlighted_set.add(div)
			
			/// scroll into view
			/*
			const toc_height = tocNode.offsetHeight
			const div_pos = div.offsetTop
			const div_height = div.offsetHeight
			const current_scroll = tocNode.scrollTop
			const header_height = tocNode.querySelector("header").offsetHeight
			
			const scroll_to_top = div_pos - header_height
			const scroll_to_bottom = div_pos + div_height - toc_height
			
			// if we set a scrollTop, then the browser will stop any currently ongoing smoothscroll animation. So let's only do this if you are not currently in a smoothscroll.
			if(Date.now() - last_toc_element_click_time.current >= 2000)
				if(current_scroll < scroll_to_bottom){
					tocNode.scrollTop = scroll_to_bottom
				} else if(current_scroll > scroll_to_top){
					tocNode.scrollTop = scroll_to_top
				}
			*/
		})
	}
}
let intersection_observer_1 = new IntersectionObserver(intersection_callback, {
	root: null, // i.e. the viewport
  	threshold: 1,
	rootMargin: "-15px", // slightly smaller than the viewport
	// delay: 100,
})
let intersection_observer_2 = new IntersectionObserver(intersection_callback, {
	root: null, // i.e. the viewport
  	threshold: 1,
	rootMargin: "15px", // slightly larger than the viewport
	// delay: 100,
})

const render = (elements) => {
	header_to_index_entry_map.clear()
	currently_highlighted_set.clear()
	intersection_observer_1.disconnect()
	intersection_observer_2.disconnect()

		let last_level = `H1`
	return html`${elements.map(h => {
	const parent_cell = getParentCell(h)

		let [className, title_el] = h.matches(`.pluto-docs-binding`) ? ["pluto-docs-binding-el", h.firstElementChild] : [h.nodeName, h]

	const id = title_el.matches("assignee") ?
		title_el.innerText.replace(/^const /, "") :
		title_el.id ?
		title_el.id :
		parent_cell.id
	
	const inner_html = title_el.innerHTML
		
	const a = html`<a 
		class="${className}" 
		title="${title_el.innerText}"
		href="#${id}"
	>${inner_html}</a>`
	/* a.onmouseover=()=>{
		parent_cell.firstElementChild.classList.add(
			'highlight-pluto-cell-shoulder'
		)
	}
	a.onmouseout=() => {
		parent_cell.firstElementChild.classList.remove(
			'highlight-pluto-cell-shoulder'
		)
	} */
		
		
	a.onclick=(e) => {
		e.preventDefault();
		history.replaceState(null, null, a.href)
		last_toc_element_click_time.current = Date.now()
		scrollIntoView(h, {
			behavior: 'smooth', 
			block: 'start',
		}).then(() => 
			// sometimes it doesn't scroll to the right place
			// solution: try a second time!
			scrollIntoView(h, {
				behavior: 'smooth', 
				block: 'start',
			})
	   )
	}
	   
	// Remove any `id` attributes recursively, because they may interfere with linking-to-id using `#`
	const removeIdAttributes = (el) => {
		if (el && el.nodeType === 1) { // Element node
			if (el.hasAttribute?.("id")) el.removeAttribute?.("id")
			el.childNodes.forEach(removeIdAttributes)
		}
	}
	removeIdAttributes(a)

	// Remove Click-To-Copy-Header-ID feature
	a.querySelectorAll("pluto-header-id-copy-wrapper").forEach(el => el.remove())

	const row =  html`<div class="toc-row ${className} after-${last_level}">${a}</div>`
		intersection_observer_1.observe(title_el)
		intersection_observer_2.observe(title_el)
		header_to_index_entry_map.set(title_el, row)

	if(className.startsWith("H"))
		last_level = className
		
	return row
})}`
}

const invalidated = { current: false }

const updateCallback = () => {
	if (!invalidated.current) {
		tocNode.querySelector("section").replaceWith(
			html`<section>${render(getHeaders())}</section>`
		)
	}
}
updateCallback()
setTimeout(updateCallback, 100)
setTimeout(updateCallback, 1000)
setTimeout(updateCallback, 5000)

const notebook = document.querySelector("pluto-notebook")


// We have a mutationobserver for each cell:
const mut_observers = {
	current: [],
}

const createCellObservers = () => {
	mut_observers.current.forEach((o) => o.disconnect())
	mut_observers.current = Array.from(notebook.querySelectorAll("pluto-cell")).map(el => {
		const o = new MutationObserver(updateCallback)
		o.observe(el, {attributeFilter: ["class"]})
		return o
	})
}
createCellObservers()

// And one for the notebook's child list, which updates our cell observers:
const notebookObserver = new MutationObserver(() => {
	updateCallback()
	createCellObservers()
})
notebookObserver.observe(notebook, {childList: true})

// And finally, an observer for the document.body classList, to make sure that the toc also works when it is loaded during notebook initialization
const bodyClassObserver = new MutationObserver(updateCallback)
bodyClassObserver.observe(document.body, {attributeFilter: ["class"]})

// Hide/show the ToC when the screen gets small
let match_listener = () => {
	const small = (tocNode.closest("pluto-editor") ?? document.body).scrollWidth < 1000
	tocNode.classList.toggle("smallscreen", small)
	tocNode.classList.toggle("hide", small)
}
for(let s of [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) {
	let m = matchMedia(`(max-width: ${s}px)`)
	m.addListener(match_listener)
	invalidation.then(() => m.removeListener(match_listener))
}
match_listener()

invalidation.then(() => {
	invalidated.current = true
	intersection_observer_1.disconnect()
	intersection_observer_2.disconnect()
	notebookObserver.disconnect()
	bodyClassObserver.disconnect()
	mut_observers.current.forEach((o) => o.disconnect())
	document.removeEventListener("click", document_click_handler)
})

return tocNode
</script>
<style>
@media not print {

.plutoui-toc {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Cantarell, "Apple Color Emoji",
		"Segoe UI Emoji", "Segoe UI Symbol", system-ui, sans-serif;
	--main-bg-color: #fafafa;
	--pluto-output-color: hsl(0, 0%, 36%);
	--pluto-output-h-color: hsl(0, 0%, 21%);
	--sidebar-li-active-bg: rgb(235, 235, 235);
	--icon-filter: unset;
}

@media (prefers-color-scheme: dark) {
	.plutoui-toc {
		--main-bg-color: #303030;
		--pluto-output-color: hsl(0, 0%, 90%);
		--pluto-output-h-color: hsl(0, 0%, 97%);
		--sidebar-li-active-bg: rgb(82, 82, 82);
		--icon-filter: invert(1);
	}
}

.plutoui-toc.aside {
	color: var(--pluto-output-color);
	position: fixed;
	right: 1rem;
	top: 5rem;
	width: min(80vw, 300px);
	padding: 0.5rem;
	padding-top: 0em;
	/* border: 3px solid rgba(0, 0, 0, 0.15); */
	border-radius: 10px;
	max-height: calc(100vh - 5rem - 90px);
	overflow: auto;
	z-index: 40;
	background-color: var(--main-bg-color);
	transition: transform 300ms cubic-bezier(0.18, 0.89, 0.45, 1.12);
}

.plutoui-toc.smallscreen:not(.hide) {
	box-shadow: 0 0 11px 0px #00000010;
}

.plutoui-toc.aside.hide {
	transform: translateX(calc(100% - 28px));
	color: transparent;
}
.plutoui-toc.aside.hide section {
	display: none;
}
.plutoui-toc.aside.hide header {
	margin-bottom: 0em;
	padding-bottom: 0em;
	border-bottom: none;
}
}  /* End of Media print query */
.plutoui-toc.aside.hide .open-toc,
.plutoui-toc.aside:not(.hide) .closed-toc,
.plutoui-toc:not(.aside) .closed-toc {
	display: none;
}

@media (prefers-reduced-motion) {
  .plutoui-toc.aside {
	transition-duration: 0s;
  }
}

.toc-toggle {
	cursor: pointer;
    padding: 1em;
    margin: -1em;
    margin-right: -0.7em;
    line-height: 1em;
    display: flex;
}

.toc-toggle::before {
    content: "";
    display: inline-block;
    height: 1em;
    width: 1em;
    background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/list-outline.svg");
	/* generated using https://dopiaza.org/tools/datauri/index.php */
    background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PHRpdGxlPmlvbmljb25zLXY1LW88L3RpdGxlPjxsaW5lIHgxPSIxNjAiIHkxPSIxNDQiIHgyPSI0NDgiIHkyPSIxNDQiIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDA7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS13aWR0aDozMnB4Ii8+PGxpbmUgeDE9IjE2MCIgeTE9IjI1NiIgeDI9IjQ0OCIgeTI9IjI1NiIgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLXdpZHRoOjMycHgiLz48bGluZSB4MT0iMTYwIiB5MT0iMzY4IiB4Mj0iNDQ4IiB5Mj0iMzY4IiBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6MzJweCIvPjxjaXJjbGUgY3g9IjgwIiBjeT0iMTQ0IiByPSIxNiIgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDtzdHJva2UtbGluZWNhcDpyb3VuZDtzdHJva2UtbGluZWpvaW46cm91bmQ7c3Ryb2tlLXdpZHRoOjMycHgiLz48Y2lyY2xlIGN4PSI4MCIgY3k9IjI1NiIgcj0iMTYiIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDA7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS13aWR0aDozMnB4Ii8+PGNpcmNsZSBjeD0iODAiIGN5PSIzNjgiIHI9IjE2IiBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6MzJweCIvPjwvc3ZnPg==");
    background-size: 1em;
	filter: var(--icon-filter);
}

.aside .toc-toggle.open-toc:hover::before {
    background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/arrow-forward-outline.svg");
	/* generated using https://dopiaza.org/tools/datauri/index.php */
    background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PHRpdGxlPmlvbmljb25zLXY1LWE8L3RpdGxlPjxwb2x5bGluZSBwb2ludHM9IjI2OCAxMTIgNDEyIDI1NiAyNjggNDAwIiBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6NDhweCIvPjxsaW5lIHgxPSIzOTIiIHkxPSIyNTYiIHgyPSIxMDAiIHkyPSIyNTYiIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDA7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS13aWR0aDo0OHB4Ii8+PC9zdmc+");
}
.aside .toc-toggle.closed-toc:hover::before {
    background-image: url("https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/arrow-back-outline.svg");
	/* generated using https://dopiaza.org/tools/datauri/index.php */
    background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgNTEyIDUxMiI+PHRpdGxlPmlvbmljb25zLXY1LWE8L3RpdGxlPjxwb2x5bGluZSBwb2ludHM9IjI0NCA0MDAgMTAwIDI1NiAyNDQgMTEyIiBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6NDhweCIvPjxsaW5lIHgxPSIxMjAiIHkxPSIyNTYiIHgyPSI0MTIiIHkyPSIyNTYiIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDA7c3Ryb2tlLWxpbmVjYXA6cm91bmQ7c3Ryb2tlLWxpbmVqb2luOnJvdW5kO3N0cm9rZS13aWR0aDo0OHB4Ii8+PC9zdmc+");
}



.plutoui-toc header {
	display: flex;
	align-items: center;
	gap: .3em;
	font-size: 1.5em;
	/* margin-top: -0.1em; */
	margin-bottom: 0.4em;
	padding: 0.5rem;
	margin-left: 0;
	margin-right: 0;
	font-weight: bold;
	/* border-bottom: 2px solid rgba(0, 0, 0, 0.15); */
	position: sticky;
	top: 0px;
	background: var(--main-bg-color);
	z-index: 41;
}
.plutoui-toc.aside header {
	padding-left: 0;
	padding-right: 0;
}

.plutoui-toc section .toc-row {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	padding: .1em;
	border-radius: .2em;
}

.plutoui-toc section .toc-row.H1 {
	margin-top: 1em;
}


.plutoui-toc.aside section .toc-row.in-view {
	background: var(--sidebar-li-active-bg);
}


	
.highlight-pluto-cell-shoulder {
	background: rgba(0, 0, 0, 0.05);
	background-clip: padding-box;
}

.plutoui-toc section a {
	text-decoration: none;
	font-weight: normal;
	color: var(--pluto-output-color);
}
.plutoui-toc section a:hover {
	color: var(--pluto-output-h-color);
}

.plutoui-toc.indent section a.H1 {
	font-weight: 700;
	line-height: 1em;
}

.plutoui-toc.indent section .after-H2 a { padding-left: 10px; }
.plutoui-toc.indent section .after-H3 a { padding-left: 20px; }
.plutoui-toc.indent section .after-H4 a { padding-left: 30px; }
.plutoui-toc.indent section .after-H5 a { padding-left: 40px; }
.plutoui-toc.indent section .after-H6 a { padding-left: 50px; }

.plutoui-toc.indent section a.H1 { padding-left: 0px; }
.plutoui-toc.indent section a.H2 { padding-left: 10px; }
.plutoui-toc.indent section a.H3 { padding-left: 20px; }
.plutoui-toc.indent section a.H4 { padding-left: 30px; }
.plutoui-toc.indent section a.H5 { padding-left: 40px; }
.plutoui-toc.indent section a.H6 { padding-left: 50px; }


.plutoui-toc.indent section a.pluto-docs-binding-el,
.plutoui-toc.indent section a.ASSIGNEE
	{
	font-family: JuliaMono, monospace;
	font-size: .8em;
	/* background: black; */
	font-weight: 700;
    font-style: italic;
	color: var(--cm-var-color); /* this is stealing a variable from Pluto, but it's fine if that doesnt work */
}
.plutoui-toc.indent section a.pluto-docs-binding-el::before,
.plutoui-toc.indent section a.ASSIGNEE::before
	{
	content: "> ";
	opacity: .3;
}
</style>
mimetext/htmlrootassigneelast_run_timestampA})?ܰpersist_js_state·has_pluto_hook_features§cell_id$bcb4be20-0439-4809-a166-8c50b6b9206bdepends_on_disabled_cells§runtimeVpublished_object_keysdepends_on_skipped_cells§errored$3e18b2fa-d294-11ef-1255-df048f0dcec2queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Richard-Cox-and-the-Calculus-of-Rational-Reasoning">Richard Cox and the Calculus of Rational Reasoning</h2>
<p><a href="https://aapt.scitation.org/doi/10.1119/1.1990764">Richard T. Cox &#40;1946&#41;</a> developed a <strong>calculus for rational reasoning</strong> about how to represent and update the <strong>degree-of-belief</strong> about the truth value of an event when faced with new information.  </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})+԰persist_js_state·has_pluto_hook_features§cell_id$3e18b2fa-d294-11ef-1255-df048f0dcec2depends_on_disabled_cells§runtime ~published_object_keysdepends_on_skipped_cells§errored$5394e37c-ae00-4042-8ada-3bbf32fbca9equeued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})Kpersist_js_state·has_pluto_hook_features§cell_id$5394e37c-ae00-4042-8ada-3bbf32fbca9edepends_on_disabled_cells§runtime1]0<published_object_keysdepends_on_skipped_cells§errored$3e1b5c9c-d294-11ef-137f-d75b3731eae4queued¤logsrunning¦outputbody<div class="markdown"><p>We mentioned before that every inference problem in PT can be evaluated through the sum and product rules. Next, we present two useful corollaries: &#40;1&#41; <em>Marginalization</em> and &#40;2&#41; <em>Bayes rule</em>. </p>
</div>mimetext/htmlrootassigneelast_run_timestampA})7!persist_js_state·has_pluto_hook_features§cell_id$3e1b5c9c-d294-11ef-137f-d75b3731eae4depends_on_disabled_cells§runtime }published_object_keysdepends_on_skipped_cells§errored$727dc817-0284-4c0f-9a92-21dcbea50807queued¤logsrunning¦outputbody<details>
	<summary>Click for the solution</summary>
	<div class="details-content">
		<plutoui-detail><div class="markdown"><p>&#40;a&#41; <span class="tex">$p&#40;S_1&#61;R&#41; &#61; \frac&#123;N_\text&#123;red&#125;&#125;&#123;N_\text&#123;red&#125;&#43;N_\text&#123;green&#125;&#125; &#61; \frac&#123;5&#125;&#123;12&#125;$</span></p>
<p>&#40;b&#41; The outcome of the <span class="tex">$n$</span>-th draw is referred to by <span class="tex">$S_n$</span>. Use Bayes rule to get,	</p>
<p class="tex">$$\begin&#123;align&#125;
p&#40;S_1&#61;\text&#123;R&#125; | S_2&#61;\text&#123;G&#125;&#41; &amp;&#61; \frac&#123;p&#40;S_2&#61;\text&#123;G&#125; | S_1&#61;\text&#123;R&#125;&#41; p&#40;S_1&#61;\text&#123;R&#125;&#41;&#125; &#123;p&#40;S_2&#61;\text&#123;G&#125; | S_1 &#61; \text&#123;R&#125;&#41; p&#40;S_1&#61;\text&#123;R&#125;&#41; &#43; p&#40;S_2&#61;\text&#123;G&#125; | S_1&#61;\text&#123;G&#125;&#41; p&#40;S_1&#61;\text&#123;G&#125;&#41;&#125; \\
    &amp;&#61; \frac&#123;\frac&#123;7&#125;&#123;11&#125;\cdot\frac&#123;5&#125;&#123;12&#125;&#125;&#123;\frac&#123;7&#125;&#123;11&#125;\cdot\frac&#123;5&#125;&#123;12&#125;&#43;\frac&#123;6&#125;&#123;11&#125;\cdot\frac&#123;7&#125;&#123;12&#125;&#125; \\
	&amp;&#61; \frac&#123;5&#125;&#123;11&#125;
\end&#123;align&#125;$$</p>
</div></plutoui-detail>
	</div>
</details>
<style type="text/css">
plutoui-detail {
	display: block;
	margin-block-end: var(--pluto-cell-spacing);
}

plutoui-detail:last-child {
	margin-block-end: 0;
}

pluto-output div.summary-title-outer {
	display: inline-flex;
	vertical-align: text-top;
	width: calc(100% - 1em);
	margin-left: -1em;
	padding-left: 1em;
}

pluto-output div.summary-title-outer > div.summary-title-inner {
	display: inline-block;
}
</style>

mimetext/htmlrootassigneelast_run_timestampA})\persist_js_state·has_pluto_hook_features§cell_id$727dc817-0284-4c0f-9a92-21dcbea50807depends_on_disabled_cells§runtime tpublished_object_keysdepends_on_skipped_cells§errored$eeb9a1f5-b857-4843-920b-2e4a9656f66bqueued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA})Xpersist_js_state·has_pluto_hook_features§cell_id$eeb9a1f5-b857-4843-920b-2e4a9656f66bdepends_on_disabled_cells§runtime·published_object_keysdepends_on_skipped_cells§errored$9b85a92b-c56b-48a3-97c1-6b1882e33a22queued¤logsrunning¦outputbodyٟ<label style="font-weight: bold;">
Show solution? <bond def="show_disease_diagnosis_solution" unique_id="wjxogaflfocu"><input type="checkbox"></bond>
</label>
mimetext/htmlrootassigneelast_run_timestampA})2˟persist_js_state·has_pluto_hook_features§cell_id$9b85a92b-c56b-48a3-97c1-6b1882e33a22depends_on_disabled_cells§runtimeH
еpublished_object_keysdepends_on_skipped_cells§errored$3e1babca-d294-11ef-37c1-cd821a6488b2queued¤logsrunning¦outputbody<div class="markdown"><p>Note that marginalization can be understood as applying a &quot;generalized&quot; sum rule. Bishop &#40;p.14&#41; and some other authors also refer to this as the sum rule, but we do not follow that terminology.</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})=%persist_js_state·has_pluto_hook_features§cell_id$3e1babca-d294-11ef-37c1-cd821a6488b2depends_on_disabled_cells§runtime )published_object_keysdepends_on_skipped_cells§errored$3e1b4b1c-d294-11ef-0423-9152887cc403queued¤logsrunning¦outputbody<div class="markdown"><h2 id="Independent,-Exclusive,-and-Exhaustive-Events">Independent, Exclusive, and Exhaustive Events</h2>
<p>It will be helpful to introduce some terms concerning special relationships between events.  </p>
<h5 id="Joint-events">Joint events</h5>
<p>The expression <span class="tex">$p&#40;A,B&#41;$</span> for the probability of the conjuction <span class="tex">$A \land B$</span> is also called the <strong>joint probability</strong> of events <span class="tex">$A$</span> and <span class="tex">$B$</span>. Note that </p>
<p class="tex">$$p&#40;A,B&#41; &#61; p&#40;B,A&#41;\,,$$</p>
<p>since <span class="tex">$A\land B &#61; B \land A$</span>. Therefore, the order of arguments in a joint probability distribution does not matter: <span class="tex">$p&#40;A,B,C,D&#41; &#61; p&#40;C,A,D,B&#41;$</span>, etc.</p>
<h5 id="Independent-events">Independent events</h5>
<p>Two events <span class="tex">$A$</span> and <span class="tex">$B$</span> are said to be <strong>independent</strong> if the probability of one event is not altered by information about the truth of the other event, i.e., </p>
<p class="tex">$$p&#40;A|B&#41; &#61; p&#40;A&#41;\,.$$</p>
<p>It follows that, if <span class="tex">$A$</span> and <span class="tex">$B$</span> are independent, then the product rule simplifies to </p>
<p class="tex">$$p&#40;A,B&#41; &#61; p&#40;A&#41; p&#40;B&#41;\,.$$</p>
<p><span class="tex">$A$</span> and <span class="tex">$B$</span> with given background <span class="tex">$I$</span> are said to be <strong>conditionally independent</strong> for given <span class="tex">$I$</span>, if </p>
<p class="tex">$$p&#40;A|B,I&#41; &#61; p&#40;A|I&#41;\,.$$</p>
<p>In that case, the product rule simplifies to <span class="tex">$p&#40;A,B|I&#41; &#61; p&#40;A|I&#41; p&#40;B|I&#41;$</span>.</p>
<h5 id="Mutually-exclusive-events">Mutually exclusive events</h5>
<p>Two events <span class="tex">$A_1$</span> and <span class="tex">$A_2$</span> are said to be <strong>mutually exclusive</strong> &#40;&#39;disjoint&#39;&#41; if they cannot be true simultaneously, i.e., if</p>
<p class="tex">$$p&#40;A_1,A_2&#41;&#61;0 \,.$$</p>
<p>For mutually exclusive events, probabilities add &#40;this follows from the sum rule&#41;, hence </p>
<p class="tex">$$p&#40;A_1 &#43; A_2&#41; &#61; p&#40;A_1&#41; &#43; p&#40;A_2&#41;$$</p>
<h5 id="Collectively-exhaustive-events">Collectively exhaustive events</h5>
<p>A set of events <span class="tex">$A_1, A_2, \ldots, A_N$</span> is said to be <strong>collectively exhaustive</strong> if one of the statements is necessarily true, i.e., <span class="tex">$A_1&#43;A_2&#43;\cdots &#43;A_N&#61;\mathrm&#123;TRUE&#125;$</span>, or equivalently </p>
<p class="tex">$$p&#40;A_1&#43;A_2&#43;\cdots &#43;A_N&#41; &#61; 1 \,.$$</p>
<h5 id="Partitioning-the-universe">Partitioning the universe</h5>
<p>If a set of events <span class="tex">$A_1, A_2, \ldots, A_n$</span> is both <strong>mutually exclusive</strong> and <strong>collectively exhaustive</strong>, then we say that they <strong>partition the universe</strong>. Technically, this means that </p>
<p class="tex">$$\sum_&#123;n&#61;1&#125;^N p&#40;A_n&#41; &#61; p&#40;A_1 &#43; \ldots &#43; A_N&#41; &#61; 1$$</p>
</div>mimetext/htmlrootassigneelast_run_timestampA})7^persist_js_state·has_pluto_hook_features§cell_id$3e1b4b1c-d294-11ef-0423-9152887cc403depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$3e18e4bc-d294-11ef-38bc-cb97cb4e0963queued¤logsrunning¦outputbody<div class="markdown"><div class="admonition key-concept"><p class="admonition-title">🎯 Key concept</p><p><strong> </strong></p>

<p>When real numbers are used to represent <strong>degrees of belief</strong>, logical consistency enforces the sum and product rules of probability theory, making probability theory the optimal framework for information processing under uncertainty.</p>

</div>
</div>mimetext/htmlrootassigneelast_run_timestampA})K8persist_js_state·has_pluto_hook_features§cell_id$3e18e4bc-d294-11ef-38bc-cb97cb4e0963depends_on_disabled_cells§runtime,nӵpublished_object_keysdepends_on_skipped_cells§errored±cell_dependencies 5$9b92fc89-2036-4525-979b-d296ab29329cprecedence_heuristic	cell_id$9b92fc89-2036-4525-979b-d296ab29329cdownstream_cells_mapupstream_cells_map@md_strgetindex$b305a905-06c2-4a15-8042-72ef6375720fprecedence_heuristiccell_id$b305a905-06c2-4a15-8042-72ef6375720fdownstream_cells_mapBmlipTeachingToolsupstream_cells_map$3e1b7d14-d294-11ef-0d10-1148a928dd57precedence_heuristic	cell_id$3e1b7d14-d294-11ef-0d10-1148a928dd57downstream_cells_mapupstream_cells_map@md_strgetindex$5377c5a4-77c4-4fa7-9f84-0c511e3bf708precedence_heuristic	cell_id$5377c5a4-77c4-4fa7-9f84-0c511e3bf708downstream_cells_mapupstream_cells_map@md_strhide_proofgetindex$3e1b8bf4-d294-11ef-04cc-6364e46fdd64precedence_heuristic	cell_id$3e1b8bf4-d294-11ef-04cc-6364e46fdd64downstream_cells_mapupstream_cells_map@md_strgetindex$3e1de32c-d294-11ef-1f63-f190c8361404precedence_heuristic	cell_id$3e1de32c-d294-11ef-1f63-f190c8361404downstream_cells_mapupstream_cells_map@md_strgetindex$3e185ab0-d294-11ef-3f7d-9bd465518274precedence_heuristic	cell_id$3e185ab0-d294-11ef-3f7d-9bd465518274downstream_cells_mapupstream_cells_map@md_strspecificity_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5aprevalence_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5asensitivity_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5agetindex$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4precedence_heuristic	cell_id$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4downstream_cells_mapupstream_cells_map@md_strhide_solutiongetindex$4a81342c-17c7-4eb9-933b-edb98df7b9c4precedence_heuristic	cell_id$4a81342c-17c7-4eb9-933b-edb98df7b9c4downstream_cells_mapn$2156f96e-eebe-4190-8ce9-c76825c6da71upstream_cells_map@sprintf$3e1bcb00-d294-11ef-2795-bd225bd00496precedence_heuristic	cell_id$3e1bcb00-d294-11ef-2795-bd225bd00496downstream_cells_mapupstream_cells_map@md_strHTMLgetindex$70d79732-0f55-40ba-929d-fba431318848precedence_heuristic	cell_id$70d79732-0f55-40ba-929d-fba431318848downstream_cells_mapupstream_cells_map@md_strgetindex$922770f4-ddc8-4089-b378-f14088276b43precedence_heuristic	cell_id$922770f4-ddc8-4089-b378-f14088276b43downstream_cells_mapupstream_cells_mapexercise_statement$3e027ede-4ac1-4521-a026-dc00bfca4adfprecedence_heuristic	cell_id$3e027ede-4ac1-4521-a026-dc00bfca4adfdownstream_cells_mapupstream_cells_mapexercise_statement$a66ab9df-897c-42e5-8b0f-c520ceaffa23precedence_heuristiccell_id$a66ab9df-897c-42e5-8b0f-c520ceaffa23downstream_cells_mapPrintfupstream_cells_map$ea803646-b18e-4f13-ab6a-fc5080d44e92precedence_heuristic	cell_id$ea803646-b18e-4f13-ab6a-fc5080d44e92downstream_cells_mapupstream_cells_mapchallenge_solution$16c2eb59-16b8-4347-9aab-6e4b99016c79precedence_heuristic	cell_id$16c2eb59-16b8-4347-9aab-6e4b99016c79downstream_cells_mapupstream_cells_map@md_strkeyconceptgetindex$3e1e2b96-d294-11ef-3a68-fdc78232142eprecedence_heuristic	cell_id$3e1e2b96-d294-11ef-3a68-fdc78232142edownstream_cells_mapupstream_cells_map@md_strgetindex$b176ceae-884e-4460-9f66-020c1ac447f1precedence_heuristic	cell_id$b176ceae-884e-4460-9f66-020c1ac447f1downstream_cells_mapupstream_cells_map@md_strgetindex$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4precedence_heuristic	cell_id$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4downstream_cells_mapupstream_cells_map@md_strgetindex$3e1ab104-d294-11ef-1a98-412946949fbaprecedence_heuristic	cell_id$3e1ab104-d294-11ef-1a98-412946949fbadownstream_cells_mapupstream_cells_map@md_strHTMLgetindex$fea8ae4c-8ef9-4b74-ad13-1314afef97deprecedence_heuristic	cell_id$fea8ae4c-8ef9-4b74-ad13-1314afef97dedownstream_cells_mapupstream_cells_map@md_strgetindex$3e18d2ea-d294-11ef-35e9-2332dd31dbf0precedence_heuristic	cell_id$3e18d2ea-d294-11ef-35e9-2332dd31dbf0downstream_cells_mapupstream_cells_map@md_strgetindex$42b47af6-b850-4987-a2d7-805a2cb64e43precedence_heuristiccell_id$42b47af6-b850-4987-a2d7-805a2cb64e43downstream_cells_map@mdx$2156f96e-eebe-4190-8ce9-c76825c6da71upstream_cells_map$3e1bdd02-d294-11ef-19e8-2f44eccf58afprecedence_heuristic	cell_id$3e1bdd02-d294-11ef-19e8-2f44eccf58afdownstream_cells_mapupstream_cells_map@md_strgetindex$5da42e9a-4318-48ea-9f43-4c1e1c97bcebprecedence_heuristic	cell_id$5da42e9a-4318-48ea-9f43-4c1e1c97bcebdownstream_cells_mapupstream_cells_mapkeyconceptsummary$dd31ec7c-708d-4fd7-958d-f9887798a5bcprecedence_heuristic	cell_id$dd31ec7c-708d-4fd7-958d-f9887798a5bcdownstream_cells_mapupstream_cells_map@md_strgetindex$bbce1c6f-6f13-4449-9215-bd8ed839a44bprecedence_heuristic	cell_id$bbce1c6f-6f13-4449-9215-bd8ed839a44bdownstream_cells_mapupstream_cells_mapnavigate_prev_nextnothing$4abbb3de-3b21-4c31-b015-e16c466a20aaprecedence_heuristic	cell_id$4abbb3de-3b21-4c31-b015-e16c466a20aadownstream_cells_mapupstream_cells_map@md_strgetindex$3e1d33c8-d294-11ef-0a08-bdc419949925precedence_heuristic	cell_id$3e1d33c8-d294-11ef-0a08-bdc419949925downstream_cells_mapupstream_cells_map@md_strgetindex$4f6dd225-c64d-4b76-b075-0bf71c863b5aprecedence_heuristic	cell_id$4f6dd225-c64d-4b76-b075-0bf71c863b5adownstream_cells_mapspecificity_bond$3e185ab0-d294-11ef-3f7d-9bd465518274$3e1d6d00-d294-11ef-1081-e11b8397eb91prevalence_bond$3e185ab0-d294-11ef-3f7d-9bd465518274$3e1d6d00-d294-11ef-1081-e11b8397eb91sensitivity$2156f96e-eebe-4190-8ce9-c76825c6da71$a8046381-ff11-40af-ae2b-078d71c586e7specificity$2156f96e-eebe-4190-8ce9-c76825c6da71$a8046381-ff11-40af-ae2b-078d71c586e7prevalence$2156f96e-eebe-4190-8ce9-c76825c6da71$a8046381-ff11-40af-ae2b-078d71c586e7sensitivity_bond$3e185ab0-d294-11ef-3f7d-9bd465518274$3e1d6d00-d294-11ef-1081-e11b8397eb91upstream_cells_mapCoreBase:PlutoRunner.create_bondPlutoRunnerCore.applicable@bindBase.getScrubbable$a8046381-ff11-40af-ae2b-078d71c586e7precedence_heuristic	cell_id$a8046381-ff11-40af-ae2b-078d71c586e7downstream_cells_mapresult$2156f96e-eebe-4190-8ce9-c76825c6da71upstream_cells_map-sensitivity$4f6dd225-c64d-4b76-b075-0bf71c863b5a/specificity$4f6dd225-c64d-4b76-b075-0bf71c863b5a+*prevalence$4f6dd225-c64d-4b76-b075-0bf71c863b5a$3e18c25c-d294-11ef-11bc-a93c2572b107precedence_heuristic	cell_id$3e18c25c-d294-11ef-11bc-a93c2572b107downstream_cells_mapupstream_cells_map@md_strgetindex$3e1b05ee-d294-11ef-33de-efed64d01c0dprecedence_heuristic	cell_id$3e1b05ee-d294-11ef-33de-efed64d01c0ddownstream_cells_mapupstream_cells_map@md_strkeyconceptgetindex$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafprecedence_heuristic	cell_id$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafdownstream_cells_mapupstream_cells_map@md_strgetindex$2156f96e-eebe-4190-8ce9-c76825c6da71precedence_heuristic	cell_id$2156f96e-eebe-4190-8ce9-c76825c6da71downstream_cells_map#468#resultupstream_cells_mapresult$a8046381-ff11-40af-ae2b-078d71c586e7HypertextLiteral.Bypassspecificity$4f6dd225-c64d-4b76-b075-0bf71c863b5aHypertextLiteral.content@mdx$42b47af6-b850-4987-a2d7-805a2cb64e43prevalence$4f6dd225-c64d-4b76-b075-0bf71c863b5aMarkdownLiteral-sensitivity$4f6dd225-c64d-4b76-b075-0bf71c863b5a MarkdownLiteral.CMParsedRendererHypertextLiteral.ResultHypertextLiteralshow_disease_diagnosis_solution$9b85a92b-c56b-48a3-97c1-6b1882e33a22n$4a81342c-17c7-4eb9-933b-edb98df7b9c4$3e1bf116-d294-11ef-148b-f7a1ca3f3badprecedence_heuristic	cell_id$3e1bf116-d294-11ef-148b-f7a1ca3f3baddownstream_cells_mapupstream_cells_map@md_strgetindex$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0precedence_heuristic	cell_id$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0downstream_cells_mapupstream_cells_map@md_strgetindex$3e1889b8-d294-11ef-17bb-496655fbd618precedence_heuristic	cell_id$3e1889b8-d294-11ef-17bb-496655fbd618downstream_cells_mapupstream_cells_map@md_strgetindex$3e17df5e-d294-11ef-38c7-f573724871d8precedence_heuristic	cell_id$3e17df5e-d294-11ef-38c7-f573724871d8downstream_cells_mapupstream_cells_maptitle$ff9142ba-3a85-48cf-8b78-07e0b554e280precedence_heuristic	cell_id$ff9142ba-3a85-48cf-8b78-07e0b554e280downstream_cells_mapupstream_cells_map@md_strgetindex$61713e1c-8e37-45d9-9f58-c3db69e15b66precedence_heuristic	cell_id$61713e1c-8e37-45d9-9f58-c3db69e15b66downstream_cells_mapupstream_cells_mapchallenge_statement$41bee964-a0a9-4a7f-8505-54a9ee12ef0dprecedence_heuristic	cell_id$41bee964-a0a9-4a7f-8505-54a9ee12ef0ddownstream_cells_mapupstream_cells_map@md_strgetindex$3e1d6d00-d294-11ef-1081-e11b8397eb91precedence_heuristic	cell_id$3e1d6d00-d294-11ef-1081-e11b8397eb91downstream_cells_mapupstream_cells_map@md_strspecificity_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5aprevalence_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5asensitivity_bond$4f6dd225-c64d-4b76-b075-0bf71c863b5agetindex$bcb4be20-0439-4809-a166-8c50b6b9206bprecedence_heuristic	cell_id$bcb4be20-0439-4809-a166-8c50b6b9206bdownstream_cells_mapupstream_cells_mapPlutoUIPlutoUI.TableOfContents$3e18b2fa-d294-11ef-1255-df048f0dcec2precedence_heuristic	cell_id$3e18b2fa-d294-11ef-1255-df048f0dcec2downstream_cells_mapupstream_cells_map@md_strgetindex$5394e37c-ae00-4042-8ada-3bbf32fbca9eprecedence_heuristiccell_id$5394e37c-ae00-4042-8ada-3bbf32fbca9edownstream_cells_mapDistributionsupstream_cells_map$3e1b5c9c-d294-11ef-137f-d75b3731eae4precedence_heuristic	cell_id$3e1b5c9c-d294-11ef-137f-d75b3731eae4downstream_cells_mapupstream_cells_map@md_strgetindex$727dc817-0284-4c0f-9a92-21dcbea50807precedence_heuristic	cell_id$727dc817-0284-4c0f-9a92-21dcbea50807downstream_cells_mapupstream_cells_map@md_strhide_solutiongetindex$eeb9a1f5-b857-4843-920b-2e4a9656f66bprecedence_heuristiccell_id$eeb9a1f5-b857-4843-920b-2e4a9656f66bdownstream_cells_mapPlotsLaTeXStringsupstream_cells_map$9b85a92b-c56b-48a3-97c1-6b1882e33a22precedence_heuristic	cell_id$9b85a92b-c56b-48a3-97c1-6b1882e33a22downstream_cells_mapshow_disease_diagnosis_solution$2156f96e-eebe-4190-8ce9-c76825c6da71upstream_cells_map#PlutoRunner.PlutoRunner.create_bondHypertextLiteral.Bypass@bindHypertextLiteral.content@htlPlutoRunnerCheckBoxPlutoRunner.Base.getHypertextLiteral.ResultHypertextLiteralPlutoRunner.Core.applicable$3e1babca-d294-11ef-37c1-cd821a6488b2precedence_heuristic	cell_id$3e1babca-d294-11ef-37c1-cd821a6488b2downstream_cells_mapupstream_cells_map@md_strgetindex$3e1b4b1c-d294-11ef-0423-9152887cc403precedence_heuristic	cell_id$3e1b4b1c-d294-11ef-0423-9152887cc403downstream_cells_mapupstream_cells_map@md_strgetindex$3e18e4bc-d294-11ef-38bc-cb97cb4e0963precedence_heuristic	cell_id$3e18e4bc-d294-11ef-38bc-cb97cb4e0963downstream_cells_mapupstream_cells_map@md_strkeyconceptgetindexcell_execution_order 5$b305a905-06c2-4a15-8042-72ef6375720f$eeb9a1f5-b857-4843-920b-2e4a9656f66b$5394e37c-ae00-4042-8ada-3bbf32fbca9e$42b47af6-b850-4987-a2d7-805a2cb64e43$a66ab9df-897c-42e5-8b0f-c520ceaffa23$3e17df5e-d294-11ef-38c7-f573724871d8$bcb4be20-0439-4809-a166-8c50b6b9206b$61713e1c-8e37-45d9-9f58-c3db69e15b66$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcaf$41bee964-a0a9-4a7f-8505-54a9ee12ef0d$3e1889b8-d294-11ef-17bb-496655fbd618$3e18b2fa-d294-11ef-1255-df048f0dcec2$3e18c25c-d294-11ef-11bc-a93c2572b107$3e18d2ea-d294-11ef-35e9-2332dd31dbf0$4abbb3de-3b21-4c31-b015-e16c466a20aa$3e18e4bc-d294-11ef-38bc-cb97cb4e0963$3e1ab104-d294-11ef-1a98-412946949fba$fea8ae4c-8ef9-4b74-ad13-1314afef97de$3e1b4b1c-d294-11ef-0423-9152887cc403$3e1b5c9c-d294-11ef-137f-d75b3731eae4$3e1b7d14-d294-11ef-0d10-1148a928dd57$5377c5a4-77c4-4fa7-9f84-0c511e3bf708$3e1b8bf4-d294-11ef-04cc-6364e46fdd64$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0$3e1babca-d294-11ef-37c1-cd821a6488b2$3e1bcb00-d294-11ef-2795-bd225bd00496$3e1bdd02-d294-11ef-19e8-2f44eccf58af$3e1bf116-d294-11ef-148b-f7a1ca3f3bad$16c2eb59-16b8-4347-9aab-6e4b99016c79$3e1d33c8-d294-11ef-0a08-bdc419949925$3e1b05ee-d294-11ef-33de-efed64d01c0d$b176ceae-884e-4460-9f66-020c1ac447f1$922770f4-ddc8-4089-b378-f14088276b43$3e1de32c-d294-11ef-1f63-f190c8361404$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4$ff9142ba-3a85-48cf-8b78-07e0b554e280$3e027ede-4ac1-4521-a026-dc00bfca4adf$3e1e2b96-d294-11ef-3a68-fdc78232142e$727dc817-0284-4c0f-9a92-21dcbea50807$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4$ea803646-b18e-4f13-ab6a-fc5080d44e92$9b85a92b-c56b-48a3-97c1-6b1882e33a22$9b92fc89-2036-4525-979b-d296ab29329c$5da42e9a-4318-48ea-9f43-4c1e1c97bceb$bbce1c6f-6f13-4449-9215-bd8ed839a44b$dd31ec7c-708d-4fd7-958d-f9887798a5bc$70d79732-0f55-40ba-929d-fba431318848$4f6dd225-c64d-4b76-b075-0bf71c863b5a$3e185ab0-d294-11ef-3f7d-9bd465518274$3e1d6d00-d294-11ef-1081-e11b8397eb91$a8046381-ff11-40af-ae2b-078d71c586e7$4a81342c-17c7-4eb9-933b-edb98df7b9c4$2156f96e-eebe-4190-8ce9-c76825c6da71last_hot_reload_time        shortpathProbability Theory Review.jlprocess_statusreadypathK/home/runner/work/mlss-2026/mlss-2026/lectures/Probability Theory Review.jlpluto_versionv0.20.19last_save_timeA})ccell_order 5$3e17df5e-d294-11ef-38c7-f573724871d8$bcb4be20-0439-4809-a166-8c50b6b9206b$61713e1c-8e37-45d9-9f58-c3db69e15b66$3e185ab0-d294-11ef-3f7d-9bd465518274$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcaf$41bee964-a0a9-4a7f-8505-54a9ee12ef0d$3e1889b8-d294-11ef-17bb-496655fbd618$3e18b2fa-d294-11ef-1255-df048f0dcec2$3e18c25c-d294-11ef-11bc-a93c2572b107$3e18d2ea-d294-11ef-35e9-2332dd31dbf0$4abbb3de-3b21-4c31-b015-e16c466a20aa$3e18e4bc-d294-11ef-38bc-cb97cb4e0963$3e1ab104-d294-11ef-1a98-412946949fba$fea8ae4c-8ef9-4b74-ad13-1314afef97de$3e1b4b1c-d294-11ef-0423-9152887cc403$3e1b5c9c-d294-11ef-137f-d75b3731eae4$3e1b7d14-d294-11ef-0d10-1148a928dd57$5377c5a4-77c4-4fa7-9f84-0c511e3bf708$3e1b8bf4-d294-11ef-04cc-6364e46fdd64$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0$3e1babca-d294-11ef-37c1-cd821a6488b2$3e1bcb00-d294-11ef-2795-bd225bd00496$3e1bdd02-d294-11ef-19e8-2f44eccf58af$3e1bf116-d294-11ef-148b-f7a1ca3f3bad$16c2eb59-16b8-4347-9aab-6e4b99016c79$3e1d33c8-d294-11ef-0a08-bdc419949925$3e1b05ee-d294-11ef-33de-efed64d01c0d$b176ceae-884e-4460-9f66-020c1ac447f1$922770f4-ddc8-4089-b378-f14088276b43$3e1de32c-d294-11ef-1f63-f190c8361404$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4$ff9142ba-3a85-48cf-8b78-07e0b554e280$3e027ede-4ac1-4521-a026-dc00bfca4adf$3e1e2b96-d294-11ef-3a68-fdc78232142e$727dc817-0284-4c0f-9a92-21dcbea50807$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4$ea803646-b18e-4f13-ab6a-fc5080d44e92$3e1d6d00-d294-11ef-1081-e11b8397eb91$9b85a92b-c56b-48a3-97c1-6b1882e33a22$2156f96e-eebe-4190-8ce9-c76825c6da71$9b92fc89-2036-4525-979b-d296ab29329c$5da42e9a-4318-48ea-9f43-4c1e1c97bceb$bbce1c6f-6f13-4449-9215-bd8ed839a44b$dd31ec7c-708d-4fd7-958d-f9887798a5bc$b305a905-06c2-4a15-8042-72ef6375720f$eeb9a1f5-b857-4843-920b-2e4a9656f66b$5394e37c-ae00-4042-8ada-3bbf32fbca9e$70d79732-0f55-40ba-929d-fba431318848$4f6dd225-c64d-4b76-b075-0bf71c863b5a$a8046381-ff11-40af-ae2b-078d71c586e7$42b47af6-b850-4987-a2d7-805a2cb64e43$a66ab9df-897c-42e5-8b0f-c520ceaffa23$4a81342c-17c7-4eb9-933b-edb98df7b9c4published_objectsnbpkginstall_time_ns   ] instantiatedòinstalled_versionsMarkdownLiteral0.1.3Distributions0.25.123BmlipTeachingTools1.4.1Plots1.41.4PrintfstdlibLaTeXStrings1.4.0terminal_outputsMarkdownLiteral
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
nbpkg_sync
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Distributions
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Plots
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
BmlipTeachingTools
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
Printf
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
LaTeXStrings
[0m[1mWaiting for the package registry to update...[22m
[90m===[39m

[0m[1mResolving...[22m
[90m===[39m
[32m[1m   Installed[22m[39m FillArrays ────── v1.16.0
[32m[1m   Installed[22m[39m JSON ──────────── v1.4.0
[32m[1m   Installed[22m[39m StatsBase ─────── v0.34.10
[32m[1m   Installed[22m[39m MarkdownLiteral ─ v0.1.3
[32m[1m   Installed[22m[39m StructUtils ───── v2.6.2
[32m[1m   Installed[22m[39m libpng_jll ────── v1.6.54+0
[32m[1m   Installed[22m[39m CommonMark ────── v0.10.0
[32m[1m  Installing[22m[39m 1 artifacts
[32m[1m   Installed[22m[39m artifact libpng                   328.7 KiB
[36m[1m     Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Project.toml`
[32m[1m    Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_hydifrkczp/Manifest.toml`
  [90m[a65dc6b1] [39m[92m+ Xorg_libpciaccess_jll v0.19.0+0[39m
  [90m[8e53e030] [39m[92m+ libdrm_jll v2.4.125+1[39m
  [90m[9a156e7d] [39m[92m+ libva_jll v2.23.0+0[39m
  [90m[44cfe95a] [39m[93m↑ Pkg v1.12.0 ⇒ v1.12.1[39m
  [90m[14a3606d] [39m[93m↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4[39m

[0m[1mInstantiating...[22m
[90m===[39m

[0m[1mPrecompiling...[22m
[90m===[39m
enabled÷restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputs 5$9b92fc89-2036-4525-979b-d296ab29329ccell_id$9b92fc89-2036-4525-979b-d296ab29329ccodemd"""
# Summary
"""metadatashow_logsèdisabled®skip_as_script«code_folded$b305a905-06c2-4a15-8042-72ef6375720fcell_id$b305a905-06c2-4a15-8042-72ef6375720fcodeusing BmlipTeachingToolsmetadatashow_logsèdisabled®skip_as_script«code_folded$3e1b7d14-d294-11ef-0d10-1148a928dd57cell_id$3e1b7d14-d294-11ef-0d10-1148a928dd57code%md"""
## Marginalization

Let ``A`` and ``B_1,B_2,\ldots,B_n`` be events, where ``B_1,B_2,\ldots,B_n`` partitions the universe. Then

```math
\sum_{i=1}^n p(A,B_i) = p(A) \,.
```

This rule is called the [law of total probability](https://en.wikipedia.org/wiki/Law_of_total_probability). 

"""metadatashow_logsèdisabled®skip_as_script«code_folded$5377c5a4-77c4-4fa7-9f84-0c511e3bf708cell_id$5377c5a4-77c4-4fa7-9f84-0c511e3bf708code'hide_proof( 
	   md"""
		```math
\begin{align*}
  \sum_i p(A,B_i) &= p\big(\sum_i AB_i\big)  &&\quad \text{(since all $AB_i$ are disjoint)}\\
  &= p\big(A,\sum_i B_i\big) \\
  &= p(A,\Omega) &&\quad \text{($\Omega$ is true event, since $B_i$ are exhaustive)} \\
  &= p(A)
  \end{align*}
```
""")metadatashow_logsèdisabled®skip_as_script«code_folded$3e1b8bf4-d294-11ef-04cc-6364e46fdd64cell_id$3e1b8bf4-d294-11ef-04cc-6364e46fdd64codemd"""
A very practical application of this law is to get rid of a variable that we are not interested in. For instance, if ``X`` and ``Y \in \{y_1,y_2,\ldots,y_n\}`` are discrete variables, then

```math
p(X) = \sum_{i=1}^n p(X,Y=y_i)\,.
```

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1de32c-d294-11ef-1f63-f190c8361404cell_id$3e1de32c-d294-11ef-1f63-f190c8361404codemd"""

##### Problem  

- A bag contains one ball, known to be either white or black. A white ball is put in , and the bag is shaken. Next, a ball is drawn out, which proves to be white. If we now take out another ball, what is the probability it will be white? 


"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e185ab0-d294-11ef-3f7d-9bd465518274cell_id$3e185ab0-d294-11ef-3f7d-9bd465518274codemd"""
##### Problem
  - Given is a disease with a prevalence of $(prevalence_bond) and a test procedure with sensitivity ('true positive' rate) of $(sensitivity_bond), and specificity ('true negative' rate) of $(specificity_bond). What is the chance that somebody who tests positive actually has the disease?

##### Solution
  - [Later in this lecture](#Challenge-Revisited:-Disease-Diagnosis), making use (only) of the sum and product rules of probability theory. 
"""metadatashow_logsèdisabled®skip_as_script«code_folded$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4cell_id$4c639e65-e06b-4c5e-b6e7-aabed6b6c0b4codelhide_solution( 
	   md"""
There are two hypotheses: let ``H = 0`` mean that the original ball in the bag was white and ``H = 1`` that it was black. Assume the prior probabilities are equal, i.e.,
```math
		P(H =0) = 1/2, \quad P(H =1) = 1/2 \,.
```
The data is that when a randomly selected ball was drawn from the bag, which contained a white one and the unknown one, it turned out to be white. The probability of this result according to each hypothesis is:
```math
		P(D|H =0) = 1, \quad P(D|H =1) = 1/2 \,.
```		
So by Bayes theorem, 
```math
\begin{align}
P(H=0|D) &= \frac{P(H=0,D)}{P(D)} \\
    &= \frac{P(D|H=0) P(H=0)}{P(D|H=0) P(H=0) + P(D|H=1) P(H=1)} \\
    &= \frac{1 \cdot \frac{1}{2}}{1 \cdot \frac{1}{2} + \frac{1}{2} \cdot \frac{1}{2}} \\
    &= \frac{2}{3} 
\end{align}
```		
and consequently,  		
```math 
	P(H =1|D) = 1 - P(H =0|D) = \frac{1}{3}
```		
""")metadatashow_logsèdisabled®skip_as_script«code_folded$4a81342c-17c7-4eb9-933b-edb98df7b9c4cell_id$4a81342c-17c7-4eb9-933b-edb98df7b9c4code,n(x; digits=2) = @sprintf("%.*f", digits, x)metadatashow_logsèdisabled®skip_as_script«code_folded$3e1bcb00-d294-11ef-2795-bd225bd00496cell_id$3e1bcb00-d294-11ef-2795-bd225bd00496codermd"""
## $(HTML("<span id='Bayes-rule'>Bayes Rule</span>"))

Consider two variables ``D`` and ``\theta``. It follows from symmetry arguments that 

```math
p(D,\theta)=p(\theta,D)\,,
```

and hence that

```math
p(D|\theta)p(\theta)=p(\theta|D)p(D)\,,
```

or equivalently,

```math
 p(\theta|D) = \frac{p(D|\theta) }{p(D)}p(\theta)\,.\qquad \text{(Bayes rule)}
```

"""metadatashow_logsèdisabled®skip_as_script«code_folded$70d79732-0f55-40ba-929d-fba431318848cell_id$70d79732-0f55-40ba-929d-fba431318848code0md"""
##### Disease diagnosis implementation
"""metadatashow_logsèdisabled®skip_as_script«code_folded$922770f4-ddc8-4089-b378-f14088276b43cell_id$922770f4-ddc8-4089-b378-f14088276b43codeJexercise_statement("Which color does the ball have?"; prefix="Inference ")metadatashow_logsèdisabled®skip_as_script«code_folded$3e027ede-4ac1-4521-a026-dc00bfca4adfcell_id$3e027ede-4ac1-4521-a026-dc00bfca4adfcode5exercise_statement("Causality?"; prefix="Inference ")metadatashow_logsèdisabled®skip_as_script«code_folded$a66ab9df-897c-42e5-8b0f-c520ceaffa23cell_id$a66ab9df-897c-42e5-8b0f-c520ceaffa23codeusing Printfmetadatashow_logsèdisabled®skip_as_script«code_folded$ea803646-b18e-4f13-ab6a-fc5080d44e92cell_id$ea803646-b18e-4f13-ab6a-fc5080d44e92code6challenge_solution("Disease Diagnosis",header_level=1)metadatashow_logsèdisabled®skip_as_script«code_folded$16c2eb59-16b8-4347-9aab-6e4b99016c79cell_id$16c2eb59-16b8-4347-9aab-6e4b99016c79codeNkeyconcept("", md"Bayes rule is the fundamental rule for learning from data!")metadatashow_logsèdisabled®skip_as_script«code_folded$3e1e2b96-d294-11ef-3a68-fdc78232142ecell_id$3e1e2b96-d294-11ef-3a68-fdc78232142ecodecmd"""

##### Problem 

- A dark bag contains five red balls and seven green ones. 
  - (a) What is the probability of drawing a red ball on the first draw? 
- Balls are not returned to the bag after each draw. 
  - (b) If you know that on the second draw the ball was a green one, what is now the probability of drawing a red ball on the first draw?


"""metadatashow_logsèdisabled®skip_as_script«code_folded$b176ceae-884e-4460-9f66-020c1ac447f1cell_id$b176ceae-884e-4460-9f66-020c1ac447f1codemd"""
# Examples
"""metadatashow_logsèdisabled®skip_as_script«code_folded$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4cell_id$fae6f2ce-ac8f-4ea6-b2cf-38b30a7e20d4codemd"""
In this case, knowledge about the future influences our state of knowledge about the present. Once again, we see that conditional probabilities capture implications for a state of knowledge, not temporal causality.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1ab104-d294-11ef-1a98-412946949fbacell_id$3e1ab104-d294-11ef-1a98-412946949fbacodeQmd"""
# $(HTML("<span id='PT-calculus'>Probability Theory Calculus</span>"))

"""metadatashow_logsèdisabled®skip_as_script«code_folded$fea8ae4c-8ef9-4b74-ad13-1314afef97decell_id$fea8ae4c-8ef9-4b74-ad13-1314afef97decodemd"""
## True and False Events

In probability theory, events that are certainly true or certainly false are treated as special cases of general events, and they correspond to probabilities of ``1`` and ``0``, respectively.

Let ``\Omega`` be the sample space, i.e., the set of all possible outcomes of an experiment. Then:
  - The true event corresponds to the entire sample space ``\Omega``.
  - It always happens, regardless of the outcome.
    - For example, for the outcome of a throw of a dice, the sample space is ``\Omega = \{1,2,3,4,5,6\}``.
  - Its probability is
```math
p(\Omega) = 1\,.
```

The false event corresponds to the empty set ``\emptyset``.
  - It never happens (no possible outcomes).
  - Its probability is
```math
p(\emptyset) = 0 \,.
```

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e18d2ea-d294-11ef-35e9-2332dd31dbf0cell_id$3e18d2ea-d294-11ef-35e9-2332dd31dbf0codemd"""
Under these assumptions, Cox showed that any consistent system of reasoning about uncertainty must obey the **rules of probability theory** (see [Cox theorem, 1946](https://en.wikipedia.org/wiki/Cox%27s_theorem), and [Caticha, 2012](https://github.com/bmlip/course/blob/main/assets/files/Caticha-2012-Entropic-Inference-and-the-Foundations-of-Physics.pdf), pp.7-26). These rules are the sum and product rules.



"""metadatashow_logsèdisabled®skip_as_script«code_folded$42b47af6-b850-4987-a2d7-805a2cb64e43cell_id$42b47af6-b850-4987-a2d7-805a2cb64e43code# The Disease Diagnosis example uses a combination of:
# - PlutoUI.Scrubbable for the interactive input percentages
# - MarkdownLiteral to be able to interpolate numbers into markdown math
# - PrintF for consistent formatting
using MarkdownLiteral: @mdxmetadatashow_logsèdisabled®skip_as_script«code_folded$3e1bdd02-d294-11ef-19e8-2f44eccf58afcell_id$3e1bdd02-d294-11ef-19e8-2f44eccf58afcodefmd"""
This last formula is called **Bayes rule**, named after its inventor [Thomas Bayes](https://en.wikipedia.org/wiki/Thomas_Bayes) (1701-1761). While Bayes rule is always true, a particularly useful application occurs when ``D`` refers to an observed data set and ``\theta`` is set of unobserved model parameters. In that case,

  * the **prior** probability ``p(\theta)`` represents our **state-of-knowledge** about proper values for ``\theta``, before seeing the data ``D``.
  * the **posterior** probability ``p(\theta|D)`` represents our state-of-knowledge about ``\theta`` after we have seen the data.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$5da42e9a-4318-48ea-9f43-4c1e1c97bcebcell_id$5da42e9a-4318-48ea-9f43-4c1e1c97bcebcodekeyconceptsummary()metadatashow_logsèdisabled®skip_as_script«code_folded$dd31ec7c-708d-4fd7-958d-f9887798a5bccell_id$dd31ec7c-708d-4fd7-958d-f9887798a5bccodemd"""
# Code
"""metadatashow_logsèdisabled®skip_as_script«code_folded$bbce1c6f-6f13-4449-9215-bd8ed839a44bcell_id$bbce1c6f-6f13-4449-9215-bd8ed839a44bcodeqnavigate_prev_next(
	nothing,
	"https://bertdv.github.io/mlss-2026/lectures/Bayesian%20Machine%20Learning.html"
)metadatashow_logsèdisabled®skip_as_script«code_folded$4abbb3de-3b21-4c31-b015-e16c466a20aacell_id$4abbb3de-3b21-4c31-b015-e16c466a20aacodemd"""

## The Sum and Product Rules 

##### The sum rule

- The degree of belief in the disjunction of two events ``A`` and ``B``, with given background information ``I``, is evaluated as

```math
 p(A+B|I) = p(A|I) + p(B|I) - p(A,B|I)
```

##### The product rule

- The degree of belief in the conjunction of two events ``A`` and ``B``, with given background information ``I``, is evaluated as

```math
 p(A,B|I) = p(A|B,I)\,p(B|I)
```

Cox’s Theorem derives the rules of probability theory from first principles, not as arbitrary postulates but as consequences of rational reasoning. 
In other words: **probability theory = extended logic**.
"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1d33c8-d294-11ef-0a08-bdc419949925cell_id$3e1d33c8-d294-11ef-0a08-bdc419949925codeUmd"""
## Probabilistic Inference

**Probabilistic inference** refers to computing

```math
p(\,\text{whatever-we-want-to-know}\, | \,\text{whatever-we-already-know}\,)
```

For example: 

```math
\begin{align*}
 p(\,\text{Mr.S.-killed-Mrs.S.} \;&|\; \text{he-has-her-blood-on-his-shirt}\,) \\
 p(\,\text{transmitted-codeword} \;&|\;\text{received-codeword}\,) 
  \end{align*}
```

This can be accomplished by repeatedly applying the sum and product rules.

In particular, consider a joint distribution ``p(X,Y,Z)``. Assume we are interested in ``p(X|Z)``:

```math
\begin{align*}
p(X|Z) \stackrel{p}{=} \frac{p(X,Z)}{p(Z)} \stackrel{s}{=} \frac{\sum_Y p(X,Y,Z)}{\sum_{X,Y} p(X,Y,Z)} \,,
\end{align*}
```

where the ``s`` and ``p`` above the equality sign indicate whether the sum or product rule was used. 

In the rest of this course, we'll encounter many lengthy probabilistic derivations. For each manipulation, you should be able to associate an 's' (for sum rule), a 'p' (for product or Bayes rule) or an 'm' (for a simplifying model assumption like conditional independency) above any equality sign.
"""metadatashow_logsèdisabled®skip_as_script«code_folded$4f6dd225-c64d-4b76-b075-0bf71c863b5acell_id$4f6dd225-c64d-4b76-b075-0bf71c863b5acodebegin
	prevalence_bond = @bind prevalence Scrubbable(0:0.01:1; format=".0%", default=0.01)
	sensitivity_bond = @bind sensitivity Scrubbable(0:0.01:1; format=".0%", default=0.95)
	specificity_bond = @bind specificity Scrubbable(0:0.01:1; format=".0%", default=0.85)
end;metadatashow_logsèdisabled®skip_as_script«code_folded$a8046381-ff11-40af-ae2b-078d71c586e7cell_id$a8046381-ff11-40af-ae2b-078d71c586e7codeeresult = (sensitivity * prevalence) / (sensitivity * prevalence + (1 - specificity)*(1 - prevalence))metadatashow_logsèdisabled®skip_as_script«code_folded$3e18c25c-d294-11ef-11bc-a93c2572b107cell_id$3e18c25c-d294-11ef-11bc-a93c2572b107codemd"""
In developing this calculus, only some very agreeable assumptions were made, including:

- Degrees of belief are represented by real numbers.

- Plausibility assessments are consistent, e.g.,
  - if ``A`` becomes more plausible under new information ``B``, the assigned degree-of-belief should increase accordingly.
  - If the belief in ``A`` is greater than the belief in ``B``, and the belief in ``B`` is greater than the belief in ``C``, then the belief in ``A`` must be greater than the belief in ``C``.

- Logical equivalences are preserved, e.g., 
  - If the belief in an event can be inferred in two different ways, for example, either by first updating on information ``I_1`` and then ``I_2`` or the other way around, then the two ways must agree on the resulting belief.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1b05ee-d294-11ef-33de-efed64d01c0dcell_id$3e1b05ee-d294-11ef-33de-efed64d01c0dcode\keyconcept(
	"",
	md"""
	All valid probabilistic relations can be derived from just two fundamental principles: the **sum rule** and the **product rule**. These two rules form the foundation of probability theory, from which more complex constructs such as conditional probabilities, Bayes’ theorem, and marginalization naturally follow.
	
	"""
)metadatashow_logsèdisabled®skip_as_script«code_folded$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafcell_id$840ab4dc-0d2e-4bf8-acc7-5f1ee2b0dcafcode4md"""
# Probability Theory as Rational Reasoning
"""metadatashow_logsèdisabled®skip_as_script«code_folded$2156f96e-eebe-4190-8ce9-c76825c6da71cell_id$2156f96e-eebe-4190-8ce9-c76825c6da71codeif show_disease_diagnosis_solution
	@mdx("""
 <div style="border-left: 4px solid rgba(100,100,100,0.2);padding-left: 1em;">


- The given information is ``p(D=1)=$(n(prevalence))``, ``p(T=1|D=1)=$(n(sensitivity))`` and ``p(T=0|D=0)=$(n(specificity))``. We are asked to derive ``p( D=1 | T=1)``. We just follow the sum and product rules to derive the requested probability:

```math
\\begin{align*}
p( D=1 &| T=1) \\\\
&\\stackrel{p}{=} \\frac{p(T=1,D=1)}{p(T=1)} \\\\
&\\stackrel{p}{=} \\frac{p(T=1|D=1)p(D=1)}{p(T=1)} \\\\
&\\stackrel{s}{=} \\frac{p(T=1|D=1)p(D=1)}{p(T=1|D=1)p(D=1)+p(T=1|D=0)p(D=0)} \\\\
&= \\frac{$(n(sensitivity))\\times$(n(prevalence))}{$(n(sensitivity))\\times$(n(prevalence)) + $(n(1 - specificity))\\times$(n(1 - prevalence))} = \\boldsymbol{$(n(result; digits=4))}
\\end{align*}
```


Note that ``p(\\text{sick}|\\text{positive test}) = $(n(result))`` while ``p(\\text{positive test} | \\text{sick}) = $(n(sensitivity))``. This is a huge difference that is sometimes called the "medical test paradox" or the [base rate fallacy](https://en.wikipedia.org/wiki/Base_rate_fallacy). 

Many people have trouble distinguishing ``p(A|B)`` from ``p(B|A)`` in their heads. This has led to major negative consequences. For instance, unfounded convictions in the legal arena and numerous unfounded conclusions in the pursuit of scientific results. See [Ioannidis (2005)](https://journals.plos.org/plosmedicine/article?id=10.1371/journal.pmed.0020124) and [Clayton (2021)](https://aubreyclayton.com/bernoulli).

""")
endmetadatashow_logsèdisabled®skip_as_script«code_folded$3e1bf116-d294-11ef-148b-f7a1ca3f3badcell_id$3e1bf116-d294-11ef-148b-f7a1ca3f3badcodeomd"""

Bayes rule tells us how to update our knowledge about model parameters when facing new data. Hence, 
"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0cell_id$3e1b9ba8-d294-11ef-18f2-db8eed3d87d0codeٹmd"""
Summing ``Y`` out of a joint distribution ``p(X,Y)`` is called **marginalization** and the result ``p(X)`` is sometimes referred to as the **marginal probability** of ``X``. 

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1889b8-d294-11ef-17bb-496655fbd618cell_id$3e1889b8-d294-11ef-17bb-496655fbd618codemd"""
## Probability as a Degree-of-Belief

In the real world, we are rarely completely certain about anything. Rather than assigning a binary truth value to a proposition ``A``, we associate it with a degree of belief 
```math
0 \leq p(A) \leq 1 \,,
```
which quantifies how likely we believe ``A`` is to be true.


Consider the truth value of the proposition 
```math
A = \texttt{``there is life on Mars''}
```

with 

```math
I = \texttt{``All known life forms require water''}
```

as background information. Now, assume that a new piece of information 

```math
B = \texttt{``There is water on Mars''}
```

becomes available, how **should** our degree of belief in event ``A`` be affected *if we were rational*? 

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e17df5e-d294-11ef-38c7-f573724871d8cell_id$3e17df5e-d294-11ef-38c7-f573724871d8code"title("Probability Theory Review")metadatashow_logsèdisabled®skip_as_script«code_folded$ff9142ba-3a85-48cf-8b78-07e0b554e280cell_id$ff9142ba-3a85-48cf-8b78-07e0b554e280codeumd"""
Note that the physical state of the bag—either containing one black ball or one white ball—remains unchanged after the “put one in, take one out” procedure.
Yet, the probability we assign to the color of the ball in the bag changes.
This illustrates a key point: probabilities describe a person’s state of knowledge, not an intrinsic property of nature.
"""metadatashow_logsèdisabled®skip_as_script«code_folded$61713e1c-8e37-45d9-9f58-c3db69e15b66cell_id$61713e1c-8e37-45d9-9f58-c3db69e15b66code7challenge_statement("Disease Diagnosis",header_level=1)metadatashow_logsèdisabled®skip_as_script«code_folded$41bee964-a0a9-4a7f-8505-54a9ee12ef0dcell_id$41bee964-a0a9-4a7f-8505-54a9ee12ef0dcodemd"""
## Propositional (Boolean) Logic 

Define an **event** (or "proposition") ``A`` as a statement that can be considered for its truth by a person. For instance, 

```math
𝐴= \texttt{``there is life on Mars''}
```

Boolean logic (or propositional logic) is a formal system of logic based on binary truth values: every proposition is either true (with assigned value ``1``) or false (with assigned value ``0``). It is named after George Boole, who developed the algebraic formulation of logic in the mid-19th century.

With Boolean operators (``\lor``, ``\land``, ``\implies``, etc.), we can create and evaluate compound propositions, e.g.,

- Given two events ``A`` and ``B``, the **conjunction** (logical-and) 
```math
A \land B
```
is true if-and-only-if both ``A`` and ``B`` are true. We write ``A \land B`` also shortly as ``AB`` (or use a comma as in a joint probability distribution ``p(A,B)``). 

- The **disjunction** (logical-or) 
```math
A \lor B
```
is true if either ``A`` or ``B`` is true or both ``A`` and ``B`` are true. We write ``A \lor B`` also as ``A + B`` (Note that the plus-sign is here not an arithmetic operator, but rather a logical operator to process truth values.)

- The denial of ``A``, i.e., the event **not**-A, is written as 
```math
\bar{A}\,.
```

Boolean logic provides the rules of inference for **deductive reasoning** and underpins all formal reasoning systems in mathematics and philosophy. 
"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1d6d00-d294-11ef-1081-e11b8397eb91cell_id$3e1d6d00-d294-11ef-1081-e11b8397eb91codemd"""
##### Problem 

- Given a disease ``D \in \{0, 1\}`` with prevalence (overall occurence percentage) of $(prevalence_bond) and a test procedure ``T  \in \{0, 1\}`` with sensitivity (true positive rate) of $(sensitivity_bond) and specificity (true negative' rate) of $(specificity_bond), what is the chance that somebody who tests positive actually has the disease?

_The percentages are interactive! **Click and drag** to change the values._

"""metadatashow_logsèdisabled®skip_as_script«code_folded$bcb4be20-0439-4809-a166-8c50b6b9206bcell_id$bcb4be20-0439-4809-a166-8c50b6b9206bcodePlutoUI.TableOfContents()metadatashow_logsèdisabled®skip_as_script«code_folded$3e18b2fa-d294-11ef-1255-df048f0dcec2cell_id$3e18b2fa-d294-11ef-1255-df048f0dcec2code<md"""

## Richard Cox and the Calculus of Rational Reasoning

[Richard T. Cox (1946)](https://aapt.scitation.org/doi/10.1119/1.1990764) developed a **calculus for rational reasoning** about how to represent and update the **degree-of-belief** about the truth value of an event when faced with new information.  

"""metadatashow_logsèdisabled®skip_as_script«code_folded$5394e37c-ae00-4042-8ada-3bbf32fbca9ecell_id$5394e37c-ae00-4042-8ada-3bbf32fbca9ecodeusing Distributionsmetadatashow_logsèdisabled®skip_as_script«code_folded$3e1b5c9c-d294-11ef-137f-d75b3731eae4cell_id$3e1b5c9c-d294-11ef-137f-d75b3731eae4codemd"""
We mentioned before that every inference problem in PT can be evaluated through the sum and product rules. Next, we present two useful corollaries: (1) *Marginalization* and (2) *Bayes rule*. 

"""metadatashow_logsèdisabled®skip_as_script«code_folded$727dc817-0284-4c0f-9a92-21dcbea50807cell_id$727dc817-0284-4c0f-9a92-21dcbea50807code*hide_solution( 
md"""

(a) ``p(S_1=R) = \frac{N_\text{red}}{N_\text{red}+N_\text{green}} = \frac{5}{12}``
	
(b) The outcome of the ``n``-th draw is referred to by ``S_n``. Use Bayes rule to get,	
```math
\begin{align}
p(S_1=\text{R} | S_2=\text{G}) &= \frac{p(S_2=\text{G} | S_1=\text{R}) p(S_1=\text{R})} {p(S_2=\text{G} | S_1 = \text{R}) p(S_1=\text{R}) + p(S_2=\text{G} | S_1=\text{G}) p(S_1=\text{G})} \\
    &= \frac{\frac{7}{11}\cdot\frac{5}{12}}{\frac{7}{11}\cdot\frac{5}{12}+\frac{6}{11}\cdot\frac{7}{12}} \\
	&= \frac{5}{11}
\end{align}
```
""")metadatashow_logsèdisabled®skip_as_script«code_folded$eeb9a1f5-b857-4843-920b-2e4a9656f66bcell_id$eeb9a1f5-b857-4843-920b-2e4a9656f66bcodeusing Plots, LaTeXStringsmetadatashow_logsèdisabled®skip_as_script«code_folded$9b85a92b-c56b-48a3-97c1-6b1882e33a22cell_id$9b85a92b-c56b-48a3-97c1-6b1882e33a22codeي@htl """
<label style="font-weight: bold;">
Show solution? $(@bind(show_disease_diagnosis_solution, CheckBox(default=false)))
</label>
"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1babca-d294-11ef-37c1-cd821a6488b2cell_id$3e1babca-d294-11ef-37c1-cd821a6488b2codemd"""
Note that marginalization can be understood as applying a "generalized" sum rule. Bishop (p.14) and some other authors also refer to this as the sum rule, but we do not follow that terminology.

"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e1b4b1c-d294-11ef-0423-9152887cc403cell_id$3e1b4b1c-d294-11ef-0423-9152887cc403codemd"""
## Independent, Exclusive, and Exhaustive Events

It will be helpful to introduce some terms concerning special relationships between events.  

##### Joint events

The expression ``p(A,B)`` for the probability of the conjuction ``A \land B`` is also called the **joint probability** of events ``A`` and ``B``. Note that 

```math
p(A,B) = p(B,A)\,,
```

since ``A\land B = B \land A``. Therefore, the order of arguments in a joint probability distribution does not matter: ``p(A,B,C,D) = p(C,A,D,B)``, etc.

##### Independent events

Two events ``A`` and ``B`` are said to be **independent** if the probability of one event is not altered by information about the truth of the other event, i.e., 

```math
p(A|B) = p(A)\,.
```

It follows that, if ``A`` and ``B`` are independent, then the product rule simplifies to 

```math
p(A,B) = p(A) p(B)\,.
```

``A`` and ``B`` with given background ``I`` are said to be **conditionally independent** for given ``I``, if 

```math
p(A|B,I) = p(A|I)\,.
```

In that case, the product rule simplifies to ``p(A,B|I) = p(A|I) p(B|I)``.

##### Mutually exclusive events

Two events ``A_1`` and ``A_2`` are said to be **mutually exclusive** ('disjoint') if they cannot be true simultaneously, i.e., if

```math
p(A_1,A_2)=0 \,.
```

For mutually exclusive events, probabilities add (this follows from the sum rule), hence 

```math
p(A_1 + A_2) = p(A_1) + p(A_2)
```

##### Collectively exhaustive events

A set of events ``A_1, A_2, \ldots, A_N`` is said to be **collectively exhaustive** if one of the statements is necessarily true, i.e., ``A_1+A_2+\cdots +A_N=\mathrm{TRUE}``, or equivalently 

```math
p(A_1+A_2+\cdots +A_N) = 1 \,.
```

##### Partitioning the universe

If a set of events ``A_1, A_2, \ldots, A_n`` is both **mutually exclusive** and **collectively exhaustive**, then we say that they **partition the universe**. Technically, this means that 

```math
\sum_{n=1}^N p(A_n) = p(A_1 + \ldots + A_N) = 1
```



"""metadatashow_logsèdisabled®skip_as_script«code_folded$3e18e4bc-d294-11ef-38bc-cb97cb4e0963cell_id$3e18e4bc-d294-11ef-38bc-cb97cb4e0963codekeyconcept(" ", 
	md"""
	
	When real numbers are used to represent **degrees of belief**, logical consistency enforces the sum and product rules of probability theory, making probability theory the optimal framework for information processing under uncertainty.

	
	"""
)metadatashow_logsèdisabled®skip_as_script«code_foldedënotebook_id$fd36be32-455e-11f1-9b4f-41e8110bd73ain_temp_dir¨metadatafrontmatterauthornameBMLIPurlhttps://github.com/bmlipdescription[Review of probability theory as a foundation for rational reasoning and Bayesian inference.