如何模拟泊松到达?
我想生成以“t”秒“到达”作为平均到达间隔延迟的事件?从时间 0 开始,如何生成事件发生的时间?基本上,我想在事件发生时生成时间序列,例如 t1、t2、t3...。我该如何编写这样的函数?
谢谢。
I want to generate events that "arrive" with "t" seconds as mean inter-arrival delay? Starting at time 0, how do I generate the times when the event occurs? Basically, I want to generate sequence of times such as t1, t2, t3, ... when the event occurs. How do I write such a function?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你没有说是什么语言 - 但看看 生成(泊松?)实时随机变量
You don't say what language - but take a look at Generate (Poisson?) random variable in real-time
最简单的解决方案是计算下一个事件的时间
关于“L”到达间隔延误。这是根据累计
指数分布函数:F(x) = 1 - e**(-lambda * x)
其中 lambda 是 1/L(平均时间),x 是时间量。
这可以求解 x 并输入统一的随机数:
x = -ln(1-U)/lambda,其中 U 是随机值 0..1。
从链接 1:
此链接提供了大量有关如何操作的信息以及示例
如何为泊松过程生成随机计时
请注意,还有其他可以使用的概率分布函数
用于事件生成(均匀、三角形等)。其中许多可以是
通过 Boost 代码或使用 GNU 科学库 (GSL) 生成。
因此要计算事件的时间:
next_event = time() + nextTime(D);
后续事件 = 下一个事件 + 下一个时间(D);
如果事件有持续时间,则持续时间可以是另一个独立的
泊松分布、随机分布、固定区间等。但是,
需要检查到下一个事件的间隔是否较短
比您模拟的事件的持续时间:
The easiest solution is to compute the time of the next event based
on the "L" inter-arrival delay. This is based on the cumulative
distribution function for the exponential: F(x) = 1 - e**(-lambda * x)
where lambda is 1/L, the mean time, and x is the amount of time.
This can be solved for x and fed with a uniform random number:
x = -ln(1-U)/lambda where U is a random value 0..1.
From the link 1:
This link provides a lot of information on how to do it plus examples in
How to Generate Random Timings for a Poisson Process
Note that there are other probability distribution functions that can be used
for event generation (uniform, triangle, etc.). Many of these can be
generated either by code from Boost or by using GNU Scientific Library (GSL).
So to compute times of events:
next_event = time() + nextTime(D);
following_event = next_event + nextTime(D);
If events have a duration, the duration can be another, independent
Poisson distribution, random distribution, fixed interval, etc. However,
will need to check that the interval to the next event is not shorter
than the duration of the event you are simulating:
Python 包含 random.expovariate 这使得这在 Python 中变得非常容易。例如创建 10 个样本:
通常,这将转换为整数:
感谢 此链接。
Python contains random.expovariate which makes this very easy in Python. For example to create 10 samples:
Typically, this will be converted to integer:
Thanks to this link.