From e0737c56c1e384e05064a0c6e1ac46979371041b Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 19 Dec 2018 22:58:32 +0100 Subject: New upstream version 2.0.0+repack --- .../html/math_toolkit/sf_beta/beta_derivative.html | 102 +++ .../html/math_toolkit/sf_beta/beta_function.html | 318 +++++++ .../html/math_toolkit/sf_beta/ibeta_function.html | 893 ++++++++++++++++++++ .../math_toolkit/sf_beta/ibeta_inv_function.html | 912 +++++++++++++++++++++ 4 files changed, 2225 insertions(+) create mode 100644 boost/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html create mode 100644 boost/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html create mode 100644 boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html create mode 100644 boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html (limited to 'boost/libs/math/doc/html/math_toolkit/sf_beta') diff --git a/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html b/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html new file mode 100644 index 00000000..d759f98a --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html @@ -0,0 +1,102 @@ + + + +Derivative of the Incomplete Beta Function + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Synopsis +
+
#include <boost/math/special_functions/beta.hpp>
+
+
namespace boost{ namespace math{
+
+template <class T1, class T2, class T3>
+calculated-result-type ibeta_derivative(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_derivative(T1 a, T2 b, T3 x, const Policy&);
+
+}} // namespaces
+
+
+ + Description +
+

+ This function finds some uses in statistical distributions: it computes the + partial derivative with respect to x of the incomplete + beta function ibeta. +

+

+ +

+

+ The return type of this function is computed using the result + type calculation rules when T1, T2 and T3 are different + types. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
+ + Accuracy +
+

+ Almost identical to the incomplete beta function ibeta. +

+
+ + Implementation +
+

+ This function just expose some of the internals of the incomplete beta function + ibeta: refer to + the documentation for that function for more information. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html b/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html new file mode 100644 index 00000000..252486ae --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html @@ -0,0 +1,318 @@ + + + +Beta + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+

+Beta +

+
+ + Synopsis +
+
#include <boost/math/special_functions/beta.hpp>
+
+
namespace boost{ namespace math{
+
+template <class T1, class T2>
+calculated-result-type beta(T1 a, T2 b);
+
+template <class T1, class T2, class Policy>
+calculated-result-type beta(T1 a, T2 b, const Policy&);
+
+}} // namespaces
+
+
+ + Description +
+

+ The beta function is defined by: +

+

+ +

+

+ +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+

+ There are effectively two versions of this function internally: a fully generic + version that is slow, but reasonably accurate, and a much more efficient + approximation that is used where the number of digits in the significand + of T correspond to a certain Lanczos + approximation. In practice any built-in floating-point type you will + encounter has an appropriate Lanczos + approximation defined for it. It is also possible, given enough machine + time, to generate further Lanczos approximation's + using the program libs/math/tools/lanczos_generator.cpp. +

+

+ The return type of these functions is computed using the result + type calculation rules when T1 and T2 are different types. +

+
+ + Accuracy +
+

+ The following table shows peak errors for various domains of input arguments, + along with comparisons to the GSL-1.9 + and Cephes libraries. + Note that only results for the widest floating point type on the system are + given as narrower types have effectively + zero error. +

+
+

Table 6.17. Error rates for beta

+
+++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Beta Function: Small Values +

+
+

+ Max = 1.75ε (Mean = 0.828ε) +

+
+

+ Max = 2.65ε (Mean = 1.22ε)

+ (<tr1/cmath>: Max = 11.9ε (Mean = 7.03ε)) +

+
+

+ Max = 0ε (Mean = 0ε)

(GSL + 1.16: Max = 3.94ε (Mean = 1.44ε))
(Rmath + 3.0.2: Max = 1.14ε (Mean = 0.601ε))
(Cephes: + Max = 1.97ε (Mean = 0.934ε)) +

+
+

+ Max = 2.86ε (Mean = 1.31ε) +

+
+

+ Beta Function: Medium Values +

+
+

+ Max = 99.1ε (Mean = 22.4ε) +

+
+

+ Max = 60.4ε (Mean = 19.4ε)

+ (<tr1/cmath>: Max = 1.07e+03ε (Mean = + 264ε)) +

+
+

+ Max = 0.978ε (Mean = 0.0578ε)
+
(GSL 1.16: Max = 1.18e+03ε (Mean = 238ε))
+ (Rmath 3.0.2: Max = 1.09e+03ε (Mean = 265ε))
+ (Cephes: Max = 1.5e+03ε (Mean = 329ε)) +

+
+

+ Max = 107ε (Mean = 24.5ε) +

+
+

+ Beta Function: Divergent Values +

+
+

+ Max = 10.7ε (Mean = 2.22ε) +

+
+

+ Max = 10.3ε (Mean = 2.41ε)

+ (<tr1/cmath>: Max = 128ε (Mean = 23.8ε)) +

+
+

+ Max = 0ε (Mean = 0ε)

(GSL + 1.16: Max = 12.1ε (Mean = 1.99ε))
(Rmath + 3.0.2: Max = 176ε (Mean = 28ε))
(Cephes: + Max = 175ε (Mean = 22ε)) +

+
+

+ Max = 19.7ε (Mean = 2.75ε) +

+
+
+

+ Note that the worst errors occur when a or b are large, and that when this + is the case the result is very close to zero, so absolute errors will be + very small. +

+
+ + Testing +
+

+ A mixture of spot tests of exact values, and randomly generated test data + are used: the test data was computed using NTL::RR + at 1000-bit precision. +

+
+ + Implementation +
+

+ Traditional methods of evaluating the beta function either involve evaluating + the gamma functions directly, or taking logarithms and then exponentiating + the result. However, the former is prone to overflows for even very modest + arguments, while the latter is prone to cancellation errors. As an alternative, + if we regard the gamma function as a white-box containing the Lanczos + approximation, then we can combine the power terms: +

+

+ +

+

+ which is almost the ideal solution, however almost all of the error occurs + in evaluating the power terms when a or b + are large. If we assume that a > b then the larger + of the two power terms can be reduced by a factor of b, + which immediately cuts the maximum error in half: +

+

+ +

+

+ This may not be the final solution, but it is very competitive compared to + other implementation methods. +

+

+ The generic implementation - where no Lanczos + approximation approximation is available - is implemented in a very + similar way to the generic version of the gamma function. Again in order + to avoid numerical overflow the power terms that prefix the series and continued + fraction parts are collected together into: +

+

+ +

+

+ where la, lb and lc are the integration limits used for a, b, and a+b. +

+

+ There are a few special cases worth mentioning: +

+

+ When a or b are less than one, + we can use the recurrence relations: +

+

+ +

+

+ +

+

+ to move to a more favorable region where they are both greater than 1. +

+

+ In addition: +

+

+ +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html b/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html new file mode 100644 index 00000000..be444993 --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html @@ -0,0 +1,893 @@ + + + +Incomplete Beta Functions + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Synopsis +
+
#include <boost/math/special_functions/beta.hpp>
+
+
namespace boost{ namespace math{
+
+template <class T1, class T2, class T3>
+calculated-result-type ibeta(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta(T1 a, T2 b, T3 x, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibetac(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac(T1 a, T2 b, T3 x, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type beta(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type beta(T1 a, T2 b, T3 x, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type betac(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type betac(T1 a, T2 b, T3 x, const Policy&);
+
+}} // namespaces
+
+
+ + Description +
+

+ There are four incomplete + beta functions : two are normalised versions (also known as regularized + beta functions) that return values in the range [0, 1], and two are non-normalised + and return values in the range [0, beta(a, + b)]. Users interested in statistical applications should use the normalised + (or regularized + ) versions (ibeta and ibetac). +

+

+ All of these functions require 0 <= x <= 1. +

+

+ The normalized functions ibeta + and ibetac require + a,b >= 0, and in addition that not both a + and b are zero. +

+

+ The functions beta + and betac require + a,b > 0. +

+

+ The return type of these functions is computed using the result + type calculation rules when T1, T2 and T3 are different + types. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibeta(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta(T1 a, T2 b, T3 x, const Policy&);
+
+

+ Returns the normalised incomplete beta function of a, b and x: +

+

+ +

+

+ +

+
template <class T1, class T2, class T3>
+calculated-result-type ibetac(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac(T1 a, T2 b, T3 x, const Policy&);
+
+

+ Returns the normalised complement of the incomplete beta function of a, b + and x: +

+

+ +

+
template <class T1, class T2, class T3>
+calculated-result-type beta(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type beta(T1 a, T2 b, T3 x, const Policy&);
+
+

+ Returns the full (non-normalised) incomplete beta function of a, b and x: +

+

+ +

+
template <class T1, class T2, class T3>
+calculated-result-type betac(T1 a, T2 b, T3 x);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type betac(T1 a, T2 b, T3 x, const Policy&);
+
+

+ Returns the full (non-normalised) complement of the incomplete beta function + of a, b and x: +

+

+ +

+
+ + Accuracy +
+

+ The following tables give peak and mean relative errors in over various domains + of a, b and x, along with comparisons to the GSL-1.9 + and Cephes libraries. + Note that only results for the widest floating-point type on the system are + given as narrower types have effectively + zero error. +

+

+ Note that the results for 80 and 128-bit long doubles are noticeably higher + than for doubles: this is because the wider exponent range of these types + allow more extreme test cases to be tested. For example expected results + that are zero at double precision, may be finite but exceptionally small + with the wider exponent range of the long double types. +

+
+

Table 6.18. Error rates for ibeta

+
+++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Incomplete Beta Function: Small Values +

+
+

+ Max = 9.42ε (Mean = 2.24ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(GSL + 1.16: Max = 682ε (Mean = 32.6ε))
(Rmath + 3.0.2: Max = 22.9ε (Mean = 3.35ε))
(Cephes: + Max = 22.7ε (Mean = 1.69ε)) +

+
+

+ Max = 6.27ε (Mean = 1.7ε) +

+
+

+ Max = 21.3ε (Mean = 2.74ε) +

+
+

+ Incomplete Beta Function: Medium Values +

+
+

+ Max = 108ε (Mean = 16.3ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(GSL + 1.16: Max = 690ε (Mean = 151ε))
(Rmath + 3.0.2: Max = 232ε (Mean = 27.9ε))
(Cephes: + Max = 1.55e+03ε (Mean = 121ε)) +

+
+

+ Max = 51.4ε (Mean = 12ε) +

+
+

+ Max = 124ε (Mean = 18.4ε) +

+
+

+ Incomplete Beta Function: Large and Diverse Values +

+
+

+ Max = 1.19e+003ε (Mean = 59.5ε) +

+
+

+ Max = 1.26ε (Mean = 0.063ε)

+ (GSL 1.16: Max = 3.9e+05ε (Mean = 1.82e+04ε) + And + other failures.)
(Rmath 3.0.2: + Max = 574ε (Mean = 49.4ε))
(Cephes: Max + = 5.92e+05ε (Mean = 2.17e+04ε)) +

+
+

+ Max = 1.96e+04ε (Mean = 997ε) +

+
+

+ Max = 4.98e+04ε (Mean = 2.07e+03ε) +

+
+

+ Incomplete Beta Function: Small Integer Values +

+
+

+ Max = 3.69ε (Mean = 0.765ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(GSL + 1.16: Max = 254ε (Mean = 50.9ε))
(Rmath + 3.0.2: Max = 62.2ε (Mean = 8.95ε))
(Cephes: + Max = 7.96ε (Mean = 1.3ε)) +

+
+

+ Max = 4.45ε (Mean = 0.814ε) +

+
+

+ Max = 44.5ε (Mean = 10.1ε) +

+
+
+
+

Table 6.19. Error rates for ibetac

+
+++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Incomplete Beta Function: Small Values +

+
+

+ Max = 6.56ε (Mean = 1.88ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(Rmath + 3.0.2: Max = 22.4ε (Mean = 3.67ε)) +

+
+

+ Max = 8.47ε (Mean = 1.68ε) +

+
+

+ Max = 13.8ε (Mean = 2.69ε) +

+
+

+ Incomplete Beta Function: Medium Values +

+
+

+ Max = 56.2ε (Mean = 14.1ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(Rmath + 3.0.2: Max = 204ε (Mean = 25.8ε)) +

+
+

+ Max = 75.3ε (Mean = 11.3ε) +

+
+

+ Max = 132ε (Mean = 19.8ε) +

+
+

+ Incomplete Beta Function: Large and Diverse Values +

+
+

+ Max = 1.87e+003ε (Mean = 93.8ε) +

+
+

+ Max = 0.981ε (Mean = 0.0638ε)
+
(Rmath 3.0.2: Max = 889ε (Mean = 68.4ε)) +

+
+

+ Max = 3.45e+04ε (Mean = 1.32e+03ε) +

+
+

+ Max = 4.26e+04ε (Mean = 1.54e+03ε) +

+
+

+ Incomplete Beta Function: Small Integer Values +

+
+

+ Max = 6.37ε (Mean = 1.03ε) +

+
+

+ Max = 0ε (Mean = 0ε)

(Rmath + 3.0.2: Max = 84.6ε (Mean = 18ε)) +

+
+

+ Max = 5.34ε (Mean = 1.11ε) +

+
+

+ Max = 107ε (Mean = 17.1ε) +

+
+
+
+

Table 6.20. Error rates for beta (incomplete)

+
+++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Incomplete Beta Function: Small Values +

+
+

+ Max = 11.1ε (Mean = 2.28ε) +

+
+

+ Max = 0ε (Mean = 0ε) +

+
+

+ Max = 12.5ε (Mean = 2.01ε) +

+
+

+ Max = 18.7ε (Mean = 3.19ε) +

+
+

+ Incomplete Beta Function: Medium Values +

+
+

+ Max = 91.1ε (Mean = 12.7ε) +

+
+

+ Max = 0.568ε (Mean = 0.0342ε) +

+
+

+ Max = 67.1ε (Mean = 13.3ε) +

+
+

+ Max = 174ε (Mean = 25ε) +

+
+

+ Incomplete Beta Function: Large and Diverse Values +

+
+

+ Max = 635ε (Mean = 29.5ε) +

+
+

+ Max = 0.999ε (Mean = 0.0399ε) +

+
+

+ Max = 6.84e+04ε (Mean = 2.76e+03ε) +

+
+

+ Max = 6.86e+04ε (Mean = 2.79e+03ε) +

+
+

+ Incomplete Beta Function: Small Integer Values +

+
+

+ Max = 26.8ε (Mean = 6.61ε) +

+
+

+ Max = 0.786ε (Mean = 0.0248ε) +

+
+

+ Max = 10.2ε (Mean = 3.49ε) +

+
+

+ Max = 51.8ε (Mean = 11ε) +

+
+
+
+

Table 6.21. Error rates for betac

+
+++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Incomplete Beta Function: Small Values +

+
+

+ Max = 12ε (Mean = 2.43ε) +

+
+

+ Max = 0.676ε (Mean = 0.0302ε) +

+
+

+ Max = 7.75ε (Mean = 1.91ε) +

+
+

+ Max = 12.6ε (Mean = 3.02ε) +

+
+

+ Incomplete Beta Function: Medium Values +

+
+

+ Max = 91.3ε (Mean = 14.8ε) +

+
+

+ Max = 0.949ε (Mean = 0.0944ε) +

+
+

+ Max = 63.5ε (Mean = 13.4ε) +

+
+

+ Max = 97.6ε (Mean = 24.3ε) +

+
+

+ Incomplete Beta Function: Large and Diverse Values +

+
+

+ Max = 3.72e+003ε (Mean = 113ε) +

+
+

+ Max = 1.12ε (Mean = 0.0458ε) +

+
+

+ Max = 1.05e+05ε (Mean = 5.45e+03ε) +

+
+

+ Max = 1.04e+05ε (Mean = 5.46e+03ε) +

+
+

+ Incomplete Beta Function: Small Integer Values +

+
+

+ Max = 26.7ε (Mean = 6.67ε) +

+
+

+ Max = 0.586ε (Mean = 0.0314ε) +

+
+

+ Max = 10.4ε (Mean = 3.54ε) +

+
+

+ Max = 103ε (Mean = 17.4ε) +

+
+
+
+ + Testing +
+

+ There are two sets of tests: spot tests compare values taken from Mathworld's + online function evaluator with this implementation: they provide + a basic "sanity check" for the implementation, with one spot-test + in each implementation-domain (see implementation notes below). +

+

+ Accuracy tests use data generated at very high precision (with NTL + RR class set at 1000-bit precision), using the "textbook" + continued fraction representation (refer to the first continued fraction + in the implementation discussion below). Note that this continued fraction + is not used in the implementation, and therefore we + have test data that is fully independent of the code. +

+
+ + Implementation +
+

+ This implementation is closely based upon "Algorithm + 708; Significant digit computation of the incomplete beta function ratios", + DiDonato and Morris, ACM, 1992. +

+

+ All four of these functions share a common implementation: this is passed + both x and y, and can return either p or q where these are related by: +

+

+ +

+

+ so at any point we can swap a for b, x for y and p for q if this results + in a more favourable position. Generally such swaps are performed so that + we always compute a value less than 0.9: when required this can then be subtracted + from 1 without undue cancellation error. +

+

+ The following continued fraction representation is found in many textbooks + but is not used in this implementation - it's both slower and less accurate + than the alternatives - however it is used to generate test data: +

+

+ +

+

+ The following continued fraction is due to Didonato + and Morris, and is used in this implementation when a and b are both + greater than 1: +

+

+ +

+

+ For smallish b and x then a series representation can be used: +

+

+ +

+

+ When b << a then the transition from 0 to 1 occurs very close to x + = 1 and some care has to be taken over the method of computation, in that + case the following series representation is used: +

+

+ + +

+

+ Where Q(a,x) is an incomplete + gamma function. Note that this method relies on keeping a table of + all the pn previously computed, which does limit the precision of the method, + depending upon the size of the table used. +

+

+ When a and b are both small integers, + then we can relate the incomplete beta to the binomial distribution and use + the following finite sum: +

+

+ +

+

+ Finally we can sidestep difficult areas, or move to an area with a more efficient + means of computation, by using the duplication formulae: +

+

+ +

+

+ +

+

+ The domains of a, b and x for which the various methods are used are identical + to those described in the Didonato + and Morris TOMS 708 paper. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html b/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html new file mode 100644 index 00000000..b0538b9b --- /dev/null +++ b/boost/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html @@ -0,0 +1,912 @@ + + + +The Incomplete Beta Function Inverses + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
#include <boost/math/special_functions/beta.hpp>
+
+
namespace boost{ namespace math{
+
+template <class T1, class T2, class T3>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, const Policy&);
+
+template <class T1, class T2, class T3, class T4>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, T4* py);
+
+template <class T1, class T2, class T3, class T4, class Policy>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, const Policy&);
+
+template <class T1, class T2, class T3, class T4>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, T4* py);
+
+template <class T1, class T2, class T3, class T4, class Policy>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibeta_inva(T1 b, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_inva(T1 b, T2 x, T3 p, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibetac_inva(T1 b, T2 x, T3 q);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_inva(T1 b, T2 x, T3 q, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibeta_invb(T1 a, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_invb(T1 a, T2 x, T3 p, const Policy&);
+
+template <class T1, class T2, class T3>
+calculated-result-type ibetac_invb(T1 a, T2 x, T3 q);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_invb(T1 a, T2 x, T3 q, const Policy&);
+
+}} // namespaces
+
+
+ + Description +
+

+ There are six incomplete + beta function inverses which allow you solve for any of the three + parameters to the incomplete beta, starting from either the result of the + incomplete beta (p) or its complement (q). +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
+ + + + + +
[Tip]Tip
+

+ When people normally talk about the inverse of the incomplete beta function, + they are talking about inverting on parameter x. These + are implemented here as ibeta_inv and ibetac_inv, and are by far the most + efficient of the inverses presented here. +

+

+ The inverses on the a and b parameters + find use in some statistical applications, but have to be computed by rather + brute force numerical techniques and are consequently several times slower. + These are implemented here as ibeta_inva and ibeta_invb, and complement + versions ibetac_inva and ibetac_invb. +

+
+

+ The return type of these functions is computed using the result + type calculation rules when called with arguments T1...TN + of different types. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, const Policy&);
+
+template <class T1, class T2, class T3, class T4>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, T4* py);
+
+template <class T1, class T2, class T3, class T4, class Policy>
+calculated-result-type ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy&);
+
+

+ Returns a value x such that: p + = ibeta(a, + b, x); and + sets *py + = 1 - x when + the py parameter is provided + and is non-null. Note that internally this function computes whichever is + the smaller of x and 1-x, + and therefore the value assigned to *py is free from cancellation errors. That + means that even if the function returns 1, + the value stored in *py + may be non-zero, albeit very small. +

+

+ Requires: a,b > 0 and 0 <= p <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, const Policy&);
+
+template <class T1, class T2, class T3, class T4>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, T4* py);
+
+template <class T1, class T2, class T3, class T4, class Policy>
+calculated-result-type ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy&);
+
+

+ Returns a value x such that: q + = ibetac(a, + b, x); and + sets *py + = 1 - x when + the py parameter is provided + and is non-null. Note that internally this function computes whichever is + the smaller of x and 1-x, + and therefore the value assigned to *py is free from cancellation errors. That + means that even if the function returns 1, + the value stored in *py + may be non-zero, albeit very small. +

+

+ Requires: a,b > 0 and 0 <= q <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibeta_inva(T1 b, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_inva(T1 b, T2 x, T3 p, const Policy&);
+
+

+ Returns a value a such that: p + = ibeta(a, + b, x); +

+

+ Requires: b > 0, 0 < x < 1 + and 0 <= p <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibetac_inva(T1 b, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_inva(T1 b, T2 x, T3 p, const Policy&);
+
+

+ Returns a value a such that: q + = ibetac(a, + b, x); +

+

+ Requires: b > 0, 0 < x < 1 + and 0 <= q <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibeta_invb(T1 b, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibeta_invb(T1 b, T2 x, T3 p, const Policy&);
+
+

+ Returns a value b such that: p + = ibeta(a, + b, x); +

+

+ Requires: a > 0, 0 < x < 1 + and 0 <= p <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
template <class T1, class T2, class T3>
+calculated-result-type ibetac_invb(T1 b, T2 x, T3 p);
+
+template <class T1, class T2, class T3, class Policy>
+calculated-result-type ibetac_invb(T1 b, T2 x, T3 p, const Policy&);
+
+

+ Returns a value b such that: q + = ibetac(a, + b, x); +

+

+ Requires: a > 0, 0 < x < 1 + and 0 <= q <= 1. +

+

+ The final Policy argument is optional and can + be used to control the behaviour of the function: how it handles errors, + what level of precision to use etc. Refer to the policy + documentation for more details. +

+
+ + Accuracy +
+

+ The accuracy of these functions should closely follow that of the regular + forward incomplete beta functions. However, note that in some parts of their + domain, these functions can be extremely sensitive to changes in input, particularly + when the argument p (or it's complement q) + is very close to 0 or 1. +

+

+ Comparisons to other libraries are shown below, note that our test data exercises + some rather extreme cases in the incomplete beta function which many other + libraries fail to handle: +

+
+

Table 6.22. Error rates for ibeta_inv

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 7.08e+003ε (Mean = 244ε) +

+
+

+ Max = 3.21ε (Mean = 0.158ε)

+ (Rmath 3.0.2: Max = +INFε (Mean + = +INFε) And + other failures.)
(Cephes: + Max = 1.28e+10ε (Mean = 5.17e+08ε)) +

+
+

+ Max = 4.53e+04ε (Mean = 2.93e+03ε) +

+
+

+ Max = 4.22e+04ε (Mean = 2.8e+03ε) +

+
+
+
+

Table 6.23. Error rates for ibetac_inv

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 5.53e+003ε (Mean = 220ε) +

+
+

+ Max = 1.71ε (Mean = 0.108ε)

+ (Rmath 3.0.2: Max = +INFε (Mean + = +INFε) And + other failures.)
(Cephes: + Max = 1.71ε (Mean = 0.108ε)) +

+
+

+ Max = 6.17e+04ε (Mean = 3.77e+03ε) +

+
+

+ Max = 5.15e+04ε (Mean = 3.51e+03ε) +

+
+
+
+

Table 6.24. Error rates for ibeta_inva

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 395ε (Mean = 24.7ε) +

+
+

+ Max = 0.602ε (Mean = 0.0239ε) +

+
+

+ Max = 377ε (Mean = 25.1ε) +

+
+

+ Max = 438ε (Mean = 31.6ε) +

+
+
+
+

Table 6.25. Error rates for ibetac_inva

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 408ε (Mean = 27.8ε) +

+
+

+ Max = 0.683ε (Mean = 0.0271ε) +

+
+

+ Max = 382ε (Mean = 22.2ε) +

+
+

+ Max = 315ε (Mean = 23.7ε) +

+
+
+
+

Table 6.26. Error rates for ibeta_invb

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 409ε (Mean = 17.9ε) +

+
+

+ Max = 0.836ε (Mean = 0.0491ε) +

+
+

+ Max = 407ε (Mean = 27.2ε) +

+
+

+ Max = 407ε (Mean = 24.4ε) +

+
+
+
+

Table 6.27. Error rates for ibetac_invb

+
+++++++ + + + + + + + + + + + + + + +
+ +

+ Microsoft Visual C++ version 12.0
Win32
double +

+
+

+ GNU C++ version 5.1.0
linux
double +

+
+

+ GNU C++ version 5.1.0
linux
long double +

+
+

+ Sun compiler version 0x5130
Sun Solaris
long double +

+
+

+ Inverse incomplete beta +

+
+

+ Max = 329ε (Mean = 18.2ε) +

+
+

+ Max = 0.724ε (Mean = 0.0303ε) +

+
+

+ Max = 317ε (Mean = 19.7ε) +

+
+

+ Max = 369ε (Mean = 21.7ε) +

+
+
+
+ + Testing +
+

+ There are two sets of tests: +

+
    +
  • + Basic sanity checks attempt to "round-trip" from a, + b and x to p or + q and back again. These tests have quite generous + tolerances: in general both the incomplete beta and its inverses change + so rapidly, that round tripping to more than a couple of significant + digits isn't possible. This is especially true when p + or q is very near one: in this case there isn't + enough "information content" in the input to the inverse function + to get back where you started. +
  • +
  • + Accuracy checks using high precision test values. These measure the accuracy + of the result, given exact input values. +
  • +
+
+ + Implementation + of ibeta_inv and ibetac_inv +
+

+ These two functions share a common implementation. +

+

+ First an initial approximation to x is computed then the last few bits are + cleaned up using Halley + iteration. The iteration limit is set to 1/2 of the number of bits + in T, which by experiment is sufficient to ensure that the inverses are at + least as accurate as the normal incomplete beta functions. Up to 5 iterations + may be required in extreme cases, although normally only one or two are required. + Further, the number of iterations required decreases with increasing a + and b (which generally form the more important use cases). +

+

+ The initial guesses used for iteration are obtained as follows: +

+

+ Firstly recall that: +

+

+ +

+

+ We may wish to start from either p or q, and to calculate either x or y. + In addition at any stage we can exchange a for b, p for q, and x for y if + it results in a more manageable problem. +

+

+ For a+b >= 5 the initial guess is computed using the methods + described in: +

+

+ Asymptotic Inversion of the Incomplete Beta Function, by N. M. Temme. + Journal of Computational and Applied Mathematics 41 (1992) 145-157. +

+

+ The nearly symmetrical case (section 2 of the paper) is used for +

+

+ +

+

+ and involves solving the inverse error function first. The method is accurate + to at least 2 decimal digits when a = 5 rising to at least + 8 digits when a = 105. +

+

+ The general error function case (section 3 of the paper) is used for +

+

+ +

+

+ and again expresses the inverse incomplete beta in terms of the inverse of + the error function. The method is accurate to at least 2 decimal digits when + a+b = 5 rising to 11 digits when a+b = 105. + However, when the result is expected to be very small, and when a+b is also + small, then its accuracy tails off, in this case when p1/a < 0.0025 then + it is better to use the following as an initial estimate: +

+

+ +

+

+ Finally the for all other cases where a+b > + 5 the method of section 4 of the paper + is used. This expresses the inverse incomplete beta in terms of the inverse + of the incomplete gamma function, and is therefore significantly more expensive + to compute than the other cases. However the method is accurate to at least + 3 decimal digits when a = 5 rising to at least 10 digits + when a = 105. This method is limited to a > b, and + therefore we need to perform an exchange a for b, p for q and x for y when + this is not the case. In addition when p is close to 1 the method is inaccurate + should we actually want y rather than x as output. Therefore when q is small + (q1/p < 10-3) we use: +

+

+ +

+

+ which is both cheaper to compute than the full method, and a more accurate + estimate on q. +

+

+ When a and b are both small there is a distinct lack of information in the + literature on how to proceed. I am extremely grateful to Prof Nico Temme + who provided the following information with a great deal of patience and + explanation on his part. Any errors that follow are entirely my own, and + not Prof Temme's. +

+

+ When a and b are both less than 1, then there is a point of inflection in + the incomplete beta at point xs + = (1 - a) / (2 - a + - b). Therefore if p > Ix(a,b) + we swap a for b, p for q and x for y, so that now we always look for a point + x below the point of inflection xs, + and on a convex curve. An initial estimate for x is made with: +

+

+ +

+

+ which is provably below the true value for x: Newton + iteration will therefore smoothly converge on x without problems + caused by overshooting etc. +

+

+ When a and b are both greater than 1, but a+b is too small to use the other + methods mentioned above, we proceed as follows. Observe that there is a point + of inflection in the incomplete beta at xs + = (1 - a) / (2 - a + - b). Therefore if p > Ix(a,b) + we swap a for b, p for q and x for y, so that now we always look for a point + x below the point of inflection xs, + and on a concave curve. An initial estimate for x is made with: +

+

+ +

+

+ which can be improved somewhat to: +

+

+ +

+

+ when b and x are both small (I've used b < a and x < 0.2). This actually + under-estimates x, which drops us on the wrong side of x for Newton iteration + to converge monotonically. However, use of higher derivatives and Halley + iteration keeps everything under control. +

+

+ The final case to be considered if when one of a and b is less than or equal + to 1, and the other greater that 1. Here, if b < a we swap a for b, p + for q and x for y. Now the curve of the incomplete beta is convex with no + points of inflection in [0,1]. For small p, x can be estimated using +

+

+ +

+

+ which under-estimates x, and drops us on the right side of the true value + for Newton iteration to converge monotonically. However, when p is large + this can quite badly underestimate x. This is especially an issue when we + really want to find y, in which case this method can be an arbitrary number + of order of magnitudes out, leading to very poor convergence during iteration. +

+

+ Things can be improved by considering the incomplete beta as a distorted + quarter circle, and estimating y from: +

+

+ +

+

+ This doesn't guarantee that we will drop in on the right side of x for monotonic + convergence, but it does get us close enough that Halley iteration rapidly + converges on the true value. +

+
+ + Implementation + of inverses on the a and b parameters +
+

+ These four functions share a common implementation. +

+

+ First an initial approximation is computed for a or + b: where possible this uses a Cornish-Fisher expansion + for the negative binomial distribution to get within around 1 of the result. + However, when a or b are very small + the Cornish Fisher expansion is not usable, in this case the initial approximation + is chosen so that Ix(a, b) is near the middle of the range [0,1]. +

+

+ This initial guess is then used as a starting value for a generic root finding + algorithm. The algorithm converges rapidly on the root once it has been bracketed, + but bracketing the root may take several iterations. A better initial approximation + for a or b would improve these + functions quite substantially: currently 10-20 incomplete beta function invocations + are required to find the root. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + -- cgit v1.2.3