https://en.wikipedia.org/wiki/Poisson_distribution#Generating_Poisson-distributed_random_variables
https://www.johndcook.com/blog/2010/06/14/generating-poisson-random-values/
https://hpaulkeeler.com/simulating-poisson-random-variables-direct-method/
Here’s the idea behind the algorithm. The time between arrivals in a Poisson process is exponentially distributed. Count how many arrivals there are in an interval by simulating the times between arrivals and adding them up until the time sum spills over the interval.
泊松过程的到达时间是指数分布的。通过模拟到达之间的时间来计算一个间隔内有多少到达,并将它们相加,直到时间总和溢出该间隔
第一个到达的时间是x1 ,第二个达到与第一个到达的时间是x2,........则的数量(在单位时间内有多少个到达)有多少个;
而服从泊松分布的时间间隔服从指数分布:
x1 是一个服从指数分布的随机变量,
已知分布概率,如何以此概率生成服从此分布的随机变量?
https://blog.csdn.net/zhxue123/article/details/3859512
指数分布的概率密度函数 y=lamda*exp(-lamda*x) x>=0
由此可以计算概率分布函数 y=1-exp(-lamda*x) x>=0
y是 X<x的概率,其取值在区间(0,1)内
首先,把y当作是在(0,1)区间的均匀分布的随机变量。
然后,求y=1-exp(-lamda*x)的逆函数,x=-(1/lamda)*ln(1-y)
令z=1-y,显然z也是(0,1)区间的均匀分布的随机变量,于是就有x=-(1/lamda)*ln(z)。
But, as I said before, don’t use this code instead of the inbuilt function poissrnd.