用Java生成Poisson到达 [英] Generate Poisson Arrival in Java

查看:244
本文介绍了用Java生成Poisson到达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中创建一个函数,根据平均到达率(lambda)和平均服务率(mu)生成Poisson到达。

I would like to create a function in Java that generates Poisson arrivals given the mean arrival rate (lambda) and the mean service rate (mu).

在我的例如我:每天2,2次请求,换句话说,每天2,2次到达,平均服务时间为108小时。考虑到我的程序在t = 0分钟开始,我想创建一个返回到货[]的函数,它将包含t1,t2和一个可能的t3。 T1,t2和t3是发生此类到达的一天中的瞬间(以分钟为单位)。我有以下限制:

In my example I have: 2,2 requests/day, in other words 2,2 arrivals/day and a mean service time of 108 hours. Considering that my program starts at t=0 minutes, I would like to create a function that returns arrivals[], which will contain, t1, t2, and a possible t3. T1,t2 and t3 are the instants (in minutes) during the day where this arrivals occur. I have the following restrictions:

t1< t2< t3< 1440分钟(24小时* 60分钟/小时)

t2-t1> 108分钟

t3-t2> 108分钟

t3 + 108分钟< 1440分钟

有人可以帮帮我吗?

谢谢,

Ana

推荐答案

你可以使用这个算法由D. Knuth提出

private static int getPoissonRandom(double mean) {
    Random r = new Random();
    double L = Math.exp(-mean);
    int k = 0;
    double p = 1.0;
    do {
        p = p * r.nextDouble();
        k++;
    } while (p > L);
    return k - 1;
}

要了解其工作原理,请注意 k 之后迭代循环条件变为

To understand how this works note that after k iterations the loop condition becomes

p 1 * p 2 * ... * p k > L

p1 * p2 * ... * pk > L

相当于

-ln(p 1 )/ mean -ln(p 2 )/ mean ... -ln(p k )/ mean> 1

-ln(p1)/mean -ln(p2)/mean ... -ln(pk)/mean > 1

请注意,如果 p 均匀分布,则-ln(p)/ mean具有给定均值的指数分布。当事件之间的间隔长度是具有指数分布的独立随机变量时,具有泊松分布的随机变量等于给定事件在固定间隔内发生的次数。由于我们使用泊松分布的均值作为事件之间间隔的指数分布的均值,因此我们计算出现次数的固定内部是单位长度。因此,循环条件总结了事件之间间隔的长度,并检查我们是否超出了单位间隔。如果我们在计算第k个事件时已超出单位间隔,则在该区间内发生k-1个事件,因此我们返回k-1。

Note that if p is uniformly distributed then -ln(p)/mean has exponential distribution with a given mean. A random variable with Poisson distribution is equal to the number of times a given event occurs within a fixed interval when the lengths of the intervals between events are independent random variables with exponential distribution. Since we use the mean of the Poisson distribution as the mean of the exponential distribution for the intervals between events, the fixed internal in which we count occurrences is unit length. Thus, the loop condition sums up the lengths of the intervals between events and checks whether we have gone beyond the unit interval. If we have gone beyond the unit interval while counting kth event, then k-1 events occurred within the interval and so we return k-1.

这篇关于用Java生成Poisson到达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆