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...
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,
-
type rngf_type, implying the use of intrinsic Fortran uniform RNG for Gamma RNG.
-
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
-
array of rank
1 , or
-
array of arbitrary rank if the
rng argument is missing or set to rngf_type, or
of,
-
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 ⛓
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
.
- 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 ⛓
12 integer(IK),
parameter :: NP
= 10000_IK
13 real(RKG), dimension(NP) :: kappa, omega, sigma, rand, mean
15 type(display_type) :: disp
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))
23 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show(
"! Generate random numbers from the GenGamma distribution.")
25 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
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))
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))
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))
58 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
59 call disp%show(
"! Test the mean of a random sample against the analytic answer.")
60 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
66 real(RKG) :: kappa, omega, sigma, mean
70 call disp%show(
"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)")
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]")
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)
99 if (
0 /= getErrTableWrite(
"setGenGammaRand.RKG.txt", rand))
error stop 'table write failed.'
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...
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
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...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
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.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
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))
11+0.272436172,
+0.480508566,
+0.724211037,
+0.331089705
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))
18+0.292871028,
+0.675908387,
+0.816154838,
+0.993936777
22+0.999999940E-1,
+0.464158833,
+2.15443444,
+10.0000010
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))
27+0.524736106,
+0.815635622,
+1.24057782,
+1.62298906
37+0.965915263,
+0.338249952,
+0.730535626
39mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
41+0.791569471,
+0.641790748
46+0.265706360,
+1.22294760,
+0.801577687
48mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
50+0.200455055,
+0.208884194
55+3.57070494,
+0.123714186,
+0.195370868
57mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
59+0.942456722,
+0.225128531
64+0.614998415E-1,
+4.86989689,
+0.386971742
66mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
68+0.126503566E-1,
+0.532382071
73+0.189745538E-1,
+1.19660127,
+0.348674436E-2
75mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
77+0.192727384E-4,
+0.611300202E-4
82+1.19892704,
+0.836391330,
+0.476290911
84mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
86+0.597001612,
+0.526590645
91+0.250184447,
+3.34056616,
+0.804416597
93mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
95+0.432922900,
+0.816728890
100+0.572138011,
+0.429738492,
+1.06100190
102mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
104+0.661433280,
+0.680808842
109+0.766692817,
+1.01183295,
+0.898833871
111mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
113+0.701450109,
+0.691290557
118+0.101935573,
+0.242775947,
+1.35817873
120mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
122+0.291484982,
+0.376756668
Postprocessing of the example output ⛓
3import matplotlib.pyplot
as plt
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 )"
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$"
28for kind
in [
"IKG",
"CKG",
"RKG"]:
30 pattern =
"*." + kind +
".txt"
31 fileList = glob.glob(pattern)
32 if len(fileList) == 1:
34 df = pd.read_csv(fileList[0], delimiter =
",", header =
None)
36 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
39 for j
in range(len(df.values[0,:])):
41 plt.hist( df.values[:,j]
42 , histtype =
"stepfilled"
47 plt.hist( df.values[:,j]
48 , histtype =
"stepfilled"
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)
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")
66 plt.savefig(fileList[0].replace(
".txt",
".png"))
68 elif len(fileList) > 1:
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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- Author:
- Amir Shahmoradi, Oct 16, 2009, 11:14 AM, Michigan
Definition at line 1435 of file pm_distGenGamma.F90.