0

I want to emulate a road traffic situation, which should obey the "poisson distribution", and the probability of vehicles entering the road in the "next" time slot being exponentially distributed. My method is to use the following formula:

$$ P(X \le t) = 1 - e^{-\lambda t} $$

The program logic is:

  1. calculate $p$ as the probability of a car entering the road in the next time slot(i.e. $t=1$)
  2. generate a random number $R$ between $[0, 1)$,if $R \le p$, add a car to the road, otherwise, skip until next iteration.

I wonder if this approach is correct or not?

=== EDIT ===

The following part of my question is answered by Kurt G, but he didn't answer whether my simulation procedure is correct or not.


Also, There is a function in golang (which I use):

// ExpFloat64 returns an exponentially distributed float64 in the range
// (0, +math.MaxFloat64] with an exponential distribution whose rate parameter
// (lambda) is 1 and whose mean is 1/lambda (1) from the default Source.
// To produce a distribution with a different rate parameter,
// callers can adjust the output using:
//
//  sample = ExpFloat64() / desiredRateParameter
//
func ExpFloat64() float64 { return globalRand.ExpFloat64() }

My quesion is, can I use ExpFloat64() to implement my simulation, and how do I understand the value generated by ExpFloat64()?

xrfang
  • 101

1 Answers1

0

To simulate an exponentially distributed RV $R$ you can do it in two ways:

  1. Call that ExpFloat64() function (its description sounds OK).

OR ( that's an XOR ! )

  1. Simulate a uniform random variable $U\in[0,1]$ and plug it into the inverse of the exponential CDF:

$$ R=-\log (1-U)/\lambda $$ This works because any RV that is plugged into its own CDF will create a uniform RV.

You can try both approaches and compare.

Kurt G.
  • 14,198
  • Sorry but I don't understand what to do with the output of ExpFloat64()? e.g. it output 0.314159... What does that mean? I shall wait for 0.314159... timeslot??? – xrfang Jul 28 '21 at 09:11
  • Yes. The description of your program says that the mean of the time slot is $1/\lambda$. That $\lambda$ is your model input and it has the unit $1/time$. In what unit you measure time is up to you. Suppose you measure time in seconds. Then you will have to wait 0.314159 seconds. – Kurt G. Jul 28 '21 at 12:18