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.246609062,
+0.139011100,
+0.136816716E-1,
+1.10822439
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.262083739,
+0.769532561,
+0.854447424,
+1.02380049
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.719341516,
+0.817872584,
+1.19199896,
+1.61687899
37+2.10582089,
+1.42327619,
+1.43380165
39mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
41+5.38940287,
+4.68922806
46+0.285340518,
+1.10786247,
+0.442904979E-1
48mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
50+0.901213195E-2,
+0.124671636E-1
55+1.52903306,
+2.27296162,
+2.85300994
57mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
59+56.5402489,
+15.1260548
64+2.89707136,
+0.707545221,
+0.948019326
66mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
68+1.96237516,
+1.94352341
73+0.134042829,
+1.34755206,
+0.744359493
75mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
77+0.821327195E-1,
+0.941710770E-1
82+0.308452100,
+0.946370885E-1,
+0.120554298
84mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
86+0.620471478,
+0.913114101E-1
91+0.885772765,
+0.776675165,
+0.170950890
93mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
95+0.213991478,
+0.142734900
100+0.838939939E-2,
+4.51184702,
+0.416142523
102mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
104+0.544949714E-2,
+0.419685133E-1
109+2.75959492,
+0.126669332,
+0.102064475
111mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
113+0.834350884,
+0.113669977
118+0.196212322,
+0.950398564,
+0.410032123
120mean
= exp(
log_gamma(kappa
+ omega)
- log_gamma(kappa))
* sigma
122+0.863392651E-1,
+0.817650780E-1
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.