diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-15 12:32:57 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-10-15 13:34:42 +0100 |
commit | 73639d6543db207832f663a38bf299ff26bab8bb (patch) | |
tree | 3b27765a3ad0309f78e5bfd8ec81f39a713aafba /src/libutil | |
parent | 50ed1e6c5a60ca71fdfcf528f634ecc8cd266777 (diff) | |
download | rspamd-73639d6543db207832f663a38bf299ff26bab8bb.tar.gz rspamd-73639d6543db207832f663a38bf299ff26bab8bb.zip |
[Minor] Make bayes normalization function public
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.c | 22 | ||||
-rw-r--r-- | src/libutil/util.h | 7 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index 9ca5bbce8..5380d8c94 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -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; +} diff --git a/src/libutil/util.h b/src/libutil/util.h index 85d2ce242..447e72324 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -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 |