ParaMonte Fortran 2.0.0 Parallel Monte Carlo and Machine Learning LibrarySee the latest version documentation.
pm_mathGamma::getGammaIncUpp Interface Reference

Generate and return the regularized Upper Incomplete Gamma function for the specified shape parameter ( $$\kappa$$) and lower limit of the integral x. More...

## Detailed Description

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,

$$\large Q(\kappa, x) = \frac{1}{\Gamma(\kappa)} \int_x^{+\infty}~t^{\kappa-1}{\mathrm e}^{-t} ~ dt ~,$$

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 getGammaIncUpp())
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

gammaIncUpp = getGammaIncUpp(x, kappa, tol = tol)
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.
Remarks
The procedures under discussion are impure.
The procedures under discussion are elemental.
The procedures under this generic interface solely provide a more convenient method of calling the subroutine equivalents setGammaIncUpp.
As such they are slower than the corresponding subroutine version.
setGammaIncUpp
getGammaIncLow
setGammaIncLow
setGammaIncLowSeries
setGammaIncUppContFrac

Example usage

1program example
2
3 use pm_kind, only: SK
4 use pm_kind, only: IK
5 use pm_kind, only: LK
6 use pm_kind, only: RKS, RKD, RKH
7 use pm_io, only: display_type
9
10 implicit none
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
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("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
21 call disp%skip()
22
23 call disp%skip()
24 call disp%show("getGammaIncUpp(x = 1.5_RKS, kappa = 2._RKS)")
25 call disp%show( getGammaIncUpp(x = 1.5_RKS, kappa = 2._RKS) )
26 call disp%skip()
27
28 call disp%skip()
29 call disp%show("getGammaIncUpp(x = 1.5_RKD, kappa = 2._RKD)")
30 call disp%show( getGammaIncUpp(x = 1.5_RKD, kappa = 2._RKD) )
31 call disp%skip()
32
33 call disp%skip()
34 call disp%show("getGammaIncUpp(x = 1.5_RKH, kappa = 2._RKH)")
35 call disp%show( getGammaIncUpp(x = 1.5_RKH, kappa = 2._RKH) )
36 call disp%skip()
37
38
39 call disp%skip()
40 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
41 call disp%show("! Compute the regularized Upper Incomplete Gamma Function for a vector of points.")
42 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
43 call disp%skip()
44
45
46 call disp%skip()
47 call disp%show("getGammaIncUpp(x = [0._RKS, 1._RKS, 10._RKS], kappa = 2._RKS)")
48 call disp%show( getGammaIncUpp(x = [0._RKS, 1._RKS, 10._RKS], kappa = 2._RKS) )
49 call disp%skip()
50
51 call disp%skip()
52 call disp%show("getGammaIncUpp(x = [0._RKD, 1._RKD, 10._RKD], kappa = 2._RKD)")
53 call disp%show( getGammaIncUpp(x = [0._RKD, 1._RKD, 10._RKD], kappa = 2._RKD) )
54 call disp%skip()
55
56 call disp%skip()
57 call disp%show("getGammaIncUpp(x = [0._RKH, 1._RKH, 10._RKH], kappa = 2._RKH)")
58 call disp%show( getGammaIncUpp(x = [0._RKH, 1._RKH, 10._RKH], kappa = 2._RKH) )
59 call disp%skip()
60
61
62 call disp%skip()
63 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
64 call disp%show("! Compute the regularized Upper Incomplete Gamma Function for a vector of kappa parameters.")
65 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
66 call disp%skip()
67
68
69 call disp%skip()
70 call disp%show("getGammaIncUpp(x = 1._RKS, kappa = [0.1_RKS, 1._RKS, 10._RKS])")
71 call disp%show( getGammaIncUpp(x = 1._RKS, kappa = [0.1_RKS, 1._RKS, 10._RKS]) )
72 call disp%skip()
73
74 call disp%skip()
75 call disp%show("getGammaIncUpp(x = 1._RKD, kappa = [0.1_RKD, 1._RKD, 10._RKD])")
76 call disp%show( getGammaIncUpp(x = 1._RKD, kappa = [0.1_RKD, 1._RKD, 10._RKD]) )
77 call disp%skip()
78
79 call disp%skip()
80 call disp%show("getGammaIncUpp(x = 1._RKH, kappa = [0.1_RKH, 1._RKH, 10._RKH])")
81 call disp%show( getGammaIncUpp(x = 1._RKH, kappa = [0.1_RKH, 1._RKH, 10._RKH]) )
82 call disp%skip()
83
84
85 call disp%skip()
86 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
87 call disp%show("! Compute the regularized Upper Incomplete Gamma Function for a vector of points and kappa parameters.")
88 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
89 call disp%skip()
90
91
92 call disp%skip()
93 call disp%show("getGammaIncUpp(x = [1._RKS, 1._RKS, 1._RKS], kappa = [0.1_RKS, 1._RKS, 10._RKS])")
94 call disp%show( getGammaIncUpp(x = [1._RKS, 1._RKS, 1._RKS], kappa = [0.1_RKS, 1._RKS, 10._RKS]) )
95 call disp%skip()
96
97 call disp%skip()
98 call disp%show("getGammaIncUpp(x = [1._RKD, 1._RKD, 1._RKD], kappa = [0.1_RKD, 1._RKD, 10._RKD])")
99 call disp%show( getGammaIncUpp(x = [1._RKD, 1._RKD, 1._RKD], kappa = [0.1_RKD, 1._RKD, 10._RKD]) )
100 call disp%skip()
101
102 call disp%skip()
103 call disp%show("getGammaIncUpp(x = [1._RKH, 1._RKH, 1._RKH], kappa = [0.1_RKH, 1._RKH, 10._RKH])")
104 call disp%show( getGammaIncUpp(x = [1._RKH, 1._RKH, 1._RKH], kappa = [0.1_RKH, 1._RKH, 10._RKH]) )
105 call disp%skip()
106
107
108 call disp%skip()
109 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
110 call disp%show("! Compute the regularized Upper Incomplete Gamma Function for a fixed point and kappa parameter, but with different accuracies.")
111 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
112 call disp%skip()
113
114 call disp%skip()
115 call disp%show("getGammaIncUpp(x = 1._RKH, kappa = 2._RKH, tol = [1.e-8_RKH, 1.e-16_RKH, 1.e-32_RKH])")
116 call disp%show( getGammaIncUpp(x = 1._RKH, kappa = 2._RKH, tol = [1.e-8_RKH, 1.e-16_RKH, 1.e-32_RKH]) )
117 call disp%skip()
118
119
120 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 ! Output an example array of the regularized Upper Incomplete Gamma function for visualization.
122 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123
124 block
125
126 use pm_arraySpace, only: setLinSpace
127 integer(IK) , parameter :: NP = 1000_IK
128 real(RKS) :: x_RKS(NP)
129 integer :: fileUnit, i
130
131 call setLinSpace(x_RKS, 0._RKS, 10._RKS)
132 open(newunit = fileUnit, file = "getGammaIncUpp.RK.txt")
133 do i = 1, NP
134 write(fileUnit, "(*(g0,:,' '))" ) x_RKS(i), getGammaIncUpp(x_RKS(i), kappa = [1.0_RKS, 2.5_RKS, 5.0_RKS])
135 end do
136 close(fileUnit)
137
138 end block
139
140end program example
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.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
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...
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 LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
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 RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
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
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! Compute the regularized Upper Incomplete Gamma Function using its series representation.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9getGammaIncUpp(x = 1.5_RKS, kappa = 2._RKS)
10+0.557825506
11
12
13getGammaIncUpp(x = 1.5_RKD, kappa = 2._RKD)
14+0.55782540037107464
15
16
17getGammaIncUpp(x = 1.5_RKH, kappa = 2._RKH)
18+0.557825400371074572333201176910031393
19
20
21!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22! Compute the regularized Upper Incomplete Gamma Function for a vector of points.
23!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
25
26getGammaIncUpp(x = [0._RKS, 1._RKS, 10._RKS], kappa = 2._RKS)
27+1.00000000, +0.735758901, +0.499399262E-3
28
29
30getGammaIncUpp(x = [0._RKD, 1._RKD, 10._RKD], kappa = 2._RKD)
31+1.0000000000000000, +0.73575888234288467, +0.49939922738733355E-3
32
33
34getGammaIncUpp(x = [0._RKH, 1._RKH, 10._RKH], kappa = 2._RKH)
35+1.00000000000000000000000000000000000, +0.735758882342884643191047540322921938, +0.499399227387333366891506671166056614E-3
36
37
38!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39! Compute the regularized Upper Incomplete Gamma Function for a vector of kappa parameters.
40!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42
43getGammaIncUpp(x = 1._RKS, kappa = [0.1_RKS, 1._RKS, 10._RKS])
44+0.241275430E-1, +0.367879510, +0.999999881
45
46
47getGammaIncUpp(x = 1._RKD, kappa = [0.1_RKD, 1._RKD, 10._RKD])
48+0.24127343726327410E-1, +0.36787944117144222, +0.99999988857452171
49
50
51getGammaIncUpp(x = 1._RKH, kappa = [0.1_RKH, 1._RKH, 10._RKH])
52+0.241273437263277773829694356333548275E-1, +0.367879441171442321595523770161460776, +0.999999888574521661279322646949312805
53
54
55!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56! Compute the regularized Upper Incomplete Gamma Function for a vector of points and kappa parameters.
57!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
59
60getGammaIncUpp(x = [1._RKS, 1._RKS, 1._RKS], kappa = [0.1_RKS, 1._RKS, 10._RKS])
61+0.241275430E-1, +0.367879510, +0.999999881
62
63
64getGammaIncUpp(x = [1._RKD, 1._RKD, 1._RKD], kappa = [0.1_RKD, 1._RKD, 10._RKD])
65+0.24127343726327410E-1, +0.36787944117144222, +0.99999988857452171
66
67
68getGammaIncUpp(x = [1._RKH, 1._RKH, 1._RKH], kappa = [0.1_RKH, 1._RKH, 10._RKH])
69+0.241273437263277773829694356333548275E-1, +0.367879441171442321595523770161460776, +0.999999888574521661279322646949312805
70
71
72!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73! Compute the regularized Upper Incomplete Gamma Function for a fixed point and kappa parameter, but with different accuracies.
74!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
76
77getGammaIncUpp(x = 1._RKH, kappa = 2._RKH, tol = [1.e-8_RKH, 1.e-16_RKH, 1.e-32_RKH])
78+0.735758882406482416462388959316297660, +0.735758882342884643349800300430248151, +0.735758882342884643191047540322921938
79
80

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
9fontsize = 17
10
11kind = "RK"
12label = [ r"shape: $\kappa = 1.0$"
13 , r"shape: $\kappa = 2.5$"
14 , r"shape: $\kappa = 5.0$"
15 ]
16
17pattern = "*."+kind+".txt"
18fileList = glob.glob(pattern)
19if len(fileList) == 1:
20
21 df = pd.read_csv(fileList[0], delimiter = " ")
22
23 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
24 ax = plt.subplot()
25
26 for i in range(1,len(df.values[0,:]+1)):
27
28 plt.plot( df.values[:, 0]
29 , df.values[:,i]
30 , linewidth = 2
31 )
32
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)
37
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")
41
42 ax.legend ( label
43 , fontsize = fontsize
44 #, loc = "center left"
45 #, bbox_to_anchor = (1, 0.5)
46 )
47
48 plt.savefig(fileList[0].replace(".txt",".png"))
49
50else:
51
52 sys.exit("Ambiguous file list exists.")

Visualization of the example output
Test:
test_pm_mathGamma
Remarks
See Numerical Recipes by Press et al. 1992 for further details of the Incomplete Gamma function.

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.

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:
Fatemeh Bagheri, Monday 12:36 pm, August 16, 2021, Dallas TX

Definition at line 311 of file pm_mathGamma.F90.

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