Skip to content

Commit

Permalink
add note
Browse files Browse the repository at this point in the history
add bayes theorem  category
  • Loading branch information
math4mad committed Oct 12, 2023
1 parent c6e0f7d commit b70cdbe
Show file tree
Hide file tree
Showing 12 changed files with 771 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
.RData
.Ruserdata
/.quarto/
/_freeze/
docs
2 changes: 1 addition & 1 deletion _freeze/turing/5-multi-side-dice/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ website:
text: GitHub
style: docked



contents:
- href: index.qmd
text: Home
Expand All @@ -25,6 +27,8 @@ website:
contents: turing/*
- section : "Basic"
contents: basic/*
- section : "BayesTheorem"
contents: bayestheorem/*

format:
html:
Expand Down
12 changes: 12 additions & 0 deletions basic/3-reference-test.qmd
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
42 changes: 42 additions & 0 deletions basic/4-revealjs-test.qmd
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`

:::
15 changes: 15 additions & 0 deletions bayestheorem/1.qmd
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 的流程相同
99 changes: 99 additions & 0 deletions bayestheorem/2.qmd
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)}$$









Loading

0 comments on commit b70cdbe

Please sign in to comment.