diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-07 11:38:48 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-02-07 11:38:48 +0000 |
commit | c53ad94e7b7b5970750893408ab3d12779639944 (patch) | |
tree | fc6fa50ad2f68c9b6a0b0e833fa1815500c5a5bd | |
parent | 5840268601eec9e16a42395d60063afa5eb09628 (diff) | |
download | rspamd-c53ad94e7b7b5970750893408ab3d12779639944.tar.gz rspamd-c53ad94e7b7b5970750893408ab3d12779639944.zip |
[Fix] Fix stddev calculations
-rw-r--r-- | src/libserver/symbols_cache.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 2ffa8e376..f965798f5 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -328,6 +328,7 @@ cache_logic_cmp (const void *p1, const void *p2, gpointer ud) static double rspamd_set_counter (struct counter_data *cd, gdouble value) { + gdouble cerr; /* Cumulative moving average using per-process counter data */ if (cd->number == 0) { @@ -336,7 +337,8 @@ rspamd_set_counter (struct counter_data *cd, gdouble value) } cd->mean += (value - cd->mean) / (gdouble)(++cd->number); - cd->stddev += (value - cd->mean) * (value - cd->mean); + cerr = (value - cd->mean) * (value - cd->mean); + cd->stddev += (cerr - cd->stddev) / (gdouble)(cd->number); return cd->mean; } @@ -1876,7 +1878,7 @@ rspamd_symbols_cache_call_peak_cb (struct event_base *ev_base, rspamd_lua_setclass (L, "rspamd{ev_base}", -1); lua_pushstring (L, item->symbol); lua_pushnumber (L, item->st->avg_frequency); - lua_pushnumber (L, item->st->stddev_frequency); + lua_pushnumber (L, sqrt (item->st->stddev_frequency)); lua_pushnumber (L, cur_value); lua_pushnumber (L, cur_err); @@ -1941,7 +1943,7 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) * TODO: replace magic number */ if (item->st->frequency_counter.number > 10 && - cur_err > item->st->stddev_frequency * 2) { + cur_err > sqrt (item->st->stddev_frequency) * 3) { item->frequency_peaks ++; msg_debug_cache ("peak found for %s is %.2f, avg: %.2f, " "stddev: %.2f, error: %.2f, peaks: %d", @@ -2102,7 +2104,7 @@ rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, if (item != NULL) { *frequency = item->st->avg_frequency; - *freq_stddev = item->st->stddev_frequency; + *freq_stddev = sqrt (item->st->stddev_frequency); *tm = item->st->time_counter.mean; return TRUE; |