Скачиваний:
28
Добавлен:
01.05.2014
Размер:
1.83 Кб
Скачать
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.
Соседние файлы в папке j48