ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_distGenGamma::setGenGammaRand Interface Reference

Return a scalar or array of arbitrary rank of GenGamma-distributed random values with the specified shape and scale parameters \((\kappa, \omega, \sigma)\) of the Generalized Gamma distribution corresponding to the procedure arguments (kappa, omega, sigma). More...

Detailed Description

Return a scalar or array of arbitrary rank of GenGamma-distributed random values with the specified shape and scale parameters \((\kappa, \omega, \sigma)\) of the Generalized Gamma distribution corresponding to the procedure arguments (kappa, omega, sigma).

See the documentation of pm_distGenGamma for more information on the Probability Density Function (PDF) of the Generalized Gamma distribution.

Parameters
[in,out]rng: The input/output scalar that can be an object of,
  1. type rngf_type, implying the use of intrinsic Fortran uniform RNG for Gamma RNG.
  2. type xoshiro256ssw_type, implying the use of xoshiro256** uniform RNG for Gamma RNG.
(optional, default = rngf_type, implying the use of the intrinsic Fortran URNG.)
[out]rand: The output scalar or
  1. array of rank 1, or
  2. array of arbitrary rank if the rng argument is missing or set to rngf_type, or
of,
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
On output, it contains GenGamma-distributed random value(s).
[in]kappa: The input scalar (or array of the same shape as other array-like arguments) of the same type and kind as rand, representing the \(\kappa\) shape parameter of the Generalized Gamma distribution.
[in]sigma: The input scalar (or array of the same shape as other array-like arguments) of the same type and kind as rand, representing the \(\omega\) shape parameter of the Generalized Gamma distribution.
[in]sigma: The input scalar (or array of the same shape as other array-like arguments) of the same type and kind as rand, representing the \(\sigma\) scale parameter of the Generalized Gamma distribution.


Possible calling interfaces

call setGenGammaRand(rand, kappa, omega, sigma)
call setGenGammaRand(rand(..), kappa, omega, sigma)
call setGenGammaRand(rng, rand, kappa, omega, sigma)
call setGenGammaRand(rng, rand(:), kappa, omega, sigma)
Return a scalar or array of arbitrary rank of GenGamma-distributed random values with the specified s...
This module contains classes and procedures for computing various statistical quantities related to t...
Warning
The condition 0 < kappa must hold for the corresponding input arguments.
The condition 0 < omega must hold for the corresponding input arguments.
The condition 0 < sigma must hold for the corresponding input arguments.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.
The procedures under discussion are elemental.
The procedures under discussion are recursive.
Note
For repeated Gamma RNG with fixed kappa, it is best to pass a vector of rand to be filled with random numbers rather than calling the procedures with scalar rand argument repeatedly.
In addition to avoiding procedure call overhead, vectorized RGN in this particular case also avoids an unnecessary division and square-root operation.
See also
getGenGammaLogPDF
setGenGammaLogPDF
getGenGammaCDF
setGenGammaCDF


Example usage

1program example
2
3 use pm_kind, only: SK, IK
4 use pm_kind, only: RKG => RKS ! all real kinds are supported.
8 use pm_io, only: display_type
9
10 implicit none
11
12 integer(IK), parameter :: NP = 10000_IK
13 real(RKG), dimension(NP) :: kappa, omega, sigma, rand, mean
14
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 call setLogSpace(kappa, logx1 = log(0.1_RKG), logx2 = log(10._RKG))
19 call setLogSpace(sigma, logx1 = log(0.1_RKG), logx2 = log(10._RKG))
20 call setLogSpace(omega, logx1 = log(0.1_RKG), logx2 = log(10._RKG))
21
22 call disp%skip()
23 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show("! Generate random numbers from the GenGamma distribution.")
25 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%skip()
27
28 call disp%skip()
29 call disp%show("sigma(1:NP:NP/3)")
30 call disp%show( sigma(1:NP:NP/3) )
31 call disp%show("call setGenGammaRand(rand(1:NP:NP/3), kappa(1), omega(1), sigma(1:NP:NP/3))")
32 call setGenGammaRand(rand(1:NP:NP/3), kappa(1), omega(1), sigma(1:NP:NP/3))
33 call disp%show("rand(1:NP:NP/3)")
34 call disp%show( rand(1:NP:NP/3) )
35 call disp%skip()
36
37 call disp%skip()
38 call disp%show("kappa(1:NP:NP/3)")
39 call disp%show( kappa(1:NP:NP/3) )
40 call disp%show("call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1))")
41 call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1))
42 call disp%show("rand(1:NP:NP/3)")
43 call disp%show( rand(1:NP:NP/3) )
44 call disp%skip()
45
46 call disp%skip()
47 call disp%show("kappa(1:NP:NP/3)")
48 call disp%show( kappa(1:NP:NP/3) )
49 call disp%show("sigma(1:NP:NP/3)")
50 call disp%show( sigma(1:NP:NP/3) )
51 call disp%show("call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1:NP:NP/3))")
52 call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1:NP:NP/3))
53 call disp%show("rand(1:NP:NP/3)")
54 call disp%show( rand(1:NP:NP/3) )
55 call disp%skip()
56
57 call disp%skip()
58 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
59 call disp%show("! Test the mean of a random sample against the analytic answer.")
60 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
61 call disp%skip()
62
63 block
64 use pm_sampleMean, only: getMean
65 use pm_distExp, only: getExpRand
66 real(RKG) :: kappa, omega, sigma, mean
67 integer(IK) :: itry
68 do itry = 1, 10
69 call disp%skip()
70 call disp%show("kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)")
71 kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
72 call disp%show("[kappa, omega, sigma]")
73 call disp%show( [kappa, omega, sigma] )
74 call disp%show("call setGenGammaRand(rand, kappa, omega, sigma)")
75 call setGenGammaRand(rand, kappa, omega, sigma)
76 call disp%show("mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma")
77 mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
78 call disp%show("[getMean(rand), mean]")
79 call disp%show( [getMean(rand), mean] )
80 call disp%skip()
81 end do
82 end block
83
84 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 ! Output an example rand array for visualization.
86 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88 block
89 use pm_io, only: getErrTableWrite
90 integer(IK) :: fileUnit, i
91 integer(IK), parameter :: NP = 5000
92 real(RKG), dimension(NP, 5) :: rand
93 call setGenGammaRand(rand(:,1), 2.0_RKG, omega = 1 / 5.0_RKG, sigma = 1 / 0.3_RKG)
94 call setGenGammaRand(rand(:,2), .14_RKG, omega = 1 / 7.0_RKG, sigma = 1 / .14_RKG)
95 call setGenGammaRand(rand(:,3), 0.2_RKG, omega = 1 / 5.0_RKG, sigma = 1 / 0.2_RKG)
96 call setGenGammaRand(rand(:,4), 0.5_RKG, omega = 1 / 2.0_RKG, sigma = 1 / 0.5_RKG)
97 call setGenGammaRand(rand(:,5), 2.0_RKG, omega = 1 / 0.5_RKG, sigma = 1 / 1.0_RKG)
98 !call setGenGammaRand(rand(:,6), 1.0_RKG, omega = 1 / 0.5_RKG, sigma = 1 / 0.5_RKG)
99 if (0 /= getErrTableWrite("setGenGammaRand.RKG.txt", rand)) error stop 'table write failed.'
100 end block
101
102end program example
Return the linSpace output argument with size(linSpace) elements of evenly-spaced values over the int...
Return the logSpace output argument with size(logSpace) elements of logarithmically-evenly-spaced val...
Return a scalar (or array of arbitrary rank of) random value(s) from the Exponential distribution,...
Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the spec...
Definition: pm_io.F90:5940
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
Generate and return the (weighted) mean of an input sample of nsam observations with ndim = 1 or 2 at...
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
This module contains classes and procedures for computing various statistical quantities related to t...
Definition: pm_distExp.F90:112
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
This module contains classes and procedures for computing the first moment (i.e., the statistical mea...
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3! Generate random numbers from the GenGamma distribution.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7sigma(1:NP:NP/3)
8+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
9call setGenGammaRand(rand(1:NP:NP/3), kappa(1), omega(1), sigma(1:NP:NP/3))
10rand(1:NP:NP/3)
11+0.272436172, +0.480508566, +0.724211037, +0.331089705
12
13
14kappa(1:NP:NP/3)
15+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
16call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1))
17rand(1:NP:NP/3)
18+0.292871028, +0.675908387, +0.816154838, +0.993936777
19
20
21kappa(1:NP:NP/3)
22+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
23sigma(1:NP:NP/3)
24+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
25call setGenGammaRand(rand(1:NP:NP/3), kappa(1:NP:NP/3), omega(1), sigma(1:NP:NP/3))
26rand(1:NP:NP/3)
27+0.524736106, +0.815635622, +1.24057782, +1.62298906
28
29
30!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31! Test the mean of a random sample against the analytic answer.
32!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33
34
35kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
36[kappa, omega, sigma]
37+0.965915263, +0.338249952, +0.730535626
38call setGenGammaRand(rand, kappa, omega, sigma)
39mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
40[getMean(rand), mean]
41+0.791569471, +0.641790748
42
43
44kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
45[kappa, omega, sigma]
46+0.265706360, +1.22294760, +0.801577687
47call setGenGammaRand(rand, kappa, omega, sigma)
48mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
49[getMean(rand), mean]
50+0.200455055, +0.208884194
51
52
53kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
54[kappa, omega, sigma]
55+3.57070494, +0.123714186, +0.195370868
56call setGenGammaRand(rand, kappa, omega, sigma)
57mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
58[getMean(rand), mean]
59+0.942456722, +0.225128531
60
61
62kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
63[kappa, omega, sigma]
64+0.614998415E-1, +4.86989689, +0.386971742
65call setGenGammaRand(rand, kappa, omega, sigma)
66mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
67[getMean(rand), mean]
68+0.126503566E-1, +0.532382071
69
70
71kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
72[kappa, omega, sigma]
73+0.189745538E-1, +1.19660127, +0.348674436E-2
74call setGenGammaRand(rand, kappa, omega, sigma)
75mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
76[getMean(rand), mean]
77+0.192727384E-4, +0.611300202E-4
78
79
80kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
81[kappa, omega, sigma]
82+1.19892704, +0.836391330, +0.476290911
83call setGenGammaRand(rand, kappa, omega, sigma)
84mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
85[getMean(rand), mean]
86+0.597001612, +0.526590645
87
88
89kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
90[kappa, omega, sigma]
91+0.250184447, +3.34056616, +0.804416597
92call setGenGammaRand(rand, kappa, omega, sigma)
93mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
94[getMean(rand), mean]
95+0.432922900, +0.816728890
96
97
98kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
99[kappa, omega, sigma]
100+0.572138011, +0.429738492, +1.06100190
101call setGenGammaRand(rand, kappa, omega, sigma)
102mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
103[getMean(rand), mean]
104+0.661433280, +0.680808842
105
106
107kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
108[kappa, omega, sigma]
109+0.766692817, +1.01183295, +0.898833871
110call setGenGammaRand(rand, kappa, omega, sigma)
111mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
112[getMean(rand), mean]
113+0.701450109, +0.691290557
114
115
116kappa = getExpRand(1._RKG); omega = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
117[kappa, omega, sigma]
118+0.101935573, +0.242775947, +1.35817873
119call setGenGammaRand(rand, kappa, omega, sigma)
120mean = exp(log_gamma(kappa + omega) - log_gamma(kappa)) * sigma
121[getMean(rand), mean]
122+0.291484982, +0.376756668
123
124

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6import glob
7import sys
8
9linewidth = 2
10fontsize = 17
11
12marker ={ "CKG" : "-"
13 , "IKG" : "."
14 , "RKG" : "-"
15 }
16xlab = { "CKG" : "Generalized Gamma Random Value ( real/imaginary components )"
17 , "IKG" : "Generalized Gamma Random Value ( integer-valued )"
18 , "RKG" : "Generalized Gamma Random Value ( real-valued )"
19 }
20legends = [ "$\kappa, 1/\omega, 1/\sigma = 1.0, 0.5, 0.5$"
21 , "$\kappa, 1/\omega, 1/\sigma = 2.0, 0.5, 1.0$"
22 , "$\kappa, 1/\omega, 1/\sigma = 0.5, 2.0, 0.5$"
23 , "$\kappa, 1/\omega, 1/\sigma = 0.2, 5.0, 0.2$"
24 , "$\kappa, 1/\omega, 1/\sigma = .14, 7.0, .14$"
25 , "$\kappa, 1/\omega, 1/\sigma = 2.0, 5.0, 0.3$"
26 ]
27
28for kind in ["IKG", "CKG", "RKG"]:
29
30 pattern = "*." + kind + ".txt"
31 fileList = glob.glob(pattern)
32 if len(fileList) == 1:
33
34 df = pd.read_csv(fileList[0], delimiter = ",", header = None)
35
36 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
37 ax = plt.subplot()
38
39 for j in range(len(df.values[0,:])):
40 if kind == "CKG":
41 plt.hist( df.values[:,j]
42 , histtype = "stepfilled"
43 , alpha = 0.5
44 , bins = 75
45 )
46 else:
47 plt.hist( df.values[:,j]
48 , histtype = "stepfilled"
49 , alpha = 0.5
50 , bins = 75
51 )
52 ax.legend ( legends
53 , fontsize = fontsize
54 )
55 plt.xticks(fontsize = fontsize - 2)
56 plt.yticks(fontsize = fontsize - 2)
57 ax.set_xlabel(xlab[kind], fontsize = 17)
58 ax.set_ylabel("Count", fontsize = 17)
59 ax.set_title("Histograms of {} Generalized Gamma random values".format(len(df.values[:, 0])), fontsize = 17)
60 #ax.set_yscale("log")
61
62 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
63 ax.tick_params(axis = "y", which = "minor")
64 ax.tick_params(axis = "x", which = "minor")
65
66 plt.savefig(fileList[0].replace(".txt",".png"))
67
68 elif len(fileList) > 1:
69
70 sys.exit("Ambiguous file list exists.")

Visualization of the example output
Test:
test_pm_distGenGamma


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan

Definition at line 1435 of file pm_distGenGamma.F90.


The documentation for this interface was generated from the following file: