generated from Pakillo/quarto-course-website-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bayes theorem category
- Loading branch information
Showing
12 changed files
with
771 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
.RData | ||
.Ruserdata | ||
/.quarto/ | ||
/_freeze/ | ||
docs |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: "3-reference-test" | ||
bibliography: ../references.bib | ||
#csl: ../nature.csl | ||
--- | ||
|
||
|
||
参见 @pml1Book | ||
|
||
参见 @gpml | ||
|
||
参见 @bishop2006pattern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: "reveal.js test" | ||
author: math4mad | ||
format: | ||
revealjs: | ||
chalkboard: true | ||
transition: slide | ||
--- | ||
|
||
## {background-color="aquamarine"} | ||
- Turn off alarm | ||
- Get out of bed | ||
|
||
```{.julia code-line-numbers="4"} | ||
c2=c3=1//3 | ||
c2g1=1 | ||
c3g1=1//2 | ||
p1=c2*c2g1;p2=c3*c3g1 | ||
total= p1+p2 | ||
"绿色牌面来自第二张牌的概率为"=>p1//total | ||
``` | ||
|
||
::: aside | ||
Some additional commentary of more peripheral interest. | ||
::: | ||
|
||
--- | ||
|
||
- Get in bed | ||
- Count sheep | ||
|
||
::: {.panel-tabset} | ||
|
||
### Tab A | ||
|
||
Content for `Tab A` | ||
|
||
### Tab B | ||
|
||
Content for `Tab B` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: "1-introtduction" | ||
--- | ||
|
||
> based on Bayes Theorem Examples - A Visual Guide For Beginners by Scott Hartshorn | ||
## 解决问题的流程为: | ||
|
||
1. 根据提示,判断我们想要得到的概率是什么,观测值是什么 | ||
2. 列出所有可能答案的初始概率值 | ||
3. 对于每个初始概率值,在假定为真的条件下计算获得观测值的概率 | ||
4. 2.3 步的概率相乘得到每种情况下得到观测值的概率 | ||
5. 标准化结果(所有能获得观测值概率和为 1) | ||
|
||
基本流程实际和 afcp 的流程相同 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
title: "2-dice-problem" | ||
--- | ||
|
||
:::{.callout-note title="简介"} | ||
你的朋友有三个骰子 1:4面, 2: 6面,3:8面 | ||
|
||
如果他随机取出一个骰子, 扔出的点数为 `2`, 那么这个骰子是三个其中之一的概率分别 | ||
为多少? | ||
::: | ||
|
||
|
||
## 1. 根据提示列出概率值 | ||
为了直观,仍然使用概率路径图 | ||
|
||
```{mermaid} | ||
%%| label: fig-1 | ||
%%| fig-cap: "three dice" | ||
%%| fig-width: 6.5 | ||
flowchart LR | ||
Dices["🎲"] | ||
Dices==d4:1/3==>dice4("4 sides dice") | ||
Dices==d6:1/3==>dice6("6 sides dice") | ||
Dices==d8:1/3==>dice8("8 sides dice") | ||
dice4==d42:1/4==>digit21("2️⃣") | ||
dice6==d62:1/6==>digit22("2️⃣") | ||
dice8==d82:1/8==>digit23("2️⃣") | ||
``` | ||
|
||
## 2. 计算获得观测值的概率 | ||
|
||
从 @fig-1 可以看到能观测到 2点的值, 每个骰子都有机会 | ||
|
||
4 面的骰子获得2️⃣ 的概率为: | ||
$$d4*d42=\frac{1}{3}*\frac{1}{4} \tag{1.1}$$ | ||
|
||
6面的骰子获得2️⃣ 的概率为: | ||
$$d6*d62=\frac{1}{3}*\frac{1}{6} \tag{1.2}$$ | ||
|
||
|
||
8面的骰子获得2️⃣ 的概率为: | ||
$$d8*d82=\frac{1}{3}*\frac{1}{8} \tag{1.3}$$ | ||
|
||
|
||
全概率为以上三个概率的和 | ||
$$total=d4*d42+d6*d62+d8*d82$$ | ||
|
||
当点数为2️⃣ 的条件下为 4 面骰子的概率为: | ||
$$\frac{d4*d42}{d4*d42+d6*d62+d8*d82} \tag{2.1}$$ | ||
|
||
当点数为2️⃣ 的条件下为 6 面骰子的概率为: | ||
$$\frac{d6*d62}{d4*d42+d6*d62+d8*d82} \tag{2.2}$$ | ||
|
||
|
||
当点数为2️⃣ 的条件下为 8 面骰子的概率为: | ||
$$\frac{d8*d82}{d4*d42+d6*d62+d8*d82} \tag{2.3}$$ | ||
|
||
|
||
## 3 计算 | ||
### 3.1 直接计算 | ||
```{julia} | ||
d4,d6,d8=1//3,1//3,1//3 | ||
d42=1//4;d62=1//6;d82=1//8 | ||
p1=d4*d42;p2=d6*d62;p3=d8*d82 | ||
total=p1+p2+p3 | ||
@info "当点数为 2 时" | ||
"4 面骰子概率"=> p1//total,"6面骰子概率"=> p2//total,"8面骰子"=> p3//total | ||
``` | ||
|
||
### 3.2 使用 DatFrame 进行计算 | ||
```{julia} | ||
using DataFrames,PrettyTables | ||
c1=["4","6️","8️"] | ||
c2=[1//3,1//3,1//3] | ||
c3=[1//4,1//6,1//8] | ||
df=DataFrame(step1=c1,step2=c2,step3=c3) | ||
transform!(df, [:step2, :step3] => ByRow(*) => :step4) | ||
total=sum(df[:,:step4]) | ||
transform!(df, [:step4] => ByRow(x->(x//total)) => :step5) | ||
@pt df | ||
``` | ||
|
||
## 4 贝叶斯公式 | ||
公式 (2.1,2.2,2.3) 就是贝叶斯公式的实例 | ||
以 4 面骰子为例 | ||
|
||
$$P(四面骰子|点数为 2)=\frac{P(四面骰子)*P(点数为2|四面骰子)}{P(点数为2)}$$ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.