[Spambayes-checkins] spambayes CostCounter.py,1.2,1.3
Rob W.W. Hooft
hooft@users.sourceforge.net
Tue Nov 19 17:41:34 2002
Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv30383
Modified Files:
CostCounter.py
Log Message:
More different cost counters as optimization targets
Index: CostCounter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/CostCounter.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CostCounter.py 16 Nov 2002 05:41:29 -0000 1.2
--- CostCounter.py 19 Nov 2002 17:41:28 -0000 1.3
***************
*** 14,18 ****
def __str__(self):
! return "%s: $%.2f" % (self.name, self.total)
class CompositeCostCounter:
--- 14,18 ----
def __str__(self):
! return "%s: $%.4f" % (self.name, self.total)
class CompositeCostCounter:
***************
*** 34,37 ****
--- 34,59 ----
return '\n'.join(s)
+ class DelayedCostCounter(CompositeCostCounter):
+ def __init__(self,cclist):
+ CompositeCostCounter.__init__(self,cclist)
+ self.spamscr=[]
+ self.hamscr=[]
+
+ def spam(self, scr):
+ self.spamscr.append(scr)
+
+ def ham(self, scr):
+ self.hamscr.append(scr)
+
+ def __str__(self):
+ for scr in self.spamscr:
+ CompositeCostCounter.spam(self,scr)
+ for scr in self.hamscr:
+ CompositeCostCounter.ham(self,scr)
+ s=[]
+ for line in CompositeCostCounter.__str__(self).split('\n'):
+ s.append('Delayed-'+line)
+ return '\n'.join(s)
+
class StdCostCounter(CostCounter):
name = "Standard Cost"
***************
*** 65,72 ****
self.total += self._lambda(scr) * options.best_cutoff_fp_weight
def default():
return CompositeCostCounter([
! StdCostCounter(),
! FlexCostCounter(),
! ])
--- 87,117 ----
self.total += self._lambda(scr) * options.best_cutoff_fp_weight
+ class Flex2CostCounter(FlexCostCounter):
+ name = "Flex**2 Cost"
+ def spam(self, scr):
+ self.total += (1 - self._lambda(scr))**2 * options.best_cutoff_fn_weight
+
+ def ham(self, scr):
+ self.total += self._lambda(scr)**2 * options.best_cutoff_fp_weight
+
def default():
return CompositeCostCounter([
! StdCostCounter(),
! FlexCostCounter(),
! Flex2CostCounter(),
! DelayedCostCounter([
! StdCostCounter(),
! FlexCostCounter(),
! Flex2CostCounter(),
! ])
! ])
+ if __name__=="__main__":
+ cc=default()
+ cc.ham(0)
+ cc.spam(1)
+ cc.ham(0.5)
+ cc.spam(0.5)
+ options.spam_cutoff=0.7
+ options.ham_cutoff=0.4
+ print cc
More information about the Spambayes-checkins
mailing list