[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34292 - in gnunet/src/sensor: . sensors
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34292 - in gnunet/src/sensor: . sensors |
Date: |
Mon, 15 Sep 2014 15:15:31 +0200 |
Author: otarabai
Date: 2014-09-15 15:15:31 +0200 (Mon, 15 Sep 2014)
New Revision: 34292
Modified:
gnunet/src/sensor/gnunet-service-sensor_analysis.c
gnunet/src/sensor/plugin_sensor_model_gaussian.c
gnunet/src/sensor/sensor.conf.in
gnunet/src/sensor/sensor_util_lib_crypto.c
gnunet/src/sensor/sensors/transport-tcp-bytes-transmitted
Log:
sensor: update to gaussian model + optimized parameters
Modified: gnunet/src/sensor/gnunet-service-sensor_analysis.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_analysis.c 2014-09-13 13:54:57 UTC
(rev 34291)
+++ gnunet/src/sensor/gnunet-service-sensor_analysis.c 2014-09-15 13:15:31 UTC
(rev 34292)
@@ -89,7 +89,7 @@
/**
* Hashmap of loaded sensors
*/
-struct GNUNET_CONTAINER_MultiHashMap *sensors;
+static struct GNUNET_CONTAINER_MultiHashMap *sensors;
/*
* Model library name
@@ -119,13 +119,13 @@
/**
* My peer id
*/
-struct GNUNET_PeerIdentity peerid;
+static struct GNUNET_PeerIdentity peerid;
/**
* How many subsequent values required to flip anomaly label.
* E.g. After 3 subsequent anomaly reports, status change to anomalous.
*/
-unsigned long long confirmation_count;
+static unsigned long long confirmation_count;
/**
* Destroy a created model
Modified: gnunet/src/sensor/plugin_sensor_model_gaussian.c
===================================================================
--- gnunet/src/sensor/plugin_sensor_model_gaussian.c 2014-09-13 13:54:57 UTC
(rev 34291)
+++ gnunet/src/sensor/plugin_sensor_model_gaussian.c 2014-09-15 13:15:31 UTC
(rev 34292)
@@ -18,7 +18,7 @@
* Boston, MA 02111-1307, USA.
*/
-/*
+/**
* @file sensor/plugin_sensor_model_gaussian.c
* @brief Gaussian model for sensor analysis
* @author Omar Tarabai
@@ -31,55 +31,60 @@
#define LOG(kind,...) GNUNET_log_from (kind, "sensor-model-gaussian",
__VA_ARGS__)
-/*
+/**
* Plugin state information
*/
struct Plugin
{
- /*
+ /**
* Configuration handle
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
- /*
+ /**
* Number of initial readings to be used for training only
*/
int training_window;
- /*
+ /**
* Number of standard deviations considered within "normal"
*/
int confidence_interval;
+ /**
+ * Increase in weight with each reading
+ */
+ float weight_inc;
+
};
-/*
+/**
* State of single model instance
*/
struct Model
{
- /*
+ /**
* Pointer to the plugin state
*/
struct Plugin *plugin;
- /*
+ /**
+ * Gaussian sums
+ */
+ long double s[3];
+
+ /**
* Number of readings so far
*/
int n;
- /*
- * Sum of readings
+ /**
+ * Weight to be used for the next reading
*/
- long double sum;
+ double w;
- /*
- * Sum square of readings
- */
- long double sumsq;
-
};
/**
@@ -91,8 +96,11 @@
static void
update_sums (struct Model *model, double val)
{
- model->sum += val;
- model->sumsq += val * val;
+ int i;
+
+ for (i = 0; i < 3; i++)
+ model->s[i] += model->w * pow (val, (double) i);
+ model->w += model->plugin->weight_inc;
model->n++;
}
@@ -120,10 +128,14 @@
}
if (model->n == plugin->training_window)
LOG (GNUNET_ERROR_TYPE_DEBUG, "Gaussian model out of training period.\n");
- mean = model->sum / model->n;
+ mean = model->s[1] / model->s[0];
stddev =
- sqrt ((model->sumsq - 2 * mean * model->sum +
- model->n * mean * mean) / (model->n - 1));
+ (model->s[0] * model->s[2] -
+ model->s[1] * model->s[1]) / (model->s[0] * (model->s[0] - 1));
+ if (stddev < 0) /* Value can be slightly less than 0 due to
rounding errors */
+ stddev = 0;
+ stddev = sqrt (stddev);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Mean: %Lf, Stddev: %Lf\n", mean, stddev);
allowed_variance = (plugin->confidence_interval * stddev);
if ((val < (mean - allowed_variance)) || (val > (mean + allowed_variance)))
return GNUNET_YES;
@@ -161,6 +173,7 @@
model = GNUNET_new (struct Model);
model->plugin = plugin;
+ model->w = 1;
return model;
}
@@ -191,7 +204,16 @@
_("Missing `TRAINING_WINDOW' value in configuration.\n"));
return NULL;
}
- plugin.training_window = (int) num;
+ if (num < 1)
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ "Minimum training window invalid (<1), setting to 1.\n");
+ plugin.training_window = 1;
+ }
+ else
+ {
+ plugin.training_window = (int) num;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "sensor-model-gaussian",
"CONFIDENCE_INTERVAL", &num))
@@ -200,6 +222,14 @@
_("Missing `CONFIDENCE_INTERVAL' value in configuration.\n"));
return NULL;
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_float (cfg, "sensor-model-gaussian",
+ "WEIGHT_INC", &plugin.weight_inc))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Missing `WEIGHT_INC' value in configuration.\n"));
+ return NULL;
+ }
plugin.confidence_interval = (int) num;
api = GNUNET_new (struct GNUNET_SENSOR_ModelFunctions);
Modified: gnunet/src/sensor/sensor.conf.in
===================================================================
--- gnunet/src/sensor/sensor.conf.in 2014-09-13 13:54:57 UTC (rev 34291)
+++ gnunet/src/sensor/sensor.conf.in 2014-09-15 13:15:31 UTC (rev 34292)
@@ -18,12 +18,12 @@
[sensor-analysis]
MODEL = gaussian
# How many subsequent values required to flip anomaly label. (Default: 1)
-# E.g. After 3 subsequent anomaly reports, status change to anomalous.
-CONFIRMATION_COUNT = 3
+CONFIRMATION_COUNT = 1
[sensor-model-gaussian]
-TRAINING_WINDOW = 10
-CONFIDENCE_INTERVAL = 3
+TRAINING_WINDOW = 400
+CONFIDENCE_INTERVAL = 8
+WEIGHT_INC = 0
[sensor-reporting]
POW_MATCHING_BITS = 15
Modified: gnunet/src/sensor/sensor_util_lib_crypto.c
===================================================================
--- gnunet/src/sensor/sensor_util_lib_crypto.c 2014-09-13 13:54:57 UTC (rev
34291)
+++ gnunet/src/sensor/sensor_util_lib_crypto.c 2014-09-15 13:15:31 UTC (rev
34292)
@@ -128,7 +128,6 @@
char buf[msg_size + sizeof (pow)] GNUNET_ALIGN;
struct GNUNET_HashCode result;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Msg size: %" PRIu64 ".\n", msg_size);
memcpy (buf, &pow, sizeof (pow));
memcpy (&buf[sizeof (pow)], msg, msg_size);
pow_hash (buf, sizeof (buf), &result);
Modified: gnunet/src/sensor/sensors/transport-tcp-bytes-transmitted
===================================================================
--- gnunet/src/sensor/sensors/transport-tcp-bytes-transmitted 2014-09-13
13:54:57 UTC (rev 34291)
+++ gnunet/src/sensor/sensors/transport-tcp-bytes-transmitted 2014-09-15
13:15:31 UTC (rev 34292)
@@ -1,7 +1,7 @@
[transport-tcp-bytes-transmitted]
VERSION = 1.0
-DESCRIPTION = Number of GNUnet transport service active TCP sessions
+DESCRIPTION = Number of GNUnet transport TCP bytes transmitted
CATEGORY = GNUnet
ENABLED = YES
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34292 - in gnunet/src/sensor: . sensors,
gnunet <=