Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовой проект групп 3341 и 3382 / j48 / GainRatioCrit
.pas unit GainRatioCrit;
interface
uses
DistributionClass,
Utils,
EntropyCalculator,
Math;
//This method computes the gain ratio in the same way C4.5 does.
// @param bags the distribution
// @param totalnoInst the weight of ALL instances
// @param numerator the info gain
// function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
function splitEnt(bags: Distribution; totalnoInst: double): double;
implementation
//This method computes the gain ratio in the same way C4.5 does.
// @param bags the distribution
// @param totalnoInst the weight of ALL instances
// @param numerator the info gain
function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
var
denumerator: double;
begin
// Compute split info.
denumerator := splitEnt(bags,totalnoInst);
// Test if split is trivial.
if (Utils.eq(denumerator,0)) then
begin
result := 0;
exit;
end;
denumerator := denumerator/totalnoInst;
result := numerator/denumerator;
end;
// Help method for computing the split entropy.
function splitEnt(bags: Distribution; totalnoInst: double): double;
var
returnValue: double;
noUnknown: double;
i: integer;
begin
returnValue := 0;
noUnknown := totalnoInst-bags.total();
if (Utils.gr(bags.total(),0))
then
begin
for i :=0 to bags.numBags()-1 do
returnValue := returnValue-logFunc(bags.perBag(i));
returnValue := returnValue-logFunc(noUnknown);
returnValue := returnValue+logFunc(totalnoInst);
end;
result := returnValue;
end;
end.
interface
uses
DistributionClass,
Utils,
EntropyCalculator,
Math;
//This method computes the gain ratio in the same way C4.5 does.
// @param bags the distribution
// @param totalnoInst the weight of ALL instances
// @param numerator the info gain
// function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
function splitEnt(bags: Distribution; totalnoInst: double): double;
implementation
//This method computes the gain ratio in the same way C4.5 does.
// @param bags the distribution
// @param totalnoInst the weight of ALL instances
// @param numerator the info gain
function splitCritValueN(bags: Distribution; totalnoInst: double; numerator: double): double;
var
denumerator: double;
begin
// Compute split info.
denumerator := splitEnt(bags,totalnoInst);
// Test if split is trivial.
if (Utils.eq(denumerator,0)) then
begin
result := 0;
exit;
end;
denumerator := denumerator/totalnoInst;
result := numerator/denumerator;
end;
// Help method for computing the split entropy.
function splitEnt(bags: Distribution; totalnoInst: double): double;
var
returnValue: double;
noUnknown: double;
i: integer;
begin
returnValue := 0;
noUnknown := totalnoInst-bags.total();
if (Utils.gr(bags.total(),0))
then
begin
for i :=0 to bags.numBags()-1 do
returnValue := returnValue-logFunc(bags.perBag(i));
returnValue := returnValue-logFunc(noUnknown);
returnValue := returnValue+logFunc(totalnoInst);
end;
result := returnValue;
end;
end.
Соседние файлы в папке j48