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

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...

Detailed Description

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,
  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 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

call setGammaRand(rand, kappa, sigma)
call setGammaRand(rand(..), kappa, sigma)
call setGammaRand(rng, rand, kappa, sigma)
call setGammaRand(rng, rand(:), kappa, sigma)
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.
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
getGammaLogPDF
setGammaLogPDF
getGammaCDF
setGammaCDF


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 = 1000_IK
13 real(RKG), dimension(NP) :: Kappa, Sigma, rand
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
21 call disp%skip()
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("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%skip()
28
29 call disp%skip()
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show("! Gamma random value given integer shape and real inverse rate parameters.")
32 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
33 call disp%skip()
34
35 call disp%skip()
36 call disp%show("Kappa(1)")
37 call disp%show( Kappa(1) )
38 call disp%show("Sigma(1)")
39 call disp%show( Sigma(1) )
40 call disp%show("call setGammaRand(rand(1:2), 1._RKG, sigma = Sigma(1))")
41 call setGammaRand(rand(1:2), 1._RKG, sigma = Sigma(1))
42 call disp%show("rand(1)")
43 call disp%show( rand(1) )
44 call disp%skip()
45
46 call disp%skip()
47 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
48 call disp%show("! Gamma random value given real shape and real inverse rate parameters.")
49 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
50 call disp%skip()
51
52 call disp%skip()
53 call disp%show("Kappa(1)")
54 call disp%show( Kappa(1) )
55 call disp%show("Sigma(1)")
56 call disp%show( Sigma(1) )
57 call disp%show("call setGammaRand(rand(1:2), Kappa(1), sigma = Sigma(1))")
58 call setGammaRand(rand(1:2), Kappa(1), sigma = Sigma(1))
59 call disp%show("rand(1)")
60 call disp%show( rand(1) )
61 call disp%skip()
62
63 call disp%skip()
64 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
65 call disp%show("! Gamma random numbers with a fixed set of parameters.")
66 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
67 call disp%skip()
68
69 call disp%skip()
70 call disp%show("Kappa(1:NP:NP/3)")
71 call disp%show( Kappa(1:NP:NP/3) )
72 call disp%show("Sigma(1:NP:NP/3)")
73 call disp%show( Sigma(1:NP:NP/3) )
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))
76 call disp%show("rand(1:NP:NP/3)")
77 call disp%show( rand(1:NP:NP/3) )
78 call disp%skip()
79
80 call disp%skip()
81 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
82 call disp%show("! Gamma random numbers for a range of parameters.")
83 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
84 call disp%skip()
85
86 call disp%skip()
87 call disp%show("Kappa(1:NP:NP/3)")
88 call disp%show( Kappa(1:NP:NP/3) )
89 call disp%show("Sigma(1:NP:NP/3)")
90 call disp%show( Sigma(1:NP:NP/3) )
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))
93 call disp%show("rand(1:NP:NP/3)")
94 call disp%show( rand(1:NP:NP/3) )
95 call disp%skip()
96
97 call disp%skip()
98 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
99 call disp%show("! Test the mean of a random sample against the analytic answer.")
100 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
101 call disp%skip()
102
103 block
104 use pm_sampleMean, only: getMean
105 use pm_distExp, only: getExpRand
106 real(RKG) :: kappa, omega, sigma, mean
107 integer(IK) :: itry
108 do itry = 1, 30
109 call disp%skip()
110 call disp%show("kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)")
111 kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
112 call disp%show("[kappa, sigma]")
113 call disp%show( [kappa, sigma] )
114 call disp%show("call setGammaRand(rand, kappa, sigma)")
115 call setGammaRand(rand, kappa, sigma)
116 call disp%show("mean = kappa * sigma")
117 mean = kappa * sigma
118 call disp%show("[getMean(rand), mean]")
119 call disp%show( [getMean(rand), mean] )
120 call disp%skip()
121 end do
122 end block
123
124 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 ! Output an example rand array for visualization.
126 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127
128 block
129 use pm_io, only: getErrTableWrite
130 real(RKG):: rand(5000, 3)
131 call setGammaRand(rand(:, 1), +0.8_RKG, sigma = 2._RKG)
132 call setGammaRand(rand(:, 2), +1.0_RKG, sigma = 2._RKG)
133 call setGammaRand(rand(:, 3), +5.0_RKG, sigma = 2._RKG)
134 if (0 /= getErrTableWrite(SK_"setGammaRand.RK.txt", rand)) error stop "Table writing failed."
135 end block
136
137end 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!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4! Generate random numbers from the Gamma distribution.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10! Gamma random value given integer shape and real inverse rate parameters.
11!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
13
14Kappa(1)
15+0.999999940E-1
16Sigma(1)
17+0.999999940E-1
18call setGammaRand(rand(1:2), 1._RKG, sigma = Sigma(1))
19rand(1)
20+0.192789733E-1
21
22
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24! Gamma random value given real shape and real inverse rate parameters.
25!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27
28Kappa(1)
29+0.999999940E-1
30Sigma(1)
31+0.999999940E-1
32call setGammaRand(rand(1:2), Kappa(1), sigma = Sigma(1))
33rand(1)
34+0.146627855E-1
35
36
37!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38! Gamma random numbers with a fixed set of parameters.
39!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41
42Kappa(1:NP:NP/3)
43+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
44Sigma(1:NP:NP/3)
45+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
46call setGammaRand(rand(1:NP:NP/3), Kappa(1), sigma = Sigma(1))
47rand(1:NP:NP/3)
48+0.461255433E-3, +0.232378849E-8, +0.125766145E-1, +0.796557309E-8
49
50
51!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52! Gamma random numbers for a range of parameters.
53!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55
56Kappa(1:NP:NP/3)
57+0.999999940E-1, +0.464158833, +2.15443444, +10.0000010
58Sigma(1:NP:NP/3)
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))
61rand(1:NP:NP/3)
62+0.411371235E-3, +0.387056149E-2, +6.75889826, +67.2632828
63
64
65!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66! Test the mean of a random sample against the analytic answer.
67!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69
70kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
71[kappa, sigma]
72+1.25593460, +0.843398452
73call setGammaRand(rand, kappa, sigma)
74mean = kappa * sigma
75[getMean(rand), mean]
76+1.04580116, +1.05925333
77
78
79kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
80[kappa, sigma]
81+6.53944302, +0.282809496
82call setGammaRand(rand, kappa, sigma)
83mean = kappa * sigma
84[getMean(rand), mean]
85+1.85777009, +1.84941661
86
87
88kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
89[kappa, sigma]
90+2.10668516, +0.558247901E-1
91call setGammaRand(rand, kappa, sigma)
92mean = kappa * sigma
93[getMean(rand), mean]
94+0.113393411, +0.117605254
95
96
97kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
98[kappa, sigma]
99+0.587499440, +0.686475076E-2
100call setGammaRand(rand, kappa, sigma)
101mean = kappa * sigma
102[getMean(rand), mean]
103+0.378300971E-2, +0.403303700E-2
104
105
106kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
107[kappa, sigma]
108+0.425436169, +3.09141994
109call setGammaRand(rand, kappa, sigma)
110mean = kappa * sigma
111[getMean(rand), mean]
112+1.27251959, +1.31520188
113
114
115kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
116[kappa, sigma]
117+1.10502982, +0.595415011E-1
118call setGammaRand(rand, kappa, sigma)
119mean = kappa * sigma
120[getMean(rand), mean]
121+0.632723644E-1, +0.657951310E-1
122
123
124kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
125[kappa, sigma]
126+0.617607117, +0.463864766E-1
127call setGammaRand(rand, kappa, sigma)
128mean = kappa * sigma
129[getMean(rand), mean]
130+0.284711700E-1, +0.286486186E-1
131
132
133kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
134[kappa, sigma]
135+0.138399601, +0.781810284E-1
136call setGammaRand(rand, kappa, sigma)
137mean = kappa * sigma
138[getMean(rand), mean]
139+0.140611725E-1, +0.108202230E-1
140
141
142kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
143[kappa, sigma]
144+1.10488963, +0.944579691E-1
145call setGammaRand(rand, kappa, sigma)
146mean = kappa * sigma
147[getMean(rand), mean]
148+0.103835016, +0.104365632
149
150
151kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
152[kappa, sigma]
153+0.355049670, +1.53014612
154call setGammaRand(rand, kappa, sigma)
155mean = kappa * sigma
156[getMean(rand), mean]
157+0.565379083, +0.543277860
158
159
160kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
161[kappa, sigma]
162+0.223521013E-1, +0.381012291
163call setGammaRand(rand, kappa, sigma)
164mean = kappa * sigma
165[getMean(rand), mean]
166+0.842913240E-2, +0.851642527E-2
167
168
169kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
170[kappa, sigma]
171+1.10672128, +0.162377611
172call setGammaRand(rand, kappa, sigma)
173mean = kappa * sigma
174[getMean(rand), mean]
175+0.170151368, +0.179706752
176
177
178kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
179[kappa, sigma]
180+3.66845751, +0.119955830
181call setGammaRand(rand, kappa, sigma)
182mean = kappa * sigma
183[getMean(rand), mean]
184+0.434006631, +0.440052867
185
186
187kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
188[kappa, sigma]
189+0.546247542, +1.16398180
190call setGammaRand(rand, kappa, sigma)
191mean = kappa * sigma
192[getMean(rand), mean]
193+0.624200761, +0.635822177
194
195
196kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
197[kappa, sigma]
198+0.434742302, +0.262964517E-1
199call setGammaRand(rand, kappa, sigma)
200mean = kappa * sigma
201[getMean(rand), mean]
202+0.115999999E-1, +0.114321802E-1
203
204
205kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
206[kappa, sigma]
207+1.17992485, +0.268622100
208call setGammaRand(rand, kappa, sigma)
209mean = kappa * sigma
210[getMean(rand), mean]
211+0.310573727, +0.316953897
212
213
214kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
215[kappa, sigma]
216+1.26637924, +0.804037899E-1
217call setGammaRand(rand, kappa, sigma)
218mean = kappa * sigma
219[getMean(rand), mean]
220+0.101973012, +0.101821691
221
222
223kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
224[kappa, sigma]
225+0.750454143E-1, +0.877367198
226call setGammaRand(rand, kappa, sigma)
227mean = kappa * sigma
228[getMean(rand), mean]
229+0.559935495E-1, +0.658423826E-1
230
231
232kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
233[kappa, sigma]
234+0.199832991, +1.17387259
235call setGammaRand(rand, kappa, sigma)
236mean = kappa * sigma
237[getMean(rand), mean]
238+0.258224994, +0.234578475
239
240
241kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
242[kappa, sigma]
243+1.46304011, +1.60915339
244call setGammaRand(rand, kappa, sigma)
245mean = kappa * sigma
246[getMean(rand), mean]
247+2.44233465, +2.35425591
248
249
250kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
251[kappa, sigma]
252+0.942411721, +0.190167740
253call setGammaRand(rand, kappa, sigma)
254mean = kappa * sigma
255[getMean(rand), mean]
256+0.175109044, +0.179216310
257
258
259kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
260[kappa, sigma]
261+0.186331034, +0.210274681
262call setGammaRand(rand, kappa, sigma)
263mean = kappa * sigma
264[getMean(rand), mean]
265+0.406572744E-1, +0.391806997E-1
266
267
268kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
269[kappa, sigma]
270+0.235560864, +0.924122155
271call setGammaRand(rand, kappa, sigma)
272mean = kappa * sigma
273[getMean(rand), mean]
274+0.240402922, +0.217687011
275
276
277kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
278[kappa, sigma]
279+0.400287092, +1.22469091
280call setGammaRand(rand, kappa, sigma)
281mean = kappa * sigma
282[getMean(rand), mean]
283+0.487759829, +0.490227968
284
285
286kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
287[kappa, sigma]
288+0.504582047, +0.302653670
289call setGammaRand(rand, kappa, sigma)
290mean = kappa * sigma
291[getMean(rand), mean]
292+0.162026063, +0.152713612
293
294
295kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
296[kappa, sigma]
297+1.15946388, +2.42746019
298call setGammaRand(rand, kappa, sigma)
299mean = kappa * sigma
300[getMean(rand), mean]
301+2.78323388, +2.81455231
302
303
304kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
305[kappa, sigma]
306+0.349314623E-1, +1.38247859
307call setGammaRand(rand, kappa, sigma)
308mean = kappa * sigma
309[getMean(rand), mean]
310+0.453141257E-1, +0.482919998E-1
311
312
313kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
314[kappa, sigma]
315+2.19591928, +1.53773582
316call setGammaRand(rand, kappa, sigma)
317mean = kappa * sigma
318[getMean(rand), mean]
319+3.42718101, +3.37674379
320
321
322kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
323[kappa, sigma]
324+0.522154808, +0.927167535
325call setGammaRand(rand, kappa, sigma)
326mean = kappa * sigma
327[getMean(rand), mean]
328+0.489555836, +0.484124988
329
330
331kappa = getExpRand(1._RKG); sigma = getExpRand(1._RKG)
332[kappa, sigma]
333+0.391054988, +0.755496800
334call setGammaRand(rand, kappa, sigma)
335mean = kappa * sigma
336[getMean(rand), mean]
337+0.293998480, +0.295440793
338
339

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 ={ "CK" : "-"
13 , "IK" : "."
14 , "RK" : "-"
15 }
16xlab = { "CK" : "Gamma Random Value ( real/imaginary components )"
17 , "IK" : "Gamma Random Value ( integer-valued )"
18 , "RK" : "Gamma Random Value ( real-valued )"
19 }
20legends = [ r"$\kappa = 0.8,~\sigma = 2$"
21 , r"$\kappa = 1.0,~\sigma = 2$"
22 , r"$\kappa = 5.0,~\sigma = 2$"
23 ]
24
25for kind in ["IK", "CK", "RK"]:
26
27 pattern = "*." + kind + ".txt"
28 fileList = glob.glob(pattern)
29 if len(fileList) == 1:
30
31 df = pd.read_csv(fileList[0], delimiter = ",", header = None)
32
33 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
34 ax = plt.subplot()
35
36 for j in range(len(df.values[0,:])):
37 if kind == "CK":
38 plt.hist( df.values[:,j]
39 , histtype = "stepfilled"
40 , alpha = 0.5
41 , bins = 75
42 )
43 else:
44 plt.hist( df.values[:,j]
45 , histtype = "stepfilled"
46 , alpha = 0.5
47 , bins = 75
48 )
49 ax.legend ( legends
50 , fontsize = fontsize
51 )
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)
57
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")
61
62 plt.savefig(fileList[0].replace(".txt",".png"))
63
64 elif len(fileList) > 1:
65
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.

  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 1193 of file pm_distGamma.F90.


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