File: tukey.c

package info (click to toggle)
python-scipy 0.14.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 52,228 kB
  • ctags: 63,719
  • sloc: python: 112,726; fortran: 88,685; cpp: 86,979; ansic: 85,860; makefile: 530; sh: 236
file content (59 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

/* Compute the CDF of the Tukey-Lambda distribution 
 * using a braketing search with special checks
 * 
 * The PPF of the Tukey-lambda distribution is 
 * G(p) = p**lam + (1-p)**lam / lam
 * 
 * Author:  Travis Oliphant 
 */

#include <math.h>

#define SMALLVAL 1e-4
#define EPS 1.0e-14
#define MAXCOUNT 60

double tukeylambdacdf(double x, double lmbda)
{
    double pmin, pmid, pmax, plow, phigh, xeval;
    int count;

    xeval = 1.0 / lmbda;
    if (lmbda > 0.0) {
	if (x < (-xeval))
	    return 0.0;
	if (x > xeval)
	    return 1.0;
    }

    if ((-SMALLVAL < lmbda) && (lmbda < SMALLVAL)) {
	if (x >= 0)
	    return 1.0 / (1.0 + exp(-x));
	else
	    return exp(x) / (1.0 + exp(x));
    }

    pmin = 0.0;
    pmid = 0.5;
    pmax = 1.0;
    plow = pmin;
    phigh = pmax;
    count = 0;

    while ((count < MAXCOUNT) && (fabs(pmid - plow) > EPS)) {
	xeval = (pow(pmid, lmbda) - pow(1.0 - pmid, lmbda)) / lmbda;
	if (xeval == x)
	    return pmid;
	if (xeval > x) {
	    phigh = pmid;
	    pmid = (pmid + plow) / 2.0;
	}
	else {
	    plow = pmid;
	    pmid = (pmid + phigh) / 2.0;
	}
	count++;
    }
    return pmid;
}