aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstat
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-19 14:53:49 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-04-19 14:54:13 +0100
commit5467aad1e01793c426405a0ef63ba342f7b2a7c1 (patch)
tree3110434caf22e53f686cbabee58a446407796251 /src/libstat
parent33511b81d685101798b1cd641c5f553f720000d1 (diff)
downloadrspamd-5467aad1e01793c426405a0ef63ba342f7b2a7c1.tar.gz
rspamd-5467aad1e01793c426405a0ef63ba342f7b2a7c1.zip
[Minor] Remove confusing warning about exp overflow
Diffstat (limited to 'src/libstat')
-rw-r--r--src/libstat/classifiers/bayes.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c
index ea9269a12..8116e508d 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);