-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.c
73 lines (60 loc) · 1.8 KB
/
stats.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*************************************************************************/
/* */
/* Statistical routines for C4.5 */
/* ----------------------------- */
/* */
/*************************************************************************/
//#include "c45defns.h"
#include "c45extern.h"
float CF = 0.25;
/*************************************************************************/
/* */
/* Compute the additional errors if the error rate increases to the */
/* upper limit of the confidence level. The coefficient is the */
/* square of the number of standard deviations corresponding to the */
/* selected confidence level. (Taken from Documenta Geigy Scientific */
/* Tables (Sixth Edition), p185 (with modifications).) */
/* */
/*************************************************************************/
float Val[] = { 0, 0.001, 0.005, 0.01, 0.05, 0.10, 0.20, 0.40, 1.00},
Dev[] = {4.0, 3.09, 2.58, 2.33, 1.65, 1.28, 0.84, 0.25, 0.00};
float AddErrs(N, e)
/* ------- */
float N, e;
{
static float Coeff=0;
float Val0, Pr;
if ( ! Coeff )
{
/* Compute and retain the coefficient value, interpolating from
the values in Val and Dev */
int i;
i = 0;
while ( CF > Val[i] ) i++;
Coeff = Dev[i-1] +
(Dev[i] - Dev[i-1]) * (CF - Val[i-1]) /(Val[i] - Val[i-1]);
Coeff = Coeff * Coeff;
}
if ( e < 1E-6 )
{
return N * (1 - exp(log(CF) / N));
}
else
if ( e < 0.9999 )
{
Val0 = N * (1 - exp(log(CF) / N));
return Val0 + e * (AddErrs(N, 1.0) - Val0);
}
else
if ( e + 0.5 >= N )
{
return 0.67 * (N - e);
}
else
{
Pr = (e + 0.5 + Coeff/2
+ sqrt(Coeff * ((e + 0.5) * (1 - (e + 0.5)/N) + Coeff/4)) )
/ (N + Coeff);
return (N * Pr - e);
}
}