diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-11-23 17:23:52 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-11-23 17:23:52 +0000 |
commit | 461c69e461fcfd4d9b632f0427d3e44be460013d (patch) | |
tree | c02a1b68beda5cd6e1886f1a2d1caeac8e1a7dad /src/nse | |
parent | 68621a1c1481126790d308c97dda6981f17e8b9e (diff) | |
download | gnunet-461c69e461fcfd4d9b632f0427d3e44be460013d.tar.gz gnunet-461c69e461fcfd4d9b632f0427d3e44be460013d.zip |
- Fixed simplified variance code
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index 782f30514..61ab7e57a 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -64,7 +64,7 @@ | |||
64 | /** | 64 | /** |
65 | * Over how many values do we calculate the weighted average? | 65 | * Over how many values do we calculate the weighted average? |
66 | */ | 66 | */ |
67 | #define HISTORY_SIZE 8 | 67 | #define HISTORY_SIZE 64 |
68 | 68 | ||
69 | /** | 69 | /** |
70 | * Size of the queue to core. | 70 | * Size of the queue to core. |
@@ -344,16 +344,26 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
344 | /* non-weighted trivial version */ | 344 | /* non-weighted trivial version */ |
345 | sum = 0.0; | 345 | sum = 0.0; |
346 | vsq = 0.0; | 346 | vsq = 0.0; |
347 | variance = 0.0; | ||
348 | mean = 0.0; | ||
349 | |||
347 | for (i = 0; i < estimate_count; i++) | 350 | for (i = 0; i < estimate_count; i++) |
348 | { | 351 | { |
349 | val = htonl (size_estimate_messages | 352 | int j; |
350 | [(estimate_index - i + | 353 | |
351 | HISTORY_SIZE) % HISTORY_SIZE].matching_bits); | 354 | j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
355 | val = htonl (size_estimate_messages[j].matching_bits); | ||
352 | sum += val; | 356 | sum += val; |
353 | vsq += val * val; | 357 | vsq += val * val; |
354 | } | 358 | } |
355 | mean = sum / estimate_count; | 359 | if (0 != estimate_count) |
356 | variance = vsq + mean * mean - 2 * mean * sum; // terrible for numerical stability... | 360 | { |
361 | mean = sum / estimate_count; | ||
362 | variance = (vsq - mean * sum) / estimate_count; // terrible for numerical stability... | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(%f - %f) / %u = %f\n", | ||
364 | vsq, mean * sum, estimate_count, variance); | ||
365 | |||
366 | } | ||
357 | #endif | 367 | #endif |
358 | GNUNET_assert (variance >= 0); | 368 | GNUNET_assert (variance >= 0); |
359 | std_dev = sqrt (variance); | 369 | std_dev = sqrt (variance); |