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

Return the regularized Lower Incomplete Gamma function for the specified shape parameter ( \(\kappa\)) and upper limit of the integral x. More...

Detailed Description

Return the regularized Lower Incomplete Gamma function for the specified shape parameter ( \(\kappa\)) and upper limit of the integral x.

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)\) should hold, with \(\kappa\) representing the shape parameter of the Gamma function (or distribution) and \(x\) representing the upper limit in the integral of the Lower Incomplete Gamma function.

Note that this integral is bounded between zero and one ( \([0,1]\)).

The regularized Lower Incomplete Gamma function also represents the Cumulative Distribution Function (CDF) of the univariate Gamma distribution with the specified shape parameter and standardized x (with the scale parameter of unity).

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
[out]gammaIncLow: The output scalar of the same type and kind as the input argument x representing the Lower Incomplete Gamma function for the specified kappa and lower limit.
Note that gammaIncLow is, by definition, always positive in the range \([0, 1]\).
[out]gammaIncUpp: The output scalar of same type and kind as the input argument x representing the Upper Incomplete Gamma function for the specified kappa and lower limit.
Note that gammaIncUpp is, by definition, always positive.
[in]x: The input scalar of the 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 \(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)\).
[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 zero if the algorithm succeeds to converge or a negative value if the algorithm 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.


Possible calling interfaces

call setGammaInc(gammaIncLow, gammaIncUpp, x, kappa, info)
Return the regularized Lower Incomplete Gamma function for the specified shape parameter ( ) and uppe...
This module contains procedures and generic interfaces for the Lower and Upper Incomplete Gamma funct...
Warning
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.
Remarks
The procedures under discussion are elemental.
See also
setGammaInc
getGammaIncUpp
getGammaIncLow


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 integer(IK) , parameter :: NP = 1000_IK
13 real(RKH) :: gamIncLow_RKH, gamIncUpp_RKH, x_RKH, kappa_RKH
14 real(RKD) :: gamIncLow_RKD, gamIncUpp_RKD, x_RKD, kappa_RKD
15 real(RKS) :: gamIncLow_RKS, gamIncUpp_RKS, x_RKS, kappa_RKS
16 integer(IK) :: info
17
18 type(display_type) :: disp
19 disp = display_type(file = "main.out.F90")
20
21 kappa_RKH = 1.5_RKH
22 kappa_RKD = 1.5_RKD
23 kappa_RKS = 1.5_RKS
24
25 x_RKH = 2._RKH
26 x_RKD = 2._RKD
27 x_RKS = 2._RKS
28
29 call disp%skip()
30 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%show("! Compute the regularized Lower Incomplete Gamma Function using its series representation.")
33 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
34 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
35 call disp%skip()
36
37 call disp%skip()
38 call disp%show("x_RKS")
39 call disp%show( x_RKS )
40 call disp%show("kappa_RKS")
41 call disp%show( kappa_RKS )
42 call disp%show("call setGammaInc(gamIncLow_RKS, gamIncUpp_RKS, x_RKS, kappa = kappa_RKS, info = info)")
43 call setGammaInc(gamIncLow_RKS, gamIncUpp_RKS, x_RKS, kappa = kappa_RKS, info = info)
44 call disp%show("[gamIncLow_RKS, gamIncUpp_RKS]")
45 call disp%show( [gamIncLow_RKS, gamIncUpp_RKS] )
46 call disp%show("info")
47 call disp%show( info )
48 call disp%skip()
49
50 call disp%skip()
51 call disp%show("x_RKD")
52 call disp%show( x_RKD)
53 call disp%show("kappa_RKD")
54 call disp%show( kappa_RKD)
55 call disp%show("call setGammaInc(gamIncLow_RKD, gamIncUpp_RKD, x_RKD, kappa = kappa_RKD, info = info)")
56 call setGammaInc(gamIncLow_RKD, gamIncUpp_RKD, x_RKD, kappa = kappa_RKD, info = info)
57 call disp%show("[gamIncLow_RKD, gamIncUpp_RKD]")
58 call disp%show( [gamIncLow_RKD, gamIncUpp_RKD])
59 call disp%show("info")
60 call disp%show( info )
61 call disp%skip()
62
63 call disp%skip()
64 call disp%show("x_RKH")
65 call disp%show( x_RKH )
66 call disp%show("kappa_RKH")
67 call disp%show( kappa_RKH )
68 call disp%show("call setGammaInc(gamIncLow_RKH, gamIncUpp_RKH, x_RKH, kappa = kappa_RKH, info = info)")
69 call setGammaInc(gamIncLow_RKH, gamIncUpp_RKH, x_RKH, kappa = kappa_RKH, info = info)
70 call disp%show("[gamIncLow_RKH, gamIncUpp_RKH]")
71 call disp%show( [gamIncLow_RKH, gamIncUpp_RKH] )
72 call disp%show("info")
73 call disp%show( info )
74 call disp%skip()
75
76 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 ! Output an example array of the regularized Lower Incomplete Gamma function for visualization.
78 !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80 block
81
82 use pm_arraySpace, only: setLinSpace
83 real(RKS) :: x_RKS(NP)
84 integer :: fileUnit, i
85
86 call setLinSpace(x_RKS, 0._RKS, 8._RKS)
87 open(newunit = fileUnit, file = "setGammaInc.RK.txt")
88 do i = 1, NP
89 call setGammaInc(gamIncLow_RKS, gamIncUpp_RKS, x_RKS(i), kappa = kappa_RKS, info = info)
90 write(fileUnit,"(2(g0,:,' '))") x_RKS(i), gamIncLow_RKS
91 end do
92 close(fileUnit)
93
94 end block
95
96end 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 Lower Incomplete Gamma Function using its series representation.
5!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7
8
9x_RKS
10+2.00000000
11kappa_RKS
12+1.50000000
13call setGammaInc(gamIncLow_RKS, gamIncUpp_RKS, x_RKS, kappa = kappa_RKS, info = info)
14[gamIncLow_RKS, gamIncUpp_RKS]
15+0.738535821, +0.261464179
16info
17+0
18
19
20x_RKD
21+2.0000000000000000
22kappa_RKD
23+1.5000000000000000
24call setGammaInc(gamIncLow_RKD, gamIncUpp_RKD, x_RKD, kappa = kappa_RKD, info = info)
25[gamIncLow_RKD, gamIncUpp_RKD]
26+0.73853587005088861, +0.26146412994911145
27info
28+0
29
30
31x_RKH
32+2.00000000000000000000000000000000000
33kappa_RKH
34+1.50000000000000000000000000000000000
35call setGammaInc(gamIncLow_RKH, gamIncUpp_RKH, x_RKH, kappa = kappa_RKH, info = info)
36[gamIncLow_RKH, gamIncUpp_RKH]
37+0.738535870050889377797177924024077018, +0.261464129949110622202822075975923030
38info
39+0
40
41

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
11marker ={ "CK" : "-"
12 , "IK" : "."
13 , "RK" : "-"
14 }
15xlab = { "CK" : r"x ( real/imaginary )"
16 , "IK" : r"x ( integer-valued )"
17 , "RK" : r"x ( real-valued )"
18 }
19labels = [r"shape parameter: $\kappa = 2$"]
20
21for kind in ["IK", "CK", "RK"]:
22
23 pattern = "*." + kind + ".txt"
24 fileList = glob.glob(pattern)
25 if len(fileList) == 1:
26
27 df = pd.read_csv(fileList[0], delimiter = " ")
28
29 fig = plt.figure(figsize = 1.25 * np.array([6.4, 4.8]), dpi = 200)
30 ax = plt.subplot()
31
32 if kind == "CK":
33 plt.plot( df.values[:, 0]
34 , df.values[:,2]
35 , marker[kind]
36 , color = "r"
37 )
38 plt.plot( df.values[:,1]
39 , df.values[:,3]
40 , marker[kind]
41 , color = "blue"
42 )
43 else:
44 plt.plot( df.values[:, 0]
45 , df.values[:,1]
46 , marker[kind]
47 , color = "r"
48 )
49
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\nIncomplete Gamma Function", fontsize = fontsize)
54
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")
58
59 ax.legend ( labels
60 , fontsize = fontsize
61 #, loc = "center left"
62 #, bbox_to_anchor = (1, 0.5)
63 )
64
65 plt.savefig(fileList[0].replace(".txt",".png"))
66
67 elif len(fileList) > 1:
68
69 sys.exit("Ambiguous file list exists.")

Visualization of the example output
Test:
test_pm_mathGamma


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

Definition at line 416 of file pm_mathGamma.F90.


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