[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18283 - gnunet/src/nse
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18283 - gnunet/src/nse |
Date: |
Wed, 23 Nov 2011 18:23:52 +0100 |
Author: bartpolot
Date: 2011-11-23 18:23:52 +0100 (Wed, 23 Nov 2011)
New Revision: 18283
Modified:
gnunet/src/nse/gnunet-service-nse.c
Log:
- Fixed simplified variance code
Modified: gnunet/src/nse/gnunet-service-nse.c
===================================================================
--- gnunet/src/nse/gnunet-service-nse.c 2011-11-23 16:09:11 UTC (rev 18282)
+++ gnunet/src/nse/gnunet-service-nse.c 2011-11-23 17:23:52 UTC (rev 18283)
@@ -64,7 +64,7 @@
/**
* Over how many values do we calculate the weighted average?
*/
-#define HISTORY_SIZE 8
+#define HISTORY_SIZE 64
/**
* Size of the queue to core.
@@ -344,16 +344,26 @@
/* non-weighted trivial version */
sum = 0.0;
vsq = 0.0;
+ variance = 0.0;
+ mean = 0.0;
+
for (i = 0; i < estimate_count; i++)
{
- val = htonl (size_estimate_messages
- [(estimate_index - i +
- HISTORY_SIZE) % HISTORY_SIZE].matching_bits);
+ int j;
+
+ j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
+ val = htonl (size_estimate_messages[j].matching_bits);
sum += val;
- vsq += val * val;
- }
- mean = sum / estimate_count;
- variance = vsq + mean * mean - 2 * mean * sum; // terrible for numerical
stability...
+ vsq += val * val;
+ }
+ if (0 != estimate_count)
+ {
+ mean = sum / estimate_count;
+ variance = (vsq - mean * sum) / estimate_count; // terrible for numerical
stability...
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(%f - %f) / %u = %f\n",
+ vsq, mean * sum, estimate_count, variance);
+
+ }
#endif
GNUNET_assert (variance >= 0);
std_dev = sqrt (variance);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18283 - gnunet/src/nse,
gnunet <=