Esempio n. 1
0
 def splitCritValue(self,
                    bags: Distribution,
                    totalNoInst: float = None,
                    numerator: float = None):
     if totalNoInst is None and numerator is None:
         numerator = self.oldEnt(bags) - self.newEnt(bags)
         if Utils.equal(numerator, 0):
             return float('inf')
         denumerator = self.splitEnt(bags)
         if Utils.equal(denumerator, 0):
             return float('inf')
         return denumerator / numerator
     elif numerator is None:
         res = 0
         noUnkown = totalNoInst - bags.total()
         if Utils.gr(bags.total(), 0):
             for i in range(bags.numBags()):
                 res = res - self.lnFunc(bags.perBag(i))
             res = res - self.lnFunc(noUnkown)
             res = res + self.lnFunc(totalNoInst)
         return res / math.log(2)
     else:
         denumerator = self.splitEnt(bags, totalNoInst)
         if Utils.equal(denumerator, 0):
             return 0
         denumerator /= totalNoInst
         return numerator / denumerator
 def newEnt(self,bags:Distribution):
     res=0
     for i in range(bags.numBags()):
         for j in range(bags.numClasses()):
             res=res+self.lnFunc(bags.perClassPerBag(i,j))
         res=res-self.lnFunc(bags.perBag(i))
     return -(res/math.log(2))
Esempio n. 3
0
 def splitEnt(self, bags: Distribution, totalnoInst: float = None):
     if totalnoInst is None:
         return super().splitEnt(bags)
     res = 0
     noUnknown = totalnoInst - bags.total()
     if Utils.gr(bags.total(), 0):
         for i in range(bags.numBags()):
             res = res - self.lnFunc(bags.perBag(i))
         res = res - self.lnFunc(noUnknown)
         res = res + self.lnFunc(totalnoInst)
     return res / math.log(2)
 def splitEnt(self,bags:Distribution):
     res=0
     for i in range(bags.numBags()):
         res=res+self.lnFunc(bags.perBag(i))
     return (self.lnFunc(bags.total())-res)/math.log(2)