OPTION(DEBUG_MODE "Enable debug output [default: ON]" ON)
OPTION(ENABLE_OPTIMIZATION "Enable optimization [default: OFF]" OFF)
-OPTION(ENABLE_PERL "Enable perl support [default: OFF]" OFF)
OPTION(SKIP_RELINK_RPATH "Skip relinking and full RPATH for the install tree" OFF)
OPTION(ENABLE_REDIRECTOR "Enable redirector install [default: OFF]" OFF)
OPTION(ENABLE_PROFILING "Enable profiling [default: OFF]" OFF)
uint16_t master_port;
};
-typedef double (*statfile_normalize_func)(struct config_file *cfg, double score, void *params);
+typedef double (*statfile_normalize_func)(struct config_file *cfg, long double score, void *params);
/**
* Statfile config definition
}
static double
-internal_normalizer_func (struct config_file *cfg, double score, void *data)
+internal_normalizer_func (struct config_file *cfg, long double score, void *data)
{
- double max = *(double *)data;
+ long double max = *(double *)data;
if (score < 0) {
return score;
}
- else if (score > 0.001 && score < 1) {
- return 1;
- }
- else if (score > 1 && score < max / 2.) {
- return MIN(max, score * score);
- }
- else if (score < max) {
- return score;
- }
- else if (score > max) {
- return max;
- }
+ else {
+ return max * tanhl (score / max);
+ }
return score;
}
struct classify_weight {
const char *name;
- double weight;
+ long double weight;
};
/* Common classifier structure */
struct classifier_ctx *ctx;
stat_file_t *file;
stat_file_t *learn_file;
- double sum;
+ long double sum;
double multiplier;
int count;
gboolean in_class;
/* Consider that not found blocks have value 1 */
v = statfile_pool_get_block (cd->pool, cd->file, node->h1, node->h2, cd->now);
if (fabs (v) > ALPHA) {
- if (cd->sum + v > MAX_WEIGHT) {
- cd->sum = MAX_WEIGHT;
- }
- else {
- cd->sum += v;
- }
+ cd->sum += v;
cd->in_class++;
}
}
- if (cd->sum + node->value > MAX_WEIGHT) {
- cd->sum = MAX_WEIGHT;
- }
- else {
- cd->sum += node->value;
- }
+ cd->sum += node->value;
cd->count++;
{
struct winnow_callback_data data;
char *sumbuf, *value;
- double res = 0., max = 0.;
+ long double res = 0., max = 0.;
GList *cur;
struct statfile *st, *sel = NULL;
int nodes, minnodes;
if (sel != NULL) {
sumbuf = memory_pool_alloc (task->task_pool, 32);
- snprintf (sumbuf, 32, "%.2f", max);
+ snprintf (sumbuf, 32, "%.2Lg", max);
cur = g_list_prepend (NULL, sumbuf);
#ifdef WITH_LUA
max = call_classifier_post_callbacks (ctx->cfg, task, max);
winnow_weights (struct classifier_ctx *ctx, statfile_pool_t * pool, GTree * input, struct worker_task *task)
{
struct winnow_callback_data data;
- double res = 0.;
+ long double res = 0.;
GList *cur, *resl = NULL;
struct statfile *st;
struct classify_weight *w;
int nodes, minnodes, iterations = 0;
struct statfile *st;
stat_file_t *sel;
- double res = 0., max = 0.;
+ long double res = 0., max = 0.;
GList *cur;
g_assert (pool != NULL);
}
} while ((in_class ? sel != file : sel == file) && iterations ++ < MAX_LEARN_ITERATIONS);
+ if (iterations >= MAX_LEARN_ITERATIONS) {
+ msg_warn ("learning statfile %s was not fully successfull: iterations count is limited to %d, final sum is %G",
+ file->filename, MAX_LEARN_ITERATIONS, max);
+ }
+ else {
+ msg_info ("learned statfile %s successfully with %d iterations and sum %G", file->filename, iterations, max);
+ }
+
+
if (sum) {
- if (data.count != 0) {
- *sum = data.sum / data.count;
- }
- else {
- *sum = 0;
- }
+ *sum = max;
}
}
while (cur) {
w = cur->data;
- i += snprintf (out_buf + i, sizeof (out_buf) - i, "%s: %.2f" CRLF, w->name, w->weight);
+ i += snprintf (out_buf + i, sizeof (out_buf) - i, "%s: %.2Lg" CRLF, w->name, w->weight);
cur = g_list_next (cur);
}
if (!rspamd_dispatcher_write (session->dispatcher, out_buf, i, FALSE, FALSE)) {
}
double
-lua_normalizer_func (struct config_file *cfg, double score, void *params)
+lua_normalizer_func (struct config_file *cfg, long double score, void *params)
{
GList *p = params;
- double res = score;
+ long double res = score;
lua_State *L = cfg->lua_state;
/* Call specified function and put input score on stack */
GList *call_classifier_pre_callbacks (struct classifier_config *ccf, struct worker_task *task);
double call_classifier_post_callbacks (struct classifier_config *ccf, struct worker_task *task, double in);
-double lua_normalizer_func (struct config_file *cfg, double score, void *params);
+double lua_normalizer_func (struct config_file *cfg, long double score, void *params);
/* Config file functions */
void lua_post_load_config (struct config_file *cfg);
* %[0][width|m][u][x|X]i int/ngx_int_t
* %[0][width][u][x|X]D int32_t/uint32_t
* %[0][width][u][x|X]L int64_t/uint64_t
- * %[0][width][.width]f float
+ * %[0][width][.width]f double
+ * %[0][width][.width]F long double
+ * %[0][width][.width]g double
+ * %[0][width][.width]G long double
* %P pid_t
* %r rlim_t
* %p void *
{
u_char *p, zero, *last;
int d;
- float f, scale;
+ long double f, scale;
size_t len, slen;
int64_t i64;
uint64_t ui64;
sign = 0;
fmt++;
continue;
-
case '.':
fmt++;
case 'f':
- f = (float) va_arg (args, double);
+ f = (double) va_arg (args, double);
+ if (f < 0) {
+ *buf++ = '-';
+ f = -f;
+ }
+
+ ui64 = (int64_t) f;
+
+ buf = rspamd_sprintf_num (buf, last, ui64, zero, 0, width);
+
+ if (frac_width) {
+
+ if (buf < last) {
+ *buf++ = '.';
+ }
+
+ scale = 1.0;
+
+ for (i = 0; i < frac_width; i++) {
+ scale *= 10.0;
+ }
+
+ /*
+ * (int64_t) cast is required for msvc6:
+ * it can not convert uint64_t to double
+ */
+ ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
+
+ buf = rspamd_sprintf_num (buf, last, ui64, '0', 0, frac_width);
+ }
+
+ fmt++;
+
+ continue;
+
+ case 'F':
+ f = (long double) va_arg (args, long double);
if (f < 0) {
*buf++ = '-';
}
/*
- * (int64_t) cast is required for msvc6:
- * it can not convert uint64_t to double
- */
+ * (int64_t) cast is required for msvc6:
+ * it can not convert uint64_t to double
+ */
ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
buf = rspamd_sprintf_num (buf, last, ui64, '0', 0, frac_width);
continue;
+ case 'g':
+ f = (long double) va_arg (args, double);
+
+ if (f < 0) {
+ *buf++ = '-';
+ f = -f;
+ }
+ g_ascii_formatd (buf, last - buf, "%g", (double)f);
+ buf += strlen (buf);
+ fmt++;
+
+ continue;
+
+ case 'G':
+ f = (long double) va_arg (args, long double);
+
+ if (f < 0) {
+ *buf++ = '-';
+ f = -f;
+ }
+ g_ascii_formatd (buf, last - buf, "%g", (double)f);
+ buf += strlen (buf);
+ fmt++;
+
+ continue;
+
case 'p':
ui64 = (uintptr_t) va_arg (args, void *);
hex = 2;