simulate_Gamma - fabiankindermann/ce-fortran GitHub Wiki

subroutine simulate_Gamma(x, alpha, beta, fixed)

Description:

Simulates independent draws from a random variable following a Gamma distribution with shape parameter and rate parameter .

Output arguments:

  • real*8 :: x    or    real*8 :: x(:)
    The subroutine stores the realizations of the draws from the random variable in the scalar or one-dimensional array x. If x is a scalar, the subroutine only draws one realization. If x is a one-dimensional array, the subroutine fills up all the array elements with independent draws from the random variable.

Optional arguments:

  • real*8 :: alpha
    Shape parameter. If not present, the subroutine uses alpha = 1. Note that this input variable needs to be strictly greater than zero.
  • real*8 :: beta
    Rate parameter. If not present, the subroutine uses beta = 1. Note that this input variable needs to be strictly greater than zero.
  • logical :: fixed
    If a logical variable fixed is passed to the subroutine that takes the value .true., the subroutine uses a fixed random seed. As a result, the sequence of random numbers drawn by the subroutine will always be the same every time your program is restarted. If fixed is not present or takes a value of .false., then the random seed is initialized at some arbitrary value that depends on the time and date at which you started your program. Hence, the series of random numbers drawn by this subroutine will be different every time your program is restarted.

References

  • Parts of this routine were copied and adapted from:
  • For further reading refer to:
    • Toral, R. & Colet, P. (2014). Stochastic Numerical Methods: An Introduction for Students and Scientists. Weinheim: Wiley.
    • Marsaglia, G., Tsang, W.W. (2000). A simple method for generating gamma variables, ACM Transactions on Mathematical Software, 26(2), 363-372.
  • This routine is used in the following programs:
    • prog02_16.f90
⚠️ **GitHub.com Fallback** ⚠️