Poisson Process

Table of Contents

Exponential Distribution

the cumulative distribution function for the exponential distribution is:

\begin{equation} \begin{align} f(x) = 1 - e^{-\lambda x} \end{align} \end{equation}

λ is rate parameter, the average rate of events

基本方法,一个循环,每隔X分,采样一个[0,1]的随机小数,如果小于f(X),就产生这个事件。但这种方法对随机数产生器的精度要求比较高。

所以反过来,随即产生一个事件发生的概率y,计算发生这个事件的时间x:

\begin{equation} \begin{align} x = \dfrac{-\ln y}{\lambda} \end{align} \end{equation}

Implementation

python

直接使用python提供的random.expovariate

import random
random.expovariate

测试:

>>> sum([random.expovariate(1/40.0) for i in xrange(1000000)]) / 1000000
39.96582878280089
>>> sum([random.expovariate(1/40.0) for i in xrange(1000000)]) / 1000000
40.00629399783253
>>> sum([random.expovariate(1/40.0) for i in xrange(1000000)]) / 1000000
39.92697050573954

c

#include <math.h>
#include <stdlib.h>

float happenTime(float rate_parameter) {
  return -logf(1.0 - (float)(random() / (RAND_MAX + 1))) / rate_parameter;
}

Author: Shi Shougang

Created: 2015-03-05 Thu 23:21

Emacs 24.3.1 (Org mode 8.2.10)

Validate