tukey.c
Go to the documentation of this file.
1 
2 /* Compute the CDF of the Tukey-Lambda distribution
3  * using a bracketing search with special checks
4  *
5  * The PPF of the Tukey-lambda distribution is
6  * G(p) = (p**lam + (1-p)**lam) / lam
7  *
8  * Author: Travis Oliphant
9  */
10 
11 #include <math.h>
12 
13 #define SMALLVAL 1e-4
14 #define EPS 1.0e-14
15 #define MAXCOUNT 60
16 
17 double tukeylambdacdf(double x, double lmbda)
18 {
19  double pmin, pmid, pmax, plow, phigh, xeval;
20  int count;
21 
22  if (isnan(x) || isnan(lmbda)) {
23  return NAN;
24  }
25 
26  xeval = 1.0 / lmbda;
27  if (lmbda > 0.0) {
28  if (x <= (-xeval)) {
29  return 0.0;
30  }
31  if (x >= xeval) {
32  return 1.0;
33  }
34  }
35 
36  if ((-SMALLVAL < lmbda) && (lmbda < SMALLVAL)) {
37  if (x >= 0) {
38  return 1.0 / (1.0 + exp(-x));
39  }
40  else {
41  return exp(x) / (1.0 + exp(x));
42  }
43  }
44 
45  pmin = 0.0;
46  pmid = 0.5;
47  pmax = 1.0;
48  plow = pmin;
49  phigh = pmax;
50  count = 0;
51 
52  while ((count < MAXCOUNT) && (fabs(pmid - plow) > EPS)) {
53  xeval = (pow(pmid, lmbda) - pow(1.0 - pmid, lmbda)) / lmbda;
54  if (xeval == x) {
55  return pmid;
56  }
57  if (xeval > x) {
58  phigh = pmid;
59  pmid = (pmid + plow) / 2.0;
60  }
61  else {
62  plow = pmid;
63  pmid = (pmid + phigh) / 2.0;
64  }
65  count++;
66  }
67  return pmid;
68 }
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
EPS
#define EPS
Definition: tukey.c:14
isnan
#define isnan(X)
Definition: main.h:93
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
boost::multiprecision::fabs
Real fabs(const Real &a)
Definition: boostmultiprec.cpp:119
SMALLVAL
#define SMALLVAL
Definition: tukey.c:13
MAXCOUNT
#define MAXCOUNT
Definition: tukey.c:15
Eigen::internal::pmax
EIGEN_DEVICE_FUNC Packet pmax(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:524
Eigen::ArrayBase::pow
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar, typename ExponentDerived::Scalar >, const Derived, const ExponentDerived > pow(const Eigen::ArrayBase< Derived > &x, const Eigen::ArrayBase< ExponentDerived > &exponents)
Definition: GlobalFunctions.h:143
tukeylambdacdf
double tukeylambdacdf(double x, double lmbda)
Definition: tukey.c:17
Eigen::internal::pmin
EIGEN_DEVICE_FUNC Packet pmin(const Packet &a, const Packet &b)
Definition: GenericPacketMath.h:512


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:09:36