开发者

Poisson delay formula/function for VB?

I have a requirement where in I need to sleep for a Poisson duration before sending the next packet. The current formula I can think of is

( e^(-lambda) X lambda^t ) / fact(t)

However, for time steps 280 and more the fact(t) would become obsolete due to overflow.

Can someone help me workaround this conventi开发者_C百科onal way in VB .NET?


I think you are looking for the inter-arrival time. A random inter-arrival time can be generated using

t = (Math.log(1.0-Math.random())/-lambda

The formula you posted is the one that defines the probability that there are exactly t (in your case) arrivals within a specific time period.

See the Wikipedia article on generating Poisson distributions.


Even though the factorial value is getting extremely large (as you've observed), the λ k term is also getting somewhat large to compensate. For a way to represent the distribution that takes this into account, see the Wikipedia article on the Poisson distribution:

Poisson delay formula/function for VB?

A VB implementation might look something like:

Module Module1

    Sub Main()
        Console.WriteLine(Poisson(4, 250))
        Console.ReadKey()
    End Sub

    Function Poisson(ByVal lambda As Integer, ByVal k As Integer) As Double
        Poisson = Math.Exp(k * Math.Log(lambda) - lambda - SumOverLn(1, k))
    End Function

    Function SumOverLn(ByVal start As Integer, ByVal endval As Integer) As Long
        Dim i As Integer
        SumOverLn = 0
        For i = start To endval
            SumOverLn = SumOverLn + Math.Log(i)
        Next

    End Function

End Module

It looks like after a while it is so close to 0 that it registers as such. You may be able to adjust the precision of the display to get more decimal places, but 0 might be a decent enough approximation for high values (the notion that you get from the probability theory seems to be that those values are indeed very close to zero anyway).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜