fixing variance calculation - we calculate the average from the same distribution...
authorChristian Grothoff <christian@grothoff.org>
Wed, 23 Nov 2011 18:48:46 +0000 (18:48 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 23 Nov 2011 18:48:46 +0000 (18:48 +0000)
src/nse/gnunet-service-nse.c

index 61ab7e57ab60d3077295ad38b5fe5ef37e52ad58..a0140ca28a8a0043f8836b1d4cd156d23e927b83 100644 (file)
@@ -349,7 +349,7 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
 
   for (i = 0; i < estimate_count; i++)
   {
-    int j;
+    unsigned int j;
 
     j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
     val = htonl (size_estimate_messages[j].matching_bits);
@@ -359,9 +359,9 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
   if (0 != estimate_count)
   {
     mean = sum / estimate_count;
-    variance = (vsq - mean * sum) / estimate_count; // terrible for numerical stability...
+    variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability...
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(%f - %f) / %u = %f\n", 
-      vsq, mean * sum, estimate_count, variance);
+      vsq, mean * sum, estimate_count - 1, variance);
 
   }
 #endif