如何生成泊松过程?
原始问题:
我想生成一个泊松过程。 如果按时间 t 到达的人数为 N(t) 并且我有参数为 λ 的泊松分布,我如何生成 N(t)? 我将如何在 C++ 中做到这一点?
澄清:
我最初想使用泊松分布生成过程。 但是,我对我需要的过程参数感到困惑; 我以为我可以使用 N(t) 但这告诉我在间隔 (0,t] 内发生了多少次到达,这不是我想要的。所以,然后我想我可以使用 N(t2)-N(t1) 来获取区间 [t1,t2] 以来的到达次数。 但我不想要一个时间间隔内的到达数量。
t)~Poisson(tx λ) 我可以使用Poisson(t2 x λ)-Poisson(t1 x λ) , ,我想生成到达发生的明确时间,
我可以通过使间隔 [t2,t1] 足够小,以便每个间隔只有一个到达(出现为 )来实现。 |t2-t1| -> 0)。
Original Question:
I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter λ how do I generate N(t)? How would I do this in C++?
Clarification:
I originally wanted to generate the process using a Poisson distribution. But, I was confused about what parameter from the process I needed; I thought I could use N(t) but that tells me how many arrivals have occurred on the interval (0,t] which wasn't what I wanted. So, then I thought I could use N(t2)-N(t1) to get the number of arrivals on the interval [t1,t2]. Since N(t)~Poisson(t x λ) I could use Poisson(t2 x λ)-Poisson(t1 x λ) but I don't want the number of arrivals in an interval.
Rather, I want to generate the explicit times that arrivals occur at.
I could do this by making the interval [t2,t1] sufficiently small so that each interval has only one arrival (which occurs as |t2-t1| -> 0).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您有一个速率参数为 L 的泊松过程(意味着从长远来看,每秒有 L 个到达),则到达间隔时间呈指数分布,平均值为 1/L。 因此 PDF 为 f(t) = -L*exp(-Lt),CDF 为 F(t) = Prob(T < t) = 1 - exp(-Lt)。 所以你的问题变成:如何生成分布为 F(t) = 1 - \exp(-Lt) 的随机数 t?
假设您使用的语言有一个函数(我们称之为 rand())来生成 0 到 1 之间均匀分布的随机数,则逆 CDF 技术简化为计算:
由于 python 提供了一个函数来生成指数分布的随机数,您可以以每秒 15 次到达的平均速率模拟泊松过程中的前 10 个事件,如下所示:
请注意,这将生成*间隔*到达时间。 如果您想要到达时间,则必须继续向前移动时间变量,如下所示:
If you have a Poisson process with rate parameter L (meaning that, long term, there are L arrivals per second), then the inter-arrival times are exponentially distributed with mean 1/L. So the PDF is f(t) = -L*exp(-Lt), and the CDF is F(t) = Prob(T < t) = 1 - exp(-Lt). So your problem changes to: how to I generate a random number t with distribution F(t) = 1 - \exp(-Lt)?
Assuming the language you are using has a function (let's call it
rand()
) to generate random numbers uniformly distributed between 0 and 1, the inverse CDF technique reduces to calculating:As python provides a function to generate exponentially distributed random numbers, you could simulate the first 10 events in a poisson process with an averate rate of 15 arrivals per second like this:
Note that that would generate the *inter*arrival times. If you wanted the arrival times, you would have to keep moving a time variable forward like this:
以下是使用 C++ TR1 生成泊松样本的示例代码。
如果您想要泊松过程,则到达之间的时间呈指数分布,并且可以使用逆 CDF 方法轻松生成指数值:-k*log(u),其中 u 是均匀随机变量,k 是是指数的平均值。
Here's sample code for generating Poisson samples using C++ TR1.
If you want a Poisson process, times between arrivals are exponentially distributed, and exponential values can be generated trivially with the inverse CDF method: -k*log(u) where u is a uniform random variable and k is the mean of the exponential.
我会非常小心地使用逆 CDF 并通过它泵送均匀随机数。 这里的问题是,逆 CDF 通常在数值上不稳定,或者生成它的函数可能会在区间末端附近产生不希望有的波动。 出于这个原因,我会推荐类似“C 中的数值食谱”中使用的拒绝方法。 请参阅 NRC 第 7.3 章中给出的 poidev 函数: http://www.nrbook .com/a/bookcpdf/c7-3.pdf
I would be very careful about using the inverse CDF and pumping a uniform random number through it. The problem here is that often the inverse CDF is numerically unstable or the functions to produce it can give undesirable fluctuations near the ends of the interval. For that reason I would recommend something like the rejection method used in "Numerical Recipes in C". See the poidev function given in ch 7.3 of NRC: http://www.nrbook.com/a/bookcpdf/c7-3.pdf
为了从分布中选取样本,您需要计算逆累积分布函数 (CDF)。 首先在实数区间 [0, 1] 上均匀地选取一个随机数,然后取该值的逆 CDF。
In order to pick a sample from a distribution, you need to compute the inverse cumulative distribution function (CDF). You first pick a random number uniformly on the real interval [0, 1], and then take the inverse CDF of that value.
如果您使用的是 python,则可以使用 random.expovariate(rate) 生成每个时间间隔的速率事件的到达时间
If you are using python, you can use random.expovariate(rate) to generate arrival times at rate events per time interval
通过泊松过程生成到达时间并不意味着使用泊松分布。 它是通过基于泊松到达率 lamda 创建指数分布来完成的。
简而言之,您需要生成平均值 = 1/lamda 的指数分布,请参阅以下示例:
运行此代码的结果:
因此,根据您的实验,您可以使用:newArrivalTime 或 sumArrivalTimes。
Generating arrival times via Poisson Process does not mean using a Poisson distribution. It is done by creating an exponential distribution based on the Poisson arrival rate lamda.
In short, you need to generate an exponential distribution with an average = 1/lamda, see the following example:
The result of running this code:
so, based on your experiment you can either use: newArrivalTime or sumArrivalTimes.
这里的讨论包含有关使用逆采样生成内部到达的所有细节,这通常是人们想要为游戏做的事情。
https://stackoverflow.com/a/15307412/1650437
The discussion here has all the details about using inverse sampling to generate inter-arrivals, which is usually what people want to do for games.
https://stackoverflow.com/a/15307412/1650437
在Python中,你可以尝试下面的代码。
如果你想在 60 秒内生成 20 个随机读数。 即(20 是 lambda)
In python, you can try below code.
If you want to generate 20 random readings in 60 seconds. ie (20 is the lambda)