Update criteria for partial/full IPv6 support.
[tor-metrics-tasks.git] / task-1854 / plot-entropy.R
blobac02782ba30bf487ac9a8dbe51fc0d66424e8f21
1 library(ggplot2)
2 library(reshape)
3 library(scales)
5 p <- read.csv("prob-extracted.csv", header = FALSE,
6   col.names = c("validafter", "minadvbw", "advbw", "cumprob", "prob"),
7   stringsAsFactor = FALSE)
8 p <- p[p$minadvbw >= 20480, ]
9 c <- data.frame(x = p$advbw, y = p$cumprob,
10   colour = as.factor(p$minadvbw))
11 ggplot(c, aes(x = x, y = y, colour = colour)) +
12 geom_line() +
13 scale_x_log10(name = "\nAdvertised bandwidth in B/s (log scale)") +
14 scale_y_continuous(name = "Cumulative probability\n") +
15 scale_colour_hue(name = "Adv. bw. cutoff in B/s") +
16 opts(title = paste("Consensus with valid-after time", max(p$validafter)),
17   legend.position = "top")
19 ggplot(c, aes(x = x, y = y, colour = colour)) +
20 geom_line() +
21 scale_x_log10(name = "\nAdvertised bandwidth in B/s (log scale)") +
22 scale_y_log10(name = "Cumulative probability (log scale)\n") +
23 scale_colour_hue(name = "Adv. bw. cutoff in B/s") +
24 opts(title = paste("Consensus with valid-after time", max(p$validafter)),
25   legend.position = "top")
27 p <- p[p$minadvbw == 20480 | p$minadvbw == 1048576, ]
28 c <- data.frame(x = p$advbw, y = p$prob,
29   colour = as.factor(p$minadvbw))
30 ggplot(c, aes(x = x, y = y, colour = colour)) +
31 geom_point(alpha = 0.25) +
32 scale_x_log10(name = "\nAdvertised bandwidth in B/s (log scale)") +
33 scale_y_continuous(name = paste("Single relay probability, *not*",
34   "probability distribution function\n")) +
35 scale_colour_hue(name = "Advertised bandwidth cutoff in B/s") +
36 opts(title = paste("Consensus with valid-after time", max(p$validafter)),
37   legend.position = "top")
39 ggplot(c, aes(x = x, y = y, colour = colour)) +
40 geom_point(alpha = 0.25) +
41 scale_x_log10(name = "\nAdvertised bandwidth in B/s (log scale)") +
42 scale_y_log10(name = paste("Single relay probability, *not*",
43   "probability distribution function (log scale)\n")) +
44 scale_colour_hue(name = "Advertised bandwidth cutoff in B/s") +
45 opts(title = paste("Consensus with valid-after time", max(p$validafter)),
46   legend.position = "top")
48 c <- p[p$advbw >= 1048576, ]
49 c <- data.frame(advbw = c$advbw, prob = c$prob,
50   minadvbw = paste("c", c$minadvbw, sep = ""))
51 c <- cast(c, advbw ~ minadvbw, value = "prob")
52 c <- data.frame(advbw = c$advbw, rel = c$c1048576 / c$c20480)
53 ggplot(c, aes(x = advbw, y = rel)) +
54 geom_point(alpha = 0.25) +
55 scale_x_log10(name = "\nAdvertised bandwidth in B/s (log scale)") +
56 scale_y_continuous(name = paste("Ratio of probaility at 1 MiB/s cutoff",
57   "to probability at 20 KiB/s cutoff\n")) +
58 opts(title = paste("Consensus with valid-after time ", max(p$validafter),
59   "\n", sep = ""), legend.position = "top")
61 e <- read.csv("linf-extracted.csv", header = FALSE,
62   col.names = c("validafter", "min_adv_bw", "relays", "linf",
63   "excl_adv_bw", "graph"), stringsAsFactor = FALSE)
65 l <- e[e$graph == 'last', ]
66 l <- data.frame(x = l$min_adv_bw, relays = l$relays,
67   excladvbw = l$excl_adv_bw, linf = l$linf)
68 l <- melt(l, "x")
69 ggplot(l, aes(x = x, y = value)) +
70 geom_line() +
71 facet_grid(variable ~ ., scales = "free_y") +
72 scale_x_log10(name = "\nAdvertised bandwidth cutoff in B/s (log scale)") +
73 scale_y_continuous(name = paste("Number of relays, excluded advertised",
74   "bandwidth, or linf\n")) +
75 opts(title = paste("Consensus with valid-after time ", max(e$validafter),
76   "\n", sep = ""))
78 l <- e[e$graph == 'last', ]
79 l <- data.frame(x = l$min_adv_bw, relays = l$relays,
80   excladvbw = l$excl_adv_bw, linf = l$linf)
81 l <- melt(l, "x")
82 ggplot(l, aes(x = x, y = value)) +
83 geom_line() +
84 facet_grid(variable ~ ., scales = "free_y") +
85 scale_x_log10(name = "\nAdvertised bandwidth cutoff in B/s (log scale)") +
86 scale_y_log10(name = paste("Number of relays, excluded advertised",
87   "bandwidth, or linf (log scale)\n")) +
88 opts(title = paste("Consensus with valid-after time ", max(e$validafter),
89   "\n", sep = ""))
91 l <- e[e$graph == 'last' & e$min_adv_bw >= 10000 & e$min_adv_bw <= 100000, ]
92 l <- data.frame(x = l$min_adv_bw, relays = l$relays,
93   excladvbw = l$excl_adv_bw, linf = l$linf)
94 l <- melt(l, "x")
95 ggplot(l, aes(x = x, y = value)) +
96 geom_line() +
97 facet_grid(variable ~ ., scales = "free_y") +
98 scale_x_log10(name = "\nAdvertised bandwidth cutoff in B/s (zoomed, log scale)") +
99 scale_y_continuous(name = paste("Number of relays, excluded advertised",
100   "bandwidth, or linf\n")) +
101 opts(title = paste("Consensus with valid-after time ", max(e$validafter),
102   "\n", sep = ""))
104 h <- e[e$graph == 'history' & e$min_adv_bw == 10000, ]
105 h <- data.frame(validafter = h$validafter, relays = h$relays, linf = h$linf)
106 h <- aggregate(h[, 2:length(h)], by = list(x = as.Date(h$validafter)), FUN = mean)
107 h <- melt(h, "x")
108 ggplot(h, aes(x = as.POSIXct(x), y = value)) +
109 geom_line() +
110 facet_grid(variable ~ ., scales = "free_y") +
111 scale_x_datetime(name = "") +
112 scale_y_continuous(name = "") +
113 opts(title = "Advertised bandwidth cutoff 10000 B/s\n")
115 h <- e[e$graph == 'history' & e$min_adv_bw == 50000, ]
116 h <- data.frame(validafter = h$validafter, relays = h$relays, linf = h$linf)
117 h <- aggregate(h[, 2:length(h)], by = list(x = as.Date(h$validafter)), FUN = mean)
118 h <- melt(h, "x")
119 ggplot(h, aes(x = as.POSIXct(x), y = value)) +
120 geom_line() +
121 facet_grid(variable ~ ., scales = "free_y") +
122 scale_x_datetime(name = "") +
123 scale_y_continuous(name = "") +
124 opts(title = "Advertised bandwidth cutoff 50000 B/s\n")
126 h <- e[e$graph == 'history' & e$min_adv_bw == 100000, ]
127 h <- data.frame(validafter = h$validafter, relays = h$relays, linf = h$linf)
128 h <- aggregate(h[, 2:length(h)], by = list(x = as.Date(h$validafter)), FUN = mean)
129 h <- melt(h, "x")
130 ggplot(h, aes(x = as.POSIXct(x), y = value)) +
131 geom_line() +
132 facet_grid(variable ~ ., scales = "free_y") +
133 scale_x_datetime(name = "") +
134 scale_y_continuous(name = "") +
135 opts(title = "Advertised bandwidth cutoff 100000 B/s\n")
137 h <- e[e$graph == 'history' & e$min_adv_bw %in% c(10000, 50000, 100000), ]
138 h <- data.frame(validafter = h$validafter, min_adv_bw = h$min_adv_bw, relays = h$relays, linf = h$linf)
139 h <- aggregate(h[, 2:length(h)],
140   by = list(x = as.Date(h$validafter), min_adv_bw = h$min_adv_bw), FUN = mean)
141 h <- melt(h, c("x", "min_adv_bw"))
142 ggplot(h, aes(x = as.POSIXct(x), y = value, colour = as.factor(min_adv_bw))) +
143 geom_line() +
144 facet_grid(variable ~ ., scales = "free_y") +
145 scale_x_datetime(name = "") +
146 scale_y_continuous(name = "") +
147 scale_colour_hue(name = "Advertised bandwidth cutoff in B/s") +
148 opts(legend.position = "bottom")
150 h <- e[e$graph == 'history' & e$min_adv_bw == 10000, ]
151 m10000 <- data.frame(linf = sort(h$linf),
152   frac_cons = (1:length(h$linf))/length(h$linf), min_adv_bw = "10000")
153 h <- e[e$graph == 'history' & e$min_adv_bw == 50000, ]
154 m50000 <- data.frame(linf = sort(h$linf),
155   frac_cons = (1:length(h$linf))/length(h$linf), min_adv_bw = "50000")
156 h <- e[e$graph == 'history' & e$min_adv_bw == 100000, ]
157 m100000 <- data.frame(linf = sort(h$linf),
158   frac_cons = (1:length(h$linf))/length(h$linf), min_adv_bw = "100000")
159 h <- rbind(m10000, m50000, m100000)
160 ggplot(h, aes(x = linf, y = frac_cons, colour = as.factor(min_adv_bw))) +
161 geom_line() +
162 scale_x_continuous(name = "") +
163 scale_y_continuous(
164   name = "Fraction of consensuses from 2011-11-01 to 2012-10-31\n") +
165 scale_colour_hue(name = "Advertised bandwidth cutoff in B/s") +
166 opts(legend.position = "bottom")