Return a scalar or array of arbitrary rank of Gamma-distributed random values with the specified shape and scale parameters \((\kappa, \sigma)\) of the Gamma distribution corresponding to the procedure arguments (kappa, sigma)
.
More...
Return a scalar or array of arbitrary rank of Gamma-distributed random values with the specified shape and scale parameters \((\kappa, \sigma)\) of the Gamma distribution corresponding to the procedure arguments (kappa, sigma)
.
See the documentation of pm_distGamma for more information on the Probability Density Function (PDF) of the 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 Gamma-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 shape parameter of the 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 scale parameter of the Gamma distribution.
|
Possible calling interfaces ⛓
Return a scalar or array of arbitrary rank of Gamma-distributed random values with the specified shap...
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 < 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
- getGammaLogPDF
setGammaLogPDF
getGammaCDF
setGammaCDF
Example usage ⛓
12 integer(IK),
parameter :: NP
= 1000_IK
13 real(RKG), dimension(NP) :: Kappa, Sigma, rand
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))
22 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
23 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show(
"! Generate random numbers from the Gamma distribution.")
25 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
30 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show(
"! Gamma random value given integer shape and real inverse rate parameters.")
32 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
40 call disp%show(
"call setGammaRand(rand(1:2), 1._RKG, sigma = Sigma(1))")
47 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%show(
"! Gamma random value given real shape and real inverse rate parameters.")
49 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
57 call disp%show(
"call setGammaRand(rand(1:2), Kappa(1), sigma = Sigma(1))")
64 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show(
"! Gamma random numbers with a fixed set of parameters.")
66 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
74 call disp%show(
"call setGammaRand(rand(1:NP:NP/3), Kappa(1), sigma = Sigma(1))")
75 call setGammaRand(rand(
1:NP:NP
/3), Kappa(
1), sigma
= Sigma(
1))
81 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
82 call disp%show(
"! Gamma random numbers for a range of parameters.")
83 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
91 call disp%show(
"call setGammaRand(rand(1:NP:NP/3), Kappa(1:NP:NP/3), sigma = Sigma(1:NP:NP/3))")
92 call setGammaRand(rand(
1:NP:NP
/3), Kappa(
1:NP:NP
/3), sigma
= Sigma(
1:NP:NP
/3))
98 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%show(
"! Test the mean of a random sample against the analytic answer.")
100 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
106 real(RKG) :: kappa, omega, sigma, mean
110 call disp%show(
"kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)")
114 call disp%show(
"call setGammaRand(rand, kappa, sigma)")
116 call disp%show(
"mean = kappa * sigma")
118 call disp%show(
"[getMean(rand), mean]")
130 real(RKG):: rand(
5000,
3)
134 if (
0 /= getErrTableWrite(SK_
"setGammaRand.RK.txt", rand))
error stop "Table writing 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 ⛓
43+0.999999940E-1,
+0.464158833,
+2.15443444,
+10.0000010
45+0.999999940E-1,
+0.464158833,
+2.15443444,
+10.0000010
46call setGammaRand(rand(
1:NP:NP
/3), Kappa(
1), sigma
= Sigma(
1))
48+0.161919191E-21,
+0.506589494E-25,
+0.241757636E-8,
+0.531675629E-1
57+0.999999940E-1,
+0.464158833,
+2.15443444,
+10.0000010
59+0.999999940E-1,
+0.464158833,
+2.15443444,
+10.0000010
60call setGammaRand(rand(
1:NP:NP
/3), Kappa(
1:NP:NP
/3), sigma
= Sigma(
1:NP:NP
/3))
62+0.101767357E-3,
+0.392729677E-1,
+8.54112053,
+105.588081
72+1.00546825,
+0.434241235
76+0.452220440,
+0.436615765
81+1.27718508,
+0.509940147
85+0.638982892,
+0.651287973
90+0.541436449E-1,
+0.261118054
94+0.135476189E-1,
+0.141378837E-1
99+1.16025317,
+0.122660562
103+0.135582343,
+0.142317310
108+2.52769852,
+0.642927110
112+1.59376228,
+1.62512589
117+1.20331061,
+0.945478261
121+1.10778260,
+1.13770401
126+4.17782593,
+0.967857659
130+4.15142822,
+4.04354095
135+0.632569134,
+0.426450968E-1
139+0.269864183E-1,
+0.269759726E-1
144+0.345118403,
+0.251940582E-1
148+0.878522173E-2,
+0.869493280E-2
153+0.117207125,
+1.42077124
157+0.178616077,
+0.166524515
162+0.721429884,
+1.66105318
166+1.27041173,
+1.19833338
171+1.35084963,
+0.686897561E-1
175+0.941719338E-1,
+0.927895308E-1
180+1.72837472,
+0.325220264E-1
184+0.586105883E-1,
+0.562102497E-1
189+1.67769408,
+1.59111452
193+2.67735529,
+2.66940331
198+1.46930611,
+0.460368961
202+0.663441002,
+0.676422954
207+0.653058171,
+2.33908558
211+1.54577231,
+1.52755892
216+2.02758336,
+0.965503991
220+1.92626476,
+1.95763981
225+1.80686975,
+1.13532996
229+2.12197185,
+2.05139327
234+0.553639650,
+0.412180930
238+0.226465300,
+0.228199705
243+0.348401934,
+0.112492777
247+0.399899110E-1,
+0.391927026E-1
252+1.20892048,
+1.10068536
256+1.30128932,
+1.33064103
261+4.07920074,
+4.94486237
265+20.1848640,
+20.1710854
270+2.30473351,
+0.521049500E-1
274+0.119311512,
+0.120088026
279+2.73516870,
+0.332421422
283+0.914106131,
+0.909228683
288+1.86366689,
+0.101797506
292+0.189615786,
+0.189716637
297+0.771563172,
+0.594291687
301+0.440484166,
+0.458533585
306+0.243205577,
+0.294669449
310+0.726856515E-1,
+0.716652498E-1
315+0.509388626,
+0.730737209
319+0.367854625,
+0.372229218
324+1.74241698,
+0.101324260
328+0.178830653,
+0.176549107
333+1.36058033,
+0.411827981
337+0.529349804,
+0.560325027
Postprocessing of the example output ⛓
3import matplotlib.pyplot
as plt
16xlab = {
"CK" :
"Gamma Random Value ( real/imaginary components )"
17 ,
"IK" :
"Gamma Random Value ( integer-valued )"
18 ,
"RK" :
"Gamma Random Value ( real-valued )"
20legends = [
r"$\kappa = 0.8,~\sigma = 2$"
21 ,
r"$\kappa = 1.0,~\sigma = 2$"
22 ,
r"$\kappa = 5.0,~\sigma = 2$"
25for kind
in [
"IK",
"CK",
"RK"]:
27 pattern =
"*." + kind +
".txt"
28 fileList = glob.glob(pattern)
29 if len(fileList) == 1:
31 df = pd.read_csv(fileList[0], delimiter =
",", header =
None)
33 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
36 for j
in range(len(df.values[0,:])):
38 plt.hist( df.values[:,j]
39 , histtype =
"stepfilled"
44 plt.hist( df.values[:,j]
45 , histtype =
"stepfilled"
52 plt.xticks(fontsize = fontsize - 2)
53 plt.yticks(fontsize = fontsize - 2)
54 ax.set_xlabel(xlab[kind], fontsize = 17)
55 ax.set_ylabel(
"Count", fontsize = 17)
56 ax.set_title(
"Histograms of {} Gamma random values".format(len(df.values[:, 0])), fontsize = 17)
58 plt.grid(visible =
True, which =
"both", axis =
"both", color =
"0.85", linestyle =
"-")
59 ax.tick_params(axis =
"y", which =
"minor")
60 ax.tick_params(axis =
"x", which =
"minor")
62 plt.savefig(fileList[0].replace(
".txt",
".png"))
64 elif len(fileList) > 1:
66 sys.exit(
"Ambiguous file list exists.")
Visualization of the example output ⛓
- Test:
- test_pm_distGamma
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 1193 of file pm_distGamma.F90.