From 5467aad1e01793c426405a0ef63ba342f7b2a7c1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 19 Apr 2017 14:53:49 +0100 Subject: [PATCH] [Minor] Remove confusing warning about exp overflow --- src/libstat/classifiers/bayes.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c index ea9269a127..8116e508d8 100644 --- a/src/libstat/classifiers/bayes.c +++ b/src/libstat/classifiers/bayes.c @@ -63,16 +63,32 @@ inv_chi_square (struct rspamd_task *task, gdouble value, gint freedom_deg) prob = exp (value); if (errno == ERANGE) { - msg_err_bayes ("exp overflow"); - return 0; + /* + * e^x where x is large *NEGATIVE* number is OK, so we have a very strong + * confidence that inv-chi-square is close to zero + */ + msg_debug_bayes ("exp overflow"); + + if (value < 0) { + return 0; + } + else { + return 1.0; + } } sum = prob; + /* + * m is our confidence in class + * prob is e ^ x (small value since x is normally less than zero + * So we integrate over degrees of freedom and produce the total result + * from 1.0 (no confidence) to 0.0 (full confidence) + */ for (i = 1; i < freedom_deg; i++) { prob *= m / (gdouble)i; - msg_debug_bayes ("prob: %.6f", prob); sum += prob; + msg_debug_bayes ("prob: %.6f, sum: %.6f", prob, sum); } return MIN (1.0, sum); -- 2.47.3