Скачиваний:
30
Добавлен:
01.05.2014
Размер:
1.88 Кб
Скачать
unit Stats;

interface


uses

Math,
Statistics;

function addErrs(N: double; e: double; CF: double): double;

implementation


//Computes estimated extra error for given total number of instances
// and error using normal approximation to binomial distribution
// (and continuity correction).
// @param N number of instances
// @param e observed error
// @param CF confidence value
function addErrs(N: double; e: double; CF: double): double;
var

z, f, r, base: double;

begin

// Ignore stupid values for CF
if (CF > 0.5)
then
begin
result := 0;
exit;
end;

// Check for extreme cases at the low end because the
// normal approximation won't work
if (e < 1)
then
begin
// Base case (i.e. e == 0) from documenta Geigy Scientific
// Tables, 6th edition, page 185
base := N * (1 - Math.Power(CF, 1 / N));
if (e = 0)
then
begin
result := base;
exit;
end;

// Use linear interpolation between 0 and 1 like C4.5 does
result := base + e * (addErrs(N, 1, CF) - base);
exit;
end;

// Use linear interpolation at the high end (i.e. between N - 0.5
// and N) because of the continuity correction
if (e + 0.5 >= N)
then
begin
// Make sure that we never return anything smaller than zero
result := Math.max(N - e, 0);
exit;
end;

// Get z-score corresponding to CF
z := Statistics.normalInverse(1 - CF);

// Compute upper limit of confidence interval
f := (e + 0.5) / N;
r := (f + (z * z) / (2 * N) +
z * Math.Power(
(f / N) -
(f * f / N) +
(z * z / (4 * N * N))
, 0.5)) /
(1 + (z * z) / N);

result := (r * N) - e;
end;


end.
Соседние файлы в папке j48