格式调试大集合

测试格式

文字计数功能

正文
随便写点东西

格式测试

加粗test
横线test
斜体test

  • list
  • list
  1. Sorted list
  2. Sorted list
  3. Sorted list

代码格式测试

1
2
test
test 中文
1
2
3
$ hexo new post First_Test
INFO Validating config
INFO Created: D:\<user name>\source\_posts\2023-06-25-First-Test.md
1
2
import os
print('hello world')

测试标题

标题二

标题三

标题四

标题五

测试数学公式

测试用公式1

m=(n)pm= _{(n)}p

n  (mp)n\ |\ (m-p)

mp=knm-p=kn

As kk is an integer.
There must exist a kk that satisfied:

k=mnpnk = \lfloor \frac{m}{n} \rfloor - \lfloor \frac{p}{n} \rfloor

mp=(mnpn)nmmnn=ppnnm%n=p%n\begin{aligned} m-p &= (\lfloor \frac{m}{n} \rfloor - \lfloor \frac{p}{n} \rfloor) n\\ m - \lfloor \frac{m}{n} \rfloor n &= p - \lfloor \frac{p}{n} \rfloor n\\ m\%n &= p\%n \end{aligned}

测试用公式2

h(θX)f(Xθ)τ(θ)h(\theta|X) \propto f(X|\theta)\tau(\theta)

First we should figure out f(Xθ)f(X|\theta).

f(Xθ)=f(x1,x2,,xnθ)=f(x1θ)f(x2θ)f(xnθ)=i=1n1xi!eθθxi=(i=1n1xi!)enθθi=1nxi\begin{aligned} f(X|\theta) &= f(x_1,x_2,\cdots,x_n|\theta)\\ &= f(x_1|\theta) \cdot f(x_2|\theta) \cdots f(x_n|\theta)\\ &= \prod_{i=1}^n \frac{1}{x_i !} e^{-\theta}\theta^{x_i}\\ &= \left(\prod_{i=1}^n \frac{1}{x_i !}\right) e^{-n \theta}\theta^{\sum_{i=1}^n x_i} \end{aligned}

Therefore,

h(θX)f(Xθ)τ(θ)(θα1eθ/β)(enθθi=1nxi)=θα+i=1nxi1eθ(n+1β)=θα+i=1nxi1eθ/(βnβ+1)\begin{aligned} h(\theta|X) &\propto f(X|\theta)\tau(\theta)\\ &\propto (\theta^{\alpha-1}e^{-\theta/\beta}) \cdot (e^{-n \theta}\theta^{\sum_{i=1}^n x_i})\\ &= \theta^{\alpha+\sum_{i=1}^n x_i -1} \cdot e^{-\theta(n+\frac{1}{\beta})}\\ &= \theta^{\alpha+\sum_{i=1}^n x_i -1} \cdot e^{-\theta/(\frac{\beta}{n\beta+1})} \end{aligned}

Therefore, the posterior distribution for θ\theta is :

Gamma(α+i=1nxi , βnβ+1)Gamma \left(\alpha+\sum_{i=1}^n x_i\ ,\ \frac{\beta}{n\beta+1} \right)

例题

A single die is tossed; then nn coins are tossed where nn is the number shown on the die. Show that the probability of exactly two heads is close to 0.2578.
参考答案
We will sum up the probabilities of getting exactly two heads for each possible outcome of the die roll (1 through 6). Assume the first number rolled was NN.

P(X=2)=P(X=2N=1)+P(X=2N=2)+P(X=2N=3)+P(X=2N=4)+P(X=2N=5)+P(X=2N=6)\begin{aligned} P(X=2) &= P(X=2 \cap N=1) + P(X=2 \cap N=2) + P(X=2 \cap N=3) \\ &+ P(X=2 \cap N=4) + P(X=2 \cap N=5) + P(X=2 \cap N=6) \end{aligned}

The probability of getting exactly two heads when tossing nn coins can be found using the binomial probability formula, which is given by:

P(X=k)=(nk)pk(1p)nkP(X=k) =\tbinom{n}{k}p^k(1-p)^{n-k}

(nk)\tbinom{n}{k} is the binomial coefficient, which calculates the number of ways to choose kk successes out of nn trials.

  • pp is the probability of success, for toss a coin which is 12\frac{1}{2}.
  • nn is the number of trials.
  • kk is the number of successes, in this question means two heads.
  • Only when n2n \geq 2, PP makes sense.

Therefore, We can have

P(X=2)=P(X=2N=1)+P(X=2N=2)+P(X=2N=3)+P(X=2N=4)+P(X=2N=5)+P(X=2N=6)=16((22)(12)2+(32)(12)3+(42)(12)4+(52)(12)5+(62)(12)6)=0.2578\begin{aligned} P(X=2) &= P(X=2 \cap N=1) + P(X=2 \cap N=2) + P(X=2 \cap N=3) \\ &+ P(X=2 \cap N=4) + P(X=2 \cap N=5) + P(X=2 \cap N=6)\\ &= \frac{1}{6}\left( \tbinom{2}{2}(\frac{1}{2})^2 + \tbinom{3}{2}(\frac{1}{2})^3 + \tbinom{4}{2}(\frac{1}{2})^4 + \tbinom{5}{2}(\frac{1}{2})^5 + \tbinom{6}{2}(\frac{1}{2})^6\right)\\ &= 0.2578 \end{aligned}