[cvs] bogofilter/src rstats.c,1.3,1.4
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2003-03-06 13:36:44
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1:/tmp/cvs-serv15586 Modified Files: rstats.c Log Message: Fix floating point exception while generating histogram. Index: rstats.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/rstats.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- rstats.c 18 Feb 2003 00:29:18 -0000 1.3 +++ rstats.c 6 Mar 2003 13:36:41 -0000 1.4 @@ -155,10 +155,9 @@ size_t cnt = 0; h->prob = 0.0; h->spamicity=0.0; - while ( r<count) + while (r < count) { double prob = rstats_array[r]->prob; - double invn, invproduct, product, spamicity; if (prob - fin >= EPS) break; @@ -170,13 +169,19 @@ logsum += log(prob); } - invn = (double)robn; - invproduct = 1.0 - exp(invlogsum / invn); - product = 1.0 - exp(logsum / invn); - spamicity = - (1.0 + (invproduct - product) / (invproduct + product)) / 2.0; - h->spamicity=spamicity; - + if (robn == 0) + { + h->spamicity = robx; + } + else + { + double invn, invproduct, product; + invn = (double)robn; + invproduct = 1.0 - exp(invlogsum / invn); + product = 1.0 - exp(logsum / invn); + h->spamicity = + (1.0 + (invproduct - product) / (invproduct + product)) / 2.0; + } r += 1; } h->count=cnt; |