Generate and return the regularized Upper Incomplete Gamma function for the specified shape parameter ( \(\kappa\)) and lower limit of the integral x
.
The regularized Upper Incomplete Gamma function is defined as,
\begin{equation}
\large
Q(\kappa, x) = \frac{1}{\Gamma(\kappa)} \int_x^{+\infty}~t^{\kappa-1}{\mathrm e}^{-t} ~ dt ~,
\end{equation}
where \((\kappa > 0, x > 0)\) should hold, with \(\kappa\) representing the shape parameter of the Gamma function (or distribution) and \(x\) representing the lower limit in the integral of the Upper Incomplete Gamma function.
Note that this integral is bounded between zero and one ( \([0,1]\)).
The regularized Upper Incomplete Gamma function also represents the complement of the Cumulative Distribution Function (CDF) of the univariate Gamma distribution with the specified shape parameter and standardized x
(with the scale parameter of unity).
- Parameters
-
[in] | x | : The input scalar of type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), representing the lower limit in the integral of the Lower Incomplete Gamma function \(P(\kappa,x)\). |
[in] | kappa | : The input scalar of the same type and kind as x , representing the shape parameter ( \(\kappa\)) of the Lower Incomplete Gamma function \(P(\kappa,x)\). |
[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 or its Legendre continued fraction representation.
(optional, default is set by setGammaIncUppNR()) |
- Returns
gammaIncUpp
: The output scalar of the same type and kind as the output argument x
representing the Upper Incomplete Gamma function for the specified kappa
and lower limit.
Note that gammaIncUpp
is, by definition, always positive.
Note that the procedure will abruptly end the program by calling error stop
if the computation of the Incomplete Gamma function fails to converge.
Possible calling interfaces ⛓
Generate and return the regularized Upper Incomplete Gamma function for the specified shape parameter...
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.
Furthermore, tol << 1.
must hold, if present as an input argument.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
- See also
- getGammaIncLowNR
setGammaIncUppNR
Example usage ⛓
12 type(display_type) :: disp
16 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
17 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
18 call disp%show(
"! Compute the regularized Upper Incomplete Gamma Function using its series representation.")
19 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
20 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show(
"getGammaIncUppNR(x = 1.5_RKS, kappa = 2._RKS)")
29 call disp%show(
"getGammaIncUppNR(x = 1.5_RKD, kappa = 2._RKD)")
34 call disp%show(
"getGammaIncUppNR(x = 1.5_RKH, kappa = 2._RKH)")
39 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
40 call disp%show(
"! Compute the regularized Upper Incomplete Gamma Function for a vector of points.")
41 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
45 call disp%show(
"getGammaIncUppNR(x = 1.5_RKH, kappa = [real(RKH) :: 2, 20, 200])")
50 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
51 call disp%show(
"! Compute the regularized Upper Incomplete Gamma Function for a vector of kappa parameters.")
52 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
56 call disp%show(
"getGammaIncUppNR(x = 1._RKS, kappa = [0.1_RKS, 1._RKS, 10._RKS])")
61 call disp%show(
"getGammaIncUppNR(x = 1._RKD, kappa = [0.1_RKD, 1._RKD, 10._RKD])")
66 call disp%show(
"getGammaIncUppNR(x = 1._RKH, kappa = [0.1_RKH, 1._RKH, 10._RKH])")
72 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
73 call disp%show(
"! Compute the regularized Upper Incomplete Gamma Function for a vector of points and kappa parameters.")
74 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
79 call disp%show(
"getGammaIncUppNR(x = [1._RKS, 1._RKS, 1._RKS], kappa = [0.1_RKS, 1._RKS, 10._RKS])")
84 call disp%show(
"getGammaIncUppNR(x = [1._RKD, 1._RKD, 1._RKD], kappa = [0.1_RKD, 1._RKD, 10._RKD])")
89 call disp%show(
"getGammaIncUppNR(x = [1._RKH, 1._RKH, 1._RKH], kappa = [0.1_RKH, 1._RKH, 10._RKH])")
95 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
96 call disp%show(
"! Compute the regularized Upper Incomplete Gamma Function for a fixed point and kappa parameter, but with different accuracies.")
97 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
101 call disp%show(
"getGammaIncUppNR(x = 1._RKH, kappa = 2._RKH, tol = [1.e-8_RKH, 1.e-16_RKH, 1.e-32_RKH])")
113 integer(IK) ,
parameter :: NP
= 1000_IK
114 real(RKS) :: x_RKS(NP)
115 integer :: fileUnit, i
118 open(newunit
= fileUnit, file
= "getGammaIncUppNR.RK.txt")
120 write(fileUnit,
"(*(g0,:,' '))") x_RKS(i),
getGammaIncUppNR(x_RKS(i), kappa
= [
1.0_RKS,
2.5_RKS,
5.0_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 ⛓
18+0.557825400371074572333201176910031393
27+0.557825400371074572333201176910031393,
+0.999999999999999671656580338635575848,
+1.00000000000000000000000000000000000
36+0.241275430E-1,
+0.367879391,
+0.999999881
40+0.24127343726327521E-1,
+0.36787944117144233,
+0.99999988857452171
44+0.241273437263277773829694356333550201E-1,
+0.367879441171442321595523770161460873,
+0.999999888574521661279322646949312805
52getGammaIncUppNR(x
= [
1._RKS,
1._RKS,
1._RKS], kappa
= [
0.1_RKS,
1._RKS,
10._RKS])
53+0.241275430E-1,
+0.367879391,
+0.999999881
56getGammaIncUppNR(x
= [
1._RKD,
1._RKD,
1._RKD], kappa
= [
0.1_RKD,
1._RKD,
10._RKD])
57+0.24127343726327521E-1,
+0.36787944117144233,
+0.99999988857452171
60getGammaIncUppNR(x
= [
1._RKH,
1._RKH,
1._RKH], kappa
= [
0.1_RKH,
1._RKH,
10._RKH])
61+0.241273437263277773829694356333550201E-1,
+0.367879441171442321595523770161460873,
+0.999999888574521661279322646949312805
69getGammaIncUppNR(x
= 1._RKH, kappa
= 2._RKH, tol
= [
1.e-8_RKH,
1.e-16_RKH,
1.e-32_RKH])
70+0.735758882406482416462388959316297467,
+0.735758882342884643349800300430248054,
+0.735758882342884643191047540322921745
Postprocessing of the example output ⛓
3import matplotlib.pyplot
as plt
12label = [
r"shape: $\kappa = 1.0$"
13 ,
r"shape: $\kappa = 2.5$"
14 ,
r"shape: $\kappa = 5.0$"
17pattern =
"*." + kind +
".txt"
18fileList = glob.glob(pattern)
21 df = pd.read_csv(fileList[0], delimiter =
" ")
23 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
26 for i
in range(1,len(df.values[0,:]+1)):
28 plt.plot( df.values[:, 0]
33 plt.xticks(fontsize = fontsize - 2)
34 plt.yticks(fontsize = fontsize - 2)
35 ax.set_xlabel(
"x", fontsize = fontsize)
36 ax.set_ylabel(
"Regularized Upper\nIncomplete Gamma Function", fontsize = fontsize)
38 plt.grid(visible =
True, which =
"both", axis =
"both", color =
"0.85", linestyle =
"-")
39 ax.tick_params(axis =
"y", which =
"minor")
40 ax.tick_params(axis =
"x", which =
"minor")
48 plt.savefig(fileList[0].replace(
".txt",
".png"))
52 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 326 of file pm_mathGammaNR.F90.