我有一个实时运行的程序,它具有可变帧率,例如可以是15 fps,可以是60fps.我希望平均每5秒发生一次事件.每帧,我想调用一个函数,该函数将自上一帧以来的时间作为输入,并在调用时平均每隔5秒返回一次True.我认为与Poisson分布有关.我该怎么做?
I have a program running in real-time, with variable framerate, e.g. can be 15 fps, can be 60fps. I want an event to happen, on average, once every 5 seconds. Each frame, I want to call a function which takes the time since last frame as input, and returns True on average once every 5 seconds of elapsed-time given it's called. I figure something to do with Poisson distribution.. how would I do this?
推荐答案这实际上取决于您要使用的分布,您指定的只是平均值.就像您说的那样,我希望Poisson分布可以很好地满足您的需求,但是您也可以在标题中放入统一随机变量",这是一个不同的分布,无论如何,我们还是只使用前者.
It really depends what distribution you want to use, all you specified was the mean. I would, like you said, expect that a Poisson distribution would suit your needs nicely but you also put "uniform random variable" in the title which is a different distribution, anyway let's just go with the former.
因此,如果您要使用泊松分布,则可以使用累积密度函数轻松地生成样本.只需在此处遵循伪代码即可:生成Poisson RV ,其中5秒钟是您的价值lambda.我们将此函数称为Poisson_RN().
So if a Poisson distribution is what you want, you can generate samples pretty easily using the cumulative density function. Just follow the pseudocode here: Generating Poisson RVs, with 5 seconds being your value for lambda. Let's call this function Poisson_RN().
此时的算法非常简单.
global float next_time = current_time() boolean function foo() if (next_time < current_time()) next_time = current_time() + Poisson_RN(); return true; return false;