diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-23 18:57:13 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-23 18:57:13 +0000 |
commit | 383241240e8b1409c5e36dd00074af8402aa6c10 (patch) | |
tree | 6cfc283b87f7eaa07e004bb8a386669a6851d911 /src/nse | |
parent | 5d2ea67c611975319dba37741dc6561cce3a9559 (diff) | |
download | gnunet-383241240e8b1409c5e36dd00074af8402aa6c10.tar.gz gnunet-383241240e8b1409c5e36dd00074af8402aa6c10.zip |
fixing west algorithm to also use j and to consider case where estimate_count is 0
Diffstat (limited to 'src/nse')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index a0140ca28..f7b5e311d 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -303,6 +303,7 @@ static void | |||
303 | setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | 303 | setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) |
304 | { | 304 | { |
305 | unsigned int i; | 305 | unsigned int i; |
306 | unsigned int j; | ||
306 | double mean; | 307 | double mean; |
307 | double sum; | 308 | double sum; |
308 | double std_dev; | 309 | double std_dev; |
@@ -323,20 +324,19 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
323 | sumweight = 0.0; | 324 | sumweight = 0.0; |
324 | for (i = 0; i < estimate_count; i++) | 325 | for (i = 0; i < estimate_count; i++) |
325 | { | 326 | { |
326 | val = | 327 | j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
327 | htonl (size_estimate_messages | 328 | val = htonl (size_estimate_messages[j].matching_bits); |
328 | [(estimate_index - i + | 329 | weight = 1.0; /* was: estimate_count + 1 - i; */ |
329 | HISTORY_SIZE) % HISTORY_SIZE].matching_bits); | ||
330 | weight = 1; /* was: estimate_count + 1 - i; */ | ||
331 | 330 | ||
332 | temp = weight + sumweight; | 331 | temp = weight + sumweight; |
333 | q = val - mean; | 332 | q = val - mean; |
334 | r = q * weight / temp; | 333 | r = q * weight / temp; |
335 | sum += sumweight * q * r; | ||
336 | mean += r; | 334 | mean += r; |
335 | sum += sumweight * q * r; | ||
337 | sumweight = temp; | 336 | sumweight = temp; |
338 | } | 337 | } |
339 | variance = sum / (sumweight - 1.0); | 338 | if (estimate_count > 0) |
339 | variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0); | ||
340 | #else | 340 | #else |
341 | /* trivial version for debugging */ | 341 | /* trivial version for debugging */ |
342 | double vsq; | 342 | double vsq; |
@@ -349,8 +349,6 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
349 | 349 | ||
350 | for (i = 0; i < estimate_count; i++) | 350 | for (i = 0; i < estimate_count; i++) |
351 | { | 351 | { |
352 | unsigned int j; | ||
353 | |||
354 | j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; | 352 | j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE; |
355 | val = htonl (size_estimate_messages[j].matching_bits); | 353 | val = htonl (size_estimate_messages[j].matching_bits); |
356 | sum += val; | 354 | sum += val; |
@@ -360,8 +358,9 @@ setup_estimate_message (struct GNUNET_NSE_ClientMessage *em) | |||
360 | { | 358 | { |
361 | mean = sum / estimate_count; | 359 | mean = sum / estimate_count; |
362 | variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability... | 360 | variance = (vsq - mean * sum) / (estimate_count - 1.0); // terrible for numerical stability... |
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(%f - %f) / %u = %f\n", | 361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
364 | vsq, mean * sum, estimate_count - 1, variance); | 362 | "(%f - %f) / %u = %f\n", |
363 | vsq, mean * sum, estimate_count - 1, variance); | ||
365 | 364 | ||
366 | } | 365 | } |
367 | #endif | 366 | #endif |