Return the regularized Lower Incomplete Gamma function for the specified upper limit x
and shape parameter, evaluated by the series representation of the Incomplete Gamma function.
The regularized Lower Incomplete Gamma function is defined as,
\begin{equation}
\large
P(\kappa, x) = \frac{1}{\Gamma(\kappa)} \int_0^{x}~t^{\kappa-1}{\mathrm e}^{-t} ~ dt ~,
\end{equation}
where \((\kappa > 0, x > 0)\) are respectively the shape parameter of the Gamma function (or distribution) and the upper limit in the integral of the Lower Incomplete Gamma function.
By definition, the Lower Incomplete Gamma function is always positive.
- Parameters
-
[out] | gammaIncLow | : The input scalar of the same type and kind as the input x , representing the regularized Lower Incomplete Gamma function. |
[in] | x | : The input scalar of type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), representing the upper limit in the integral of the Lower Incomplete Gamma function. |
[in] | logGammaKappa | : The input scalar of the same type and kind as the input x , representing the precomputed \(\log(\Gamma(\kappa))\) which can be computed by calling the Fortran intrinsic function log_gamma(kappa) .
|
[in] | kappa | : The input scalar of type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), representing the shape parameter ( \(\kappa\)) of the Lower Incomplete Gamma function. |
[out] | info | : The input scalar or array of the same shape as other input arguments of type integer of default kind IK.
On output, it is set to (positive) number of iterations taken for the series representation to converge or its negative if the series representation fails to converge.
A convergence failure could happen if the input value for kappa is too large.
A negative value implies the lack of convergence.
|
[in] | tol | : The input scalar of the same type and kind as x , representing the relative accuracy in the convergence checking of the Gamma series representation.
(optional, default = 10 * epsilon(x) ). |
Possible calling interfaces ⛓
Return the regularized Lower Incomplete Gamma function for the specified upper limit x and shape para...
This module contains procedures and generic interfaces for the Lower and Upper Incomplete Gamma funct...
- Warning
- The
kappa
and x
input arguments must be positive real
numbers with logGammaKappa = log_gamma(kappa)
where log_gamma()
is a Fortran intrinsic function.
Furthermore, tol << 1.
must hold, if it is present as an input argument.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
-
The
pure
procedure(s) documented herein become impure
when the ParaMonte library is compiled with preprocessor macro CHECK_ENABLED=1
.
By default, these procedures are pure
in release
build and impure
in debug
and testing
builds.
- See also
- getGammaIncLowNR
getGammaIncUppNR
setGammaIncLowNR
setGammaIncUppNR
setGammaIncUppContFracNR
See also The Numerical Recipes by Press et al. 1992 for further details about the Incomplete Gamma function.
Example usage ⛓
12 integer(IK) ,
parameter :: NP
= 1000_IK
13 real(RKH) :: gamIncLow_RKH, x_RKH, kappa_RKH
14 real(RKD) :: gamIncLow_RKD, x_RKD, kappa_RKD
15 real(RKS) :: gamIncLow_RKS, x_RKS, kappa_RKS
18 type(display_type) :: disp
34 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow_RKS, x_RKS, logGammaKappa = log_gamma(kappa_RKS), kappa = kappa_RKS, info = info)")
35 call setGammaIncLowSeriesNR(gamIncLow_RKS, x_RKS, logGammaKappa
= log_gamma(kappa_RKS), kappa
= kappa_RKS, info
= info)
47 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow_RKD, x_RKD, logGammaKappa = log_gamma(kappa_RKD), kappa = kappa_RKD, info = info)")
48 call setGammaIncLowSeriesNR(gamIncLow_RKD, x_RKD, logGammaKappa
= log_gamma(kappa_RKD), kappa
= kappa_RKD, info
= info)
60 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow_RKH, x_RKH, logGammaKappa = log_gamma(kappa_RKH), kappa = kappa_RKH, info = info)")
61 call setGammaIncLowSeriesNR(gamIncLow_RKH, x_RKH, logGammaKappa
= log_gamma(kappa_RKH), kappa
= kappa_RKH, info
= info)
70 integer(IK) :: i, rprecision
71 integer(IK),
allocatable :: exprange(:), info(:)
72 real(RKG),
allocatable :: gamIncLow(:)
74 call disp%show(
"rprecision = precision(0._RKG) / 2")
75 rprecision
= precision(
0._RKG)
/ 2
78 call disp%show(
"exprange = [(i, i = -rprecision, rprecision)]")
79 exprange
= [(i, i
= -rprecision, rprecision)]
82 call disp%show(
"allocate(gamIncLow(size(exprange)), info(size(exprange)))")
83 allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
84 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow, 10._RKG**exprange, logGammaKappa = log_gamma(10._RKG**exprange), kappa = 10._RKG**exprange, info = info)")
85 call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
95 integer(IK) :: i, rprecision
96 integer(IK),
allocatable :: exprange(:), info(:)
97 real(RKG),
allocatable :: gamIncLow(:)
99 call disp%show(
"rprecision = precision(0._RKG) / 2")
100 rprecision
= precision(
0._RKG)
/ 2
103 call disp%show(
"exprange = [(i, i = -rprecision, rprecision)]")
104 exprange
= [(i, i
= -rprecision, rprecision)]
107 call disp%show(
"allocate(gamIncLow(size(exprange)), info(size(exprange)))")
108 allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
109 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow, 10._RKG**exprange, logGammaKappa = log_gamma(10._RKG**exprange), kappa = 10._RKG**exprange, info = info)")
110 call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
120 integer(IK) :: i, rprecision
121 integer(IK),
allocatable :: exprange(:), info(:)
122 real(RKG),
allocatable :: gamIncLow(:)
124 call disp%show(
"rprecision = precision(0._RKG) / 2")
125 rprecision
= precision(
0._RKG)
/ 2
128 call disp%show(
"exprange = [(i, i = -rprecision, rprecision)]")
129 exprange
= [(i, i
= -rprecision, rprecision)]
132 call disp%show(
"allocate(gamIncLow(size(exprange)), info(size(exprange)))")
133 allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
134 call disp%show(
"call setGammaIncLowSeriesNR(gamIncLow, 10._RKG**exprange, logGammaKappa = log_gamma(10._RKG**exprange), kappa = 10._RKG**exprange, info = info)")
135 call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
150 real(RKS) :: x_RKS(NP)
151 integer :: fileUnit, i
154 open(newunit
= fileUnit, file
= "setGammaIncLowSeriesNR.RK.txt")
156 call setGammaIncLowSeriesNR(gamIncLow_RKS, x_RKS(i), logGammaKappa
= log_gamma(kappa_RKS), kappa
= kappa_RKS, info
= info)
157 write(fileUnit,
"(2(g0,:,' '))") x_RKS(i), gamIncLow_RKS
Return the linSpace output argument with size(linSpace) elements of evenly-spaced values over the int...
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.
This module contains procedures and generic interfaces for generating arrays with linear or logarithm...
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
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 ⛓
6call setGammaIncLowSeriesNR(gamIncLow_RKS, x_RKS, logGammaKappa
= log_gamma(kappa_RKS), kappa
= kappa_RKS, info
= info)
17call setGammaIncLowSeriesNR(gamIncLow_RKD, x_RKD, logGammaKappa
= log_gamma(kappa_RKD), kappa
= kappa_RKD, info
= info)
25+2.00000000000000000000000000000000000
27+1.50000000000000000000000000000000000
28call setGammaIncLowSeriesNR(gamIncLow_RKH, x_RKH, logGammaKappa
= log_gamma(kappa_RKH), kappa
= kappa_RKH, info
= info)
30+0.738535870050889377797177924024078751
35rprecision
= precision(
0._RKG)
/ 2
38exprange
= [(i, i
= -rprecision, rprecision)]
40-3,
-2,
-1,
+0,
+1,
+2,
+3
41allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
42call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
44+0.993687510,
+0.960347176,
+0.827551603,
+0.632120609,
+0.542070806,
+0.513297558,
+0.504352927
46+2,
+3,
+5,
+9,
+19,
+51,
+144
49rprecision
= precision(
0._RKG)
/ 2
52exprange
= [(i, i
= -rprecision, rprecision)]
54-7,
-6,
-5,
-4,
-3,
-2,
-1,
+0,
+1,
+2,
+3,
+4,
+5,
+6,
+7
55allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
56call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
58+0.99999844591319076,
+0.99998676179091051,
+0.99989064869904243,
+0.99913704186899466,
+0.99368764670886078,
+0.96034742352151037,
+0.82755175958585092,
+0.63212055882855767,
+0.54207028552814918,
+0.51329879827913072,
+0.50420524418018120,
+0.50132980833519247,
+0.50042052218271271,
+0.50013298041867327,
+0.50004204564265364
60+3,
+3,
+3,
+4,
+5,
+6,
+9,
+16,
+35,
+89,
+255,
+770,
+2365,
+7304,
+22572
63rprecision
= precision(
0._RKG)
/ 2
66exprange
= [(i, i
= -rprecision, rprecision)]
68-16,
-15,
-14,
-13,
-12,
-11,
-10,
-9,
-8,
-7,
-6,
-5,
-4,
-3,
-2,
-1,
+0,
+1,
+2,
+3,
+4,
+5,
+6,
+7,
+8,
+9,
+10,
+11,
+12,
+13,
+14,
+15,
+16
69allocate(gamIncLow(
size(exprange)), info(
size(exprange)))
70call setGammaIncLowSeriesNR(gamIncLow,
10._RKG**exprange, logGammaKappa
= log_gamma(
10._RKG**exprange), kappa
= 10._RKG**exprange, info
= info)
72+0.999999999999996373585417699686749232,
+0.999999999999966038439269991422472214,
+0.999999999999683410243629898865132447,
+0.999999999997064360945602184660494443,
+0.999999999972946194549337116380045185,
+0.999999999752487796450119202118857886,
+0.999999997755136475997589056179261673,
+0.999999979853950029064322113904220671,
+0.999999821565364946706359216160660606,
+0.999998445913190763809082249801272126,
+0.999986761790910335167378117814777145,
+0.999890648699043670145241731405372436,
+0.999137041868993400061435545934892983,
+0.993687646708860290206558632846491445,
+0.960347423521509198326881478159525505,
+0.827551759585850541450313496168157080,
+0.632120558828557678404476229838539127,
+0.542070285528147791685835142940666094,
+0.513298798279148664857314256564028636,
+0.504205244180215508503777843602027958,
+0.501329808339955200382742251299041340,
+0.500420522110365176693312579006613904,
+0.500132980760872591244322817957145961,
+0.500042052208723698333756164759035840,
+0.500013298076014119871248877249405453,
+0.500004205220870056962418775429246375,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000,
+0.00000000000000000000000000000000000
74+3,
+3,
+3,
+3,
+3,
+3,
+4,
+4,
+4,
+5,
+6,
+6,
+8,
+10,
+13,
+18,
+30,
+59,
+143,
+402,
+1211,
+3747,
+11701,
+36641,
+114821,
+359862,
-1000001,
-1000001,
-1000001,
-1000001,
-1000001,
-1000001,
-1000001
Postprocessing of the example output ⛓
3import matplotlib.pyplot
as plt
15xlab = {
"CK" :
r"x ( real/imaginary )"
16 ,
"IK" :
r"x ( integer-valued )"
17 ,
"RK" :
r"x ( real-valued )"
19labels = [
r"shape parameter: $\kappa = 2$"]
21for kind
in [
"IK",
"CK",
"RK"]:
23 pattern =
"*." + kind +
".txt"
24 fileList = glob.glob(pattern)
25 if len(fileList) == 1:
27 df = pd.read_csv(fileList[0], delimiter =
" ")
29 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
33 plt.plot( df.values[:, 0]
38 plt.plot( df.values[:, 1]
44 plt.plot( df.values[:, 0]
50 plt.xticks(fontsize = fontsize - 2)
51 plt.yticks(fontsize = fontsize - 2)
52 ax.set_xlabel(xlab[kind], fontsize = fontsize)
53 ax.set_ylabel(
"Regularized Lower Incomplete Gamma\nFunction via the Series Representation", fontsize = fontsize)
55 plt.grid(visible =
True, which =
"both", axis =
"both", color =
"0.85", linestyle =
"-")
56 ax.tick_params(axis =
"y", which =
"minor")
57 ax.tick_params(axis =
"x", which =
"minor")
65 plt.savefig(fileList[0].replace(
".txt",
".png"))
67 elif len(fileList) > 1:
69 sys.exit(
"Ambiguous file list exists.")
Visualization of the example output ⛓
- Test:
- test_pm_mathGammaNR
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:
- Fatemeh Bagheri, Monday 12:36 pm, August 16, 2021, Dallas TX
Definition at line 807 of file pm_mathGammaNR.F90.