]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Make bayes normalization function public
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Oct 2016 11:32:57 +0000 (12:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 15 Oct 2016 12:34:42 +0000 (13:34 +0100)
src/libstat/classifiers/bayes.c
src/libutil/util.c
src/libutil/util.h

index 35e061e08a2313df5290594e333ebab5918c28fd..07fe6cc8672af4087aad9d398dbd754e8d5ed789 100644 (file)
@@ -165,27 +165,7 @@ bayes_classify_token (struct rspamd_classifier *ctx,
        }
 }
 
-/*
- * A(x - 0.5)^4 + B(x - 0.5)^3 + C(x - 0.5)^2 + D(x - 0.5)
- * A = 32,
- * B = -6
- * C = -7
- * D = 3
- * y = 32(x - 0.5)^4 - 6(x - 0.5)^3 - 7(x - 0.5)^2 + 3(x - 0.5)
- */
-static gdouble
-bayes_normalize_prob (gdouble x)
-{
-       const gdouble a = 32, b = -6, c = -7, d = 3;
-       gdouble xx, x2, x3, x4;
-
-       xx = x - 0.5;
-       x2 = xx * xx;
-       x3 = x2 * xx;
-       x4 = x3 * xx;
 
-       return a*x4 + b*x3 + c*x2 + d*xx;
-}
 
 gboolean
 bayes_init (rspamd_mempool_t *pool, struct rspamd_classifier *cl)
@@ -308,7 +288,7 @@ bayes_classify (struct rspamd_classifier * ctx,
                 * we need to rescale it to display correctly
                 */
                rspamd_snprintf (sumbuf, 32, "%.2f%%", (final_prob - 0.5) * 200.);
-               final_prob = bayes_normalize_prob (final_prob);
+               final_prob = rspamd_normalize_probability (final_prob, 0.5);
                g_assert (st != NULL);
                cur = g_list_prepend (NULL, sumbuf);
                rspamd_task_insert_result (task,
index 9ca5bbce84648ad48b78a633ce351612619c58bd..5380d8c9443125538787471cb867ef415b8b8ce2 100644 (file)
@@ -2541,3 +2541,25 @@ rspamd_shmem_xmap (const char *fname, guint mode,
 
        return map;
 }
+
+/*
+ * A(x - 0.5)^4 + B(x - 0.5)^3 + C(x - 0.5)^2 + D(x - 0.5)
+ * A = 32,
+ * B = -6
+ * C = -7
+ * D = 3
+ * y = 32(x - 0.5)^4 - 6(x - 0.5)^3 - 7(x - 0.5)^2 + 3(x - 0.5)
+ */
+gdouble
+rspamd_normalize_probability (gdouble x, gdouble bias)
+{
+       const gdouble a = 32, b = -6, c = -7, d = 3;
+       gdouble xx, x2, x3, x4;
+
+       xx = x - bias;
+       x2 = xx * xx;
+       x3 = x2 * xx;
+       x4 = x3 * xx;
+
+       return a*x4 + b*x3 + c*x2 + d*xx;
+}
index 85d2ce2426d6b332b36c4af200625a084775f8d1..447e723243a7e1b54a1c2ffb87dcbbd8d954f29a 100644 (file)
@@ -500,5 +500,12 @@ gpointer rspamd_file_xmap (const char *fname, guint mode,
 gpointer rspamd_shmem_xmap (const char *fname, guint mode,
                gsize *size);
 
+/**
+ * Normalize probabilities using polynomial function
+ * @param x probability (bias .. 1)
+ * @return
+ */
+gdouble rspamd_normalize_probability (gdouble x, gdouble bias);
+
 #define PTR_ARRAY_FOREACH(ar, i, cur) if (ar != NULL) for ((i) = 0, (cur) = g_ptr_array_index((ar), 0); (i) < (ar)->len; (cur) = g_ptr_array_index((ar), (i)), ++(i))
 #endif