Erlan distribution random number

One, function

Generate Erlang distribution of random numbers.

Second, introduction to the method

The probability density function of the Erlang distribution is
\[ f( x)=\left\{\begin{matrix} \frac{\beta ^{-m}x^{m-1}}{(m-1)!}e^{-\frac{x}{\beta }} & x\geqslant 0,\beta> 0\\ 0 & x< 0 \end{matrix}\right. \]
Usually use \(E (m,\beta )\) means. The mean of the Erlang distribution is \(m\beta\), and the variance is \(m\beta^2\) span>. Obviously, when \(m=1\), \(E(m,\beta )\) is The parameter is the probability density function of the exponential distribution with \(beta\).

If \(y_i(i = 1,2,…,m)\) is independent and identically distributed, the parameter is \(beta\) exponential random variable, then \(x=\sum_{i=1}^{m}y_{i}\) Obey Erlang distribution\(E(m,\beta )\). Therefore, first use the inverse transformation method to generate exponentially distributed random variables\(y_i(y_i=-\beta \, ln(u_i),u_i \sim U(0,1))\) , and then generate the Erlang distribution random variable \(x\), that is,
\[ x= \sum_{i = 1}^{m}y_{i}=\sum_{i = 1}^{m}(-\beta \, ln(u_{i}))=-\beta \, ln\left (\prod_{i=1}^{m}u_{i} \right) \]
Generate Erlang distribution random variables\(x\)< The specific algorithm of /span> is as follows:

  1. Generate independent and identically distributed random numbers\(u_1,u_2,…,u_m\)< /span>, ie \(u_i \sim U(0,1)\);
  2. Calculate\ (x==-\beta \, ln\left (\prod_{i=1}^{m}u_{i} \right )\);

Three instructions for use

The method of generating Erlang distribution random numbers is realized in C language as follows:

/**** ******************************** m --- Erlang distribution parameter m beta --- Erlang distribution Parameter beta s --- random number seed************************************/#include "math .h"#include "uniform.c"double erlang(double m, double beta, long int *s){ int i; double u; double x; for(u = 1.0, i = 0; i 

See uniformly distributed random numbers in the uniform.c file

< /p>

Leave a Comment

Your email address will not be published.