[tor-commits] [metrics-tasks/master] Plot 'degree of anonymity' instead of entropy.

karsten at torproject.org karsten at torproject.org
Tue Jul 17 13:25:38 UTC 2012


commit e54b4278361184bf6ff90f189898668160474f2f
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Jul 16 20:13:52 2012 +0200

    Plot 'degree of anonymity' instead of entropy.
    
    'Degree of anonymity' should give a more intuitive view of the
    situation. For more information, see section 3 of 'Towards measuring
    anonymity' by C. Diaz, S. Stefaan, J. Claessens and B. Preneel.
---
 task-6232/plot-entropy.R |    2 +-
 task-6232/pyentropy.py   |   17 +++++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/task-6232/plot-entropy.R b/task-6232/plot-entropy.R
index 95dbdcc..87035b9 100644
--- a/task-6232/plot-entropy.R
+++ b/task-6232/plot-entropy.R
@@ -10,7 +10,7 @@ d <- melt(d, "date")
 ggplot(d, aes(x = date, y = value, colour = variable)) +
 geom_line() +
 scale_x_date(name = "\nDate") +
-scale_y_continuous(name = "Entropy\n") +
+scale_y_continuous(name = "Degree of Anonymity\n") +
 scale_colour_hue(name = "Relays",
   breaks = c("all", "exit", "guard", "country"),
   labels = c("All relays", "All exits", "All guards", "All countries"))
diff --git a/task-6232/pyentropy.py b/task-6232/pyentropy.py
index b064339..abb716a 100644
--- a/task-6232/pyentropy.py
+++ b/task-6232/pyentropy.py
@@ -57,13 +57,16 @@ def run(file_name):
                 router.add(key, values)
 
     totalBW, totalExitBW, totalGuardBW = 0, 0, 0
+    guards_n, exits_n = 0, 0
     bw_countries = {}
     for router in routers:
         totalBW += router.bandwidth
         if router.is_guard:
             totalGuardBW += router.bandwidth
+            guards_n += 1
         if router.is_exit:
             totalExitBW += router.bandwidth
+            exits_n += 1
         if bw_countries.has_key(router.country):
             bw_countries[router.country] += router.bandwidth
         else:
@@ -90,8 +93,18 @@ def run(file_name):
         p = float(bw_countries[country]) / float(totalBW)
         if p != 0:
             entropy_country += -(p * math.log(p, 2))
-    
-    return ",".join([valid_after, str(entropy), str(entropy_exit), str(entropy_guard), str(entropy_country)])
+
+    # Entropy of uniform distribution of 'n' possible values: log(n)
+    max_entropy = math.log(len(routers), 2)
+    max_entropy_guard = math.log(guards_n, 2)
+    max_entropy_exit = math.log(exits_n, 2)
+    max_entropy_country = math.log(len(bw_countries), 2)
+
+    return ",".join([valid_after,
+                     str(entropy/max_entropy),
+                     str(entropy_exit/max_entropy_exit),
+                     str(entropy_guard/max_entropy_guard),
+                     str(entropy_country/max_entropy_country)])
 
 def usage():
     print "Usage - python pyentropy.py <consensus-dir> <output-file>"





More information about the tor-commits mailing list