Add plot Python scripts (#82)

This commit is contained in:
Alvaro Revuelta 2024-02-05 09:47:27 +01:00 committed by GitHub
parent 1e3ed6a5cc
commit 12aa11a60b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 37077 additions and 4 deletions

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 69 KiB

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 82 KiB

View File

@ -0,0 +1,47 @@
from math import ceil
from numpy import log
from numpy import ceil
import matplotlib.pyplot as plt
import numpy as np
import scienceplots
L = 1 # latency in ms (msg prop + rln proof verif, etc)
N1 = 1000 # number of nodes in the network (1)
N2 = 10000 # number of nodes in the network (2)
N3 = 100000 # number of nodes in the network (3)
def delay_last_hop(n, d, l):
# multiply by l for latencies
return ceil(log(n)/log(d))
ds = np.arange(2,15)
ls = np.ones(len(ds))*L
# astype(int) is ok since ceil() returns integers
delays_1 = delay_last_hop(np.ones(len(ds))*N1, ds, ls).astype(int)
delays_2 = delay_last_hop(np.ones(len(ds))*N2, ds, ls).astype(int)
delays_3 = delay_last_hop(np.ones(len(ds))*N3, ds, ls).astype(int)
with plt.style.context(['science', 'ieee']):
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(ds, delays_1, color='r', label=r"$N_1=$"+str(N1))
ax1.plot(ds, delays_2, color='g', label=r"$N_2=$"+str(N2))
ax1.plot(ds, delays_3, color='b', label=r"$N_3=$"+str(N3))
ax2.plot(ds, ds, color='y', label="Bandwidth ampl.")
print(delays_1)
print(ds)
ax1.autoscale(tight=True)
ax2.autoscale(tight=True)
ax1.legend(loc=0)
ax2.legend(loc=0)
ax1.set(title='Worst case maximum hops vs bandwidth')
ax1.set(**dict(xlabel='Outbound degree (D)', ylabel='Amount of hops'))
ax2.set(**dict(ylabel='Bandwidth amplification'))
#ax2.set_xlim([2, 14])
fig.savefig('message_hops.svg', dpi=300)
plt.close()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

View File

@ -5,9 +5,8 @@ from analyze import load
latencies = [load("raw/latency_10kb.txt", "arrival_diff="),
load("raw/latency_100kb.txt", "arrival_diff="),
load("raw/latency_500kb.txt", "arrival_diff=")]
print(latencies)
load("raw/latency_500kb.txt", "arrival_diff="),
]
with plt.style.context(['science', 'ieee']):
fig, ax = plt.subplots()
@ -30,4 +29,4 @@ for i, line in enumerate(bp['medians']):
ax.annotate(text, xy=(x + 0.1, y), fontsize=6)
fig.set_size_inches(4, 3)
fig.savefig('plot.jpg', dpi=600)
fig.savefig('latencies_d6.svg', dpi=600)

View File

@ -0,0 +1,36 @@
import matplotlib.pyplot as plt
import scienceplots
import numpy as np
from analyze import load
latencies = [load("raw/latency_10kb.txt", "arrival_diff="),
load("raw/latency_scenario2_10kb.txt", "arrival_diff="),
load("raw/latency_100kb.txt", "arrival_diff="),
load("raw/latency_scenario2_100kb.txt", "arrival_diff="),
#load("raw/latency_500kb.txt", "arrival_diff="),
#load("raw/latency_scenario2_500kb.txt", "arrival_diff=")
]
with plt.style.context(['science', 'ieee']):
fig, ax = plt.subplots()
bp = ax.boxplot(latencies,notch=True, vert=True, patch_artist=True,
showfliers=True, whis=100000000000)
for patch, color in zip(bp['boxes'], ['red', 'blue', 'gold', 'yellowgreen']):
patch.set_facecolor(color)
ax.set(title="Message latencies distribution\nD=6 vs D=3 nodes=1000 samples="+str(latencies[1].size), xlabel='Scenario', ylabel='Message propagation time (ms)')
ax.grid(linestyle='-')
my_legend = []
for msg_size in [10, 100]:
for d in [6, 3]:
my_legend.append("Message size: " + str(msg_size) + " kB"+ " D="+ str(d))
ax.legend([bp["boxes"][i] for i in range(len(my_legend))], my_legend, loc='upper left', fontsize=5)
for i, line in enumerate(bp['medians']):
x, y = line.get_xydata()[1]
text = r' $ \mu =$ ' + '{:.0f} ms\n'.format(latencies[i].mean(axis=0)) + r' $ p_{95} = $ ' + '{:.0f} ms'.format(np.percentile(latencies[i], 95))
ax.annotate(text, xy=(x + 0.1, y), fontsize=6)
fig.set_size_inches(4, 3)
fig.savefig('latencies_d6_vs_d3.svg', dpi=600)

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 65 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff