random_generalized_gaussian

Generates pseudorandom numbers from a generalized Gaussian distribution.

Synopsis

#include <imsls.h>

float *imsls_f_generalized_gaussian (int n_random, float mu, float alpha, float beta, 0)

The type double function is imsls_d_random_generalized_gaussian.

Required Arguments

int n_random (Input)
Number of random numbers to generate.

float mu (Input)
Location parameter of the generalized Gaussian distribution. mu can be any real number.

float alpha (Input)
The scale parameter. alpha must be positive.

float beta (Input)
The shape parameter. beta must be positive.

Return Value

An array of length n_random containing the random generalized Gaussian deviates. If no deviate can be computed, NULL is returned.

Synopsis with Optional Arguments

#include <imsls.h>

float *imsls_f_generalized_gaussian (int n_random, float mu, float alpha, float beta,
IMSLS_RETURN_USER, float r[],
0)

Optional Arguments

IMSLS_RETURN_USER, float r[] (Output)
User-supplied array of length n_random containing the random generalized Gaussian deviates.

Description

The generalized Gaussian distribution GGD is a generalization of the Gaussian normal distribution. With β = 2, the GGD(μ, α, β) is equivalent to the normal distribution N(µ,σ) with mean μ=μ, and variance . The shape parameter β allows for distributions with heavier (0 < β < 2) or lighter (β >2) tails than the bell-shaped curve of the normal distribution.

The function generates pseudorandom deviates using the Inverse CDF method. That is, first a uniform(0,1) deviate is generated using imsls_f_random_uniform for the probability value p. Then, the deviate is found using the inverse CDF, by calling imsls_f_generalized_gaussian_inverse_cdf with the given parameters.

Example

This example generates 5 random deviates from the generalized Gaussian distribution with parameter values mu = 0, alpha = sqrt(2), and beta = 2 (equivalent to the standard normal distribution).

#include <imsls.h>
#include <math.h>

int main()
{
    int  n_random = 5;
    float rand[5];
    float mu, alpha, beta;

    mu = 0.0;
    alpha = sqrt(2.0);
    beta = 2.0;
 
    imsls_random_seed_set(123457);

    imsls_f_random_generalized_gaussian(n_random, mu, alpha, beta,
           IMSLS_RETURN_USER, rand, 0);

       imsls_f_write_matrix("random deviates", 1, 5, rand, 0);
}
Output
                        random deviates
          1            2            3            4            5
      1.828       -0.641        0.727        0.175        1.015

Warning Errors

IMSLS_SHAPE_TOO_LARGE

The shape parameter "beta" = # is too large. The uniform limiting distribution is used.

IMSLS_INFINITE_RESULT

The arguments "p" = #,"mu" = #, "alpha" = #, and "beta" = # result in #.

Fatal Errors

IMSLS_BAD_ARGS

The arguments "p" = #,"mu" = #, "alpha" = #, and "beta" = # result in NaN's (not a number) in the calculations. The function returns NaN.