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.326829441E-1,
+0.922724523E-18,
+0.405257754E-2,
+0.647063134E-4
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.125135131E-14,
+0.188318808E-1,
+5.77179337,
+106.766060
72+0.718482077,
+0.307035238
76+0.211707696,
+0.220599309
81+0.897499144,
+0.620168820E-1
85+0.527538955E-1,
+0.556600988E-1
90+0.482126296,
+0.244318679
94+0.124512605,
+0.117792457
99+1.84421015,
+0.326677233
103+0.583081722,
+0.602461457
108+0.916445196,
+0.540956736
112+0.486813426,
+0.495757192
117+2.16448259,
+0.974990055E-1
121+0.202412486,
+0.211034894
126+0.629441798,
+0.850616097
130+0.539749265,
+0.535413325
135+0.766554624E-1,
+0.374298632
139+0.279017799E-1,
+0.286920350E-1
144+1.73022115,
+0.350722969
148+0.604909360,
+0.606828272
153+0.308323413,
+0.354203403
157+0.107543424,
+0.109209202
162+0.782472849,
+4.04998589
166+3.08144379,
+3.16900396
171+0.497640431,
+1.95383561
175+0.875140965,
+0.972307622
180+0.453534685E-1,
+0.373548746
184+0.191997308E-1,
+0.169417318E-1
189+1.24157143,
+0.211577863
193+0.260753363,
+0.262689024
198+0.221977681,
+0.131277546
202+0.302501600E-1,
+0.291406848E-1
207+0.945052147,
+3.31201911
211+3.11428642,
+3.13003087
216+0.135524452,
+0.732155219E-1
220+0.909386389E-2,
+0.992249325E-2
225+2.04230833,
+1.15492058
229+2.41681290,
+2.35870385
234+0.888535023,
+4.35371685
238+4.00702858,
+3.86842990
243+0.551930219E-1,
+0.731519401
247+0.306411926E-1,
+0.403747670E-1
252+0.211753607,
+0.122067027
256+0.240774006E-1,
+0.258481335E-1
261+0.299967043E-1,
+0.985675812
265+0.253551845E-1,
+0.295670256E-1
270+0.116013601,
+1.93261623
274+0.230711997,
+0.224209771
279+0.433227062,
+0.540476926E-1
283+0.239297170E-1,
+0.234149229E-1
288+0.512578189,
+3.60357952
292+1.96265066,
+1.84711623
297+1.95186138,
+1.22501266
301+2.37409377,
+2.39105487
306+3.34607100,
+1.55056524
310+5.23951626,
+5.18830156
315+0.355441153,
+0.329112560E-1
319+0.113170194E-1,
+0.116980150E-1
324+1.45416820,
+0.552167036E-1
328+0.790459737E-1,
+0.802943781E-1
333+0.425744683,
+2.47353053
337+1.10324228,
+1.05309248
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.