从零构建统计随机变量生成器之泊松分布

http://www.columbia.edu/~ks20/4404-Sigman/4404-Notes-ITM.pdf

https://www.win.tue.nl/~marko/2WB05/lecture8.pdf

泊松分布

1
2
3
4
5
6
7
8
9
10
11
12
13
import random
from math import exp


def poisson(lambdda: float) -> int:
total = 1.0
i = 0
threshold = exp(-1 * lambdda)
while total >= threshold:
u = random.random()
total *= u
i += 1
return i - 1

https://github.com/MyEncyclopedia/stats_simulation/blob/main/distrib_sim/discrete_poisson_inv.py

1
2
3
4
5
6
7
8
9
10
from numpy.random import exponential

def poisson(lambdda: float) -> int:
total = 0.0
i = 0
while total <= lambdda:
y = exponential(1)
total += y
i += 1
return i - 1

https://github.com/MyEncyclopedia/stats_simulation/blob/main/distrib_sim/discrete_poisson_from_exp.py

泊松分布

$ E_{1}, E_{2}, E_{3}, (1) $

\[ \mathbb{P}(K \geqslant k)=\mathbb{P}\left(E_{1}+\cdots+E_{k} \leqslant \lambda\right) \]

1
2
3
4
5
6
7
8
9
10
from numpy.random import exponential

def poisson(lambdda: float) -> int:
total = 0.0
i = 0
while total <= lambdda:
y = exponential(1)
total += y
i += 1
return i - 1

Github 代码地址:

https://github.com/MyEncyclopedia/stats_simulation/blob/main/distrib_sim/discrete_poisson_from_exp.py

用逆变换采样方法构建随机变量生成器 解读TRPO论文,一种深度强化学习和传统优化方法结合的方法

Author and License Contact MyEncyclopedia to Authorize
myencyclopedia.top link https://blog.myencyclopedia.top/zh/2021/distribution-poisson/
github.io link https://myencyclopedia.github.io/zh/2021/distribution-poisson/

You need to set install_url to use ShareThis. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×