[cvs] bogofilter robinson.c,1.27,1.28
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2003-01-22 04:41:14
|
Update of /cvsroot/bogofilter/bogofilter In directory sc8-pr-cvs1:/tmp/cvs-serv2173 Modified Files: robinson.c Log Message: Return ROBX when no tokens are scored. Index: robinson.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/robinson.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- robinson.c 22 Jan 2003 04:00:26 -0000 1.27 +++ robinson.c 22 Jan 2003 04:41:10 -0000 1.28 @@ -252,18 +252,23 @@ #ifdef ENABLE_ROBINSON_METHOD double rob_get_spamicity(size_t robn, FLOAT P, FLOAT Q) { - double r = 1.0 / (double)robn; - double ln10 = 2.302585093; /* log(10) - 2.3025850929940459 */ + if (robn == 0) + rob_stats.s.spamicity = robx; + else + { + double r = 1.0 / (double)max(1,robn); + double ln10 = 2.302585093; /* log(10) - 2.3025850929940459 */ - rob_stats.robn = robn; + rob_stats.robn = robn; - rob_stats.p_ln = log(P.mant) + P.exp * ln10; /* invlogsum */ - rob_stats.q_ln = log(Q.mant) + Q.exp * ln10; /* logsum */ + rob_stats.p_ln = log(P.mant) + P.exp * ln10; /* invlogsum */ + rob_stats.q_ln = log(Q.mant) + Q.exp * ln10; /* logsum */ - rob_stats.p_pr = 1.0 - pow(P.mant, r) * pow(10.0, P.exp * r); /* Robinson's P */ - rob_stats.q_pr = 1.0 - pow(Q.mant, r) * pow(10.0, Q.exp * r); /* Robinson's Q */ + rob_stats.p_pr = 1.0 - pow(P.mant, r) * pow(10.0, P.exp * r); /* Robinson's P */ + rob_stats.q_pr = 1.0 - pow(Q.mant, r) * pow(10.0, Q.exp * r); /* Robinson's Q */ - rob_stats.s.spamicity = (1.0 + (rob_stats.p_pr - rob_stats.q_pr) / (rob_stats.p_pr + rob_stats.q_pr)) / 2.0; + rob_stats.s.spamicity = (1.0 + (rob_stats.p_pr - rob_stats.q_pr) / (rob_stats.p_pr + rob_stats.q_pr)) / 2.0; + } return rob_stats.s.spamicity; } |