Generate and return the integral of the input function getFunc()
in the closed range [lb, ub]
using the Adaptive Romberg extrapolation method.
This Romberg integration method is quite powerful for sufficiently smooth (e.g., analytic) integrands getFunc()
, integrated over bounded intervals which contain no singularities, and where the end points are also nonsingular.
- Parameters
-
| getFunc | : The input function to be integrated (i.e., the integrand).
- On entry, it must take an input scalar of the same type and kind as
quadRomb .
- On exit, it must generate an input scalar of the same type and kind as
quadRomb , representing the corresponding function value.
The following illustrates the general interface of getFunc : function getFunc(x) result(func)
real(RK) , intent(in) :: x
real(RK) :: func
end function
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
where RKG refers to any desired real kind supported by the processor.
|
[in] | lb | : The input scalar of the same type and kind as the output quadRomb , containing the lower bound of the integration. |
[in] | ub | : The input scalar of the same type and kind as the output quadRomb , containing the upper bound of the integration. |
[in] | tol | : The input scalar of the same type and kind as the output quadRomb , containing the relative error the integration.
The algorithm converges if \(\ms{relerr} ~(~\equiv |\Delta\ms{quadRomb}|~) ~\leq~ \ms{tol} \times | \ms{quadRomb} |\).
Note that tol > epsilon(0._RKG) must hold at all times for integration to converge. Here RKG is the desired real kind of the output.
Ideally, set tol to a value such that tol < epsilon(0._RKG) * 100 holds to ensure convergence.
|
[in] | nref | : The input scalar integer of default kind IK, representing the number of refinements to be used in the Romberg method.
Think of nref as the maximum possible degree of the polynomial extrapolation used for approximating the integral at any stage.
-
The smaller values of
nref can delay an accurate estimation of the integral via the Romberg method.
-
The larger values of
nref can delay the first estimation of the integral by requiring more function evaluations.
-
The computational precision of the
real kind used in this procedure imposes an upper limit on the value of nref .
The maximum value for nref is roughly equal to int(log(epsilon(1._RKG)) / log(0.25)) with RKG representing the real kind used for the integration.
-
The maximum
nref for real32 , real64 , real128 are respectively 12 , 26 , 56 .
-
If the specified
nref is larger than the maximum possible value, the integration will fail to converge.
-
The number
nref = 2 corresponds to the famous Simpson integration rule.
-
A number between 4-6 is frequently a reasonable choice.
|
[out] | relerr | : The output scalar of the same type and kind as the output quadRomb containing the final estimated relative error in the result.
By definition, this is always a positive value if the integration converges.
Specify the relerr optional output argument to monitor convergence.
If relerr < 0. , then the integration has failed to converge.
(optional. If missing and the integration fails to converge, the program will halt by calling error stop .)
|
[out] | neval | : The output scalar integer of default kind IK, representing the number of function evaluations made within the integrator.
(optional. It can be present if and only if relerr argument is also present.) |
- Returns
quadRomb
: The output scalar real
of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128), containing the integration result.
Possible calling interfaces ⛓
quadRomb
= getQuadRomb(getFunc, lb, ub, tol, nref, relerr)
quadRomb
= getQuadRomb(getFunc, lb, ub, tol, nref, relerr, neval)
quadRomb
= getQuadRomb(getFunc, lb, ub, tol, nref, interval)
quadRomb
= getQuadRomb(getFunc, lb, ub, tol, nref, interval, relerr)
quadRomb
= getQuadRomb(getFunc, lb, ub, tol, nref, interval, relerr, neval)
Generate and return the integral of the input function getFunc() in the closed range [lb,...
This module contains classes and procedures to perform numerical integrations.
- Warning
- The procedures of this generic interface will behave differently if the integration fails to converge:
-
If the optional
relerr
output argument is missing, the program will halt by calling error stop
upon integration convergence failure.
-
If the optional
relerr
output argument is present, the program will return relerr < 0.
to indicate integration convergence failure.
- See also
- getQuadErr
Example usage ⛓
11 integer,
parameter :: SP
= kind(
0.e0), DP
= kind(
0.d0)
15 real(SP) :: quad_sp, quadref_sp, relerr_sp, alpha_sp, beta_sp
16 real(DP) :: quad_dp, quadref_dp, relerr_dp, alpha_dp, beta_dp
17 real(QP) :: quad_qp, quadref_qp, relerr_qp, alpha_qp, beta_qp
19 type(display_type) :: disp
23 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
25 call disp%show(
"! Compute the Cumulative Distribution Function (CDF) over a closed interval of the Beta distribution by numerical integration.")
26 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
27 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
31 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
32 call disp%show(
"! Compute the numerical integration with single precision.")
33 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
41 call disp%show(
"quadref_sp = getBetaInc(1., alpha = alpha_sp, beta = beta_sp) - getBetaInc(0., alpha = alpha_sp, beta = beta_sp)")
42 quadref_sp
= getBetaInc(
1., alpha
= alpha_sp, beta
= beta_sp)
- getBetaInc(
0., alpha
= alpha_sp, beta
= beta_sp)
45 call disp%show(
"quad_sp = getQuadRomb(getFunc = getBetaPDF_SP, lb = 0., ub = 1., tol = epsilon(1.) * 100, nref = 4_IK, relerr = relerr_sp, neval = neval)")
46 quad_sp
= getQuadRomb(getFunc
= getBetaPDF_SP, lb
= 0., ub
= 1., tol
= epsilon(
1.)
* 100, nref
= 4_IK, relerr
= relerr_sp, neval
= neval)
47 call disp%show(
"if (relerr_sp < 0.) error stop 'Integration failed to converge.'")
48 if (relerr_sp
< 0.)
error stop 'Integration failed to converge.'
49 call disp%show(
"relerr_sp ! < 0. if integration fails.")
51 call disp%show(
"neval ! # calls to the integrand.")
58 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
59 call disp%show(
"! Compute the numerical integration with double precision.")
60 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
68 call disp%show(
"quadref_dp = getBetaInc(1.d0, alpha = alpha_dp, beta = beta_dp) - getBetaInc(0.d0, alpha = alpha_dp, beta = beta_dp)")
69 quadref_dp
= getBetaInc(
1.d0, alpha
= alpha_dp, beta
= beta_dp)
- getBetaInc(
0.d0, alpha
= alpha_dp, beta
= beta_dp)
72 call disp%show(
"quad_dp = getQuadRomb(getFunc = getBetaPDF_DP, lb = 0.d0, ub = 1.d0, tol = epsilon(1.d0) * 100, nref = 4_IK, relerr = relerr_dp, neval = neval)")
73 quad_dp
= getQuadRomb(getFunc
= getBetaPDF_DP, lb
= 0.d0, ub
= 1.d0, tol
= epsilon(
1.d0)
* 100, nref
= 4_IK, relerr
= relerr_dp, neval
= neval)
74 call disp%show(
"if (relerr_dp < 0.) error stop 'Integration failed to converge.'")
75 if (relerr_dp
< 0.)
error stop 'Integration failed to converge.'
76 call disp%show(
"relerr_dp ! < 0. if integration fails.")
78 call disp%show(
"neval ! # calls to the integrand.")
85 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
86 call disp%show(
"! Compute the numerical integration with quadro precision.")
87 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
95 call disp%show(
"quadref_qp = getBetaInc(1._QP, alpha = alpha_qp, beta = beta_qp) - getBetaInc(0._QP, alpha = alpha_qp, beta = beta_qp)")
96 quadref_qp
= getBetaInc(
1._QP, alpha
= alpha_qp, beta
= beta_qp)
- getBetaInc(
0._QP, alpha
= alpha_qp, beta
= beta_qp)
99 call disp%show(
"quad_qp = getQuadRomb(getFunc = getBetaPDF_QP, lb = 0._QP, ub = 1._QP, tol = epsilon(1._QP) * 100, nref = 4_IK, relerr = relerr_qp, neval = neval)")
100 quad_qp
= getQuadRomb(getFunc
= getBetaPDF_QP, lb
= 0._QP, ub
= 1._QP, tol
= epsilon(
1._QP)
* 100, nref
= 4_IK, relerr
= relerr_qp, neval
= neval)
101 call disp%show(
"if (relerr_qp < 0.) error stop 'Integration failed to converge.'")
102 if (relerr_qp
< 0.)
error stop 'Integration failed to converge.'
103 call disp%show(
"relerr_qp ! < 0. if integration fails.")
105 call disp%show(
"neval ! # calls to the integrand.")
107 call disp%show(
"quad_qp ! integral")
113 function getBetaPDF_SP(x)
result(betaPDF)
114 real ,
intent(in) :: x
116 betaPDF
= getBetaPDF(x, alpha
= alpha_sp, beta
= beta_sp)
119 function getBetaPDF_DP(x)
result(betaPDF)
120 real(DP),
intent(in) :: x
122 betaPDF
= getBetaPDF(x, alpha
= alpha_dp, beta
= beta_dp)
125 function getBetaPDF_QP(x)
result(betaPDF)
126 real(QP),
intent(in) :: x
128 betaPDF
= getBetaPDF(x, alpha
= alpha_qp, beta
= beta_qp)
Generate and return the Probability Density Function (PDF) of the Beta distribution for an input x wi...
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.
Generate and return the regularized Incomplete Beta Function as defined in the details section of pm...
This module contains classes and procedures for computing various statistical quantities related to t...
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.
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
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...
This module contains classes and procedures for computing the mathematical Beta Function and its inve...
Generate and return an object of type display_type.
This is the indicator type for generating instances of objects that indicate the integration interval...
This is the indicator type for generating instances of objects that indicate the integration interval...
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 ⛓
16quadref_sp
= getBetaInc(
1., alpha
= alpha_sp, beta
= beta_sp)
- getBetaInc(
0., alpha
= alpha_sp, beta
= beta_sp)
19quad_sp
= getQuadRomb(getFunc
= getBetaPDF_SP, lb
= 0., ub
= 1., tol
= epsilon(
1.)
* 100, nref
= 4_IK, relerr
= relerr_sp, neval
= neval)
20if (relerr_sp
< 0.)
error stop 'Integration failed to converge.'
36quadref_dp
= getBetaInc(
1.d0, alpha
= alpha_dp, beta
= beta_dp)
- getBetaInc(
0.d0, alpha
= alpha_dp, beta
= beta_dp)
39quad_dp
= getQuadRomb(getFunc
= getBetaPDF_DP, lb
= 0.d0, ub
= 1.d0, tol
= epsilon(
1.d0)
* 100, nref
= 4_IK, relerr
= relerr_dp, neval
= neval)
40if (relerr_dp
< 0.)
error stop 'Integration failed to converge.'
42+0.11564823173178713E-17
56quadref_qp
= getBetaInc(
1._QP, alpha
= alpha_qp, beta
= beta_qp)
- getBetaInc(
0._QP, alpha
= alpha_qp, beta
= beta_qp)
58+1.00000000000000000000000000000000000
59quad_qp
= getQuadRomb(getFunc
= getBetaPDF_QP, lb
= 0._QP, ub
= 1._QP, tol
= epsilon(
1._QP)
* 100, nref
= 4_IK, relerr
= relerr_qp, neval
= neval)
60if (relerr_qp
< 0.)
error stop 'Integration failed to converge.'
62+0.152851582887875861353649043062295812E-35
66+1.00000000000000000000000000000000019
- Test:
- test_pm_quadRomb
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:
- Amir Shahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Joshua Alexander Osborne, May 28, 2020, 8:58 PM, Arlington, TX
Definition at line 396 of file pm_quadRomb.F90.