-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_results.py
104 lines (90 loc) · 3.19 KB
/
plot_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import matplotlib.pyplot as plt
import numpy as np
from cycler import cycler
colors = ['red', 'blue', 'black', 'orange', 'green', 'purple']
linewidth = 2.0
# Load data
attacker_data = np.genfromtxt('attackers')
defender_data = np.genfromtxt('defenders')
utility_data = np.genfromtxt('utility')
type_data = np.genfromtxt('node_types.txt')
type_names = ['HES','Collector', 'Meter/Collector', 'Meter']
generations = attacker_data.shape[0]
if generations > 40:
markfreq = int(generations/40)
else:
markfreq = 1
attacker_data_type = np.zeros((generations, 4))
attacker_data_level = np.zeros((generations, 4))
defender_data_type = np.zeros((generations, 4))
defender_data_level = np.zeros((generations, 4))
for i in range(0, attacker_data.shape[1]):
attacker_data_type[:, int(type_data[i, 0])] += attacker_data[:, i]
attacker_data_level[:, int(type_data[i, 1])] += attacker_data[:, i]
for i in range(0, defender_data.shape[1]):
defender_data_type[:, int(type_data[i, 0])] += defender_data[:, i]
defender_data_level[:, int(type_data[i, 1])] += defender_data[:, i]
# Utility evolution
plt.figure(3)
gens = range(1, utility_data.shape[0]+1)
plt.plot(gens, utility_data[:, 0], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Attackers')
plt.plot(gens, utility_data[:, 1], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Defenders')
plt.ylabel('Average population utility')
plt.xlabel('Generation #')
plt.legend(loc='best')
plt.savefig('utility_evolution.pdf')
# Attacker level evolution
plt.figure(4)
for i in range(0, attacker_data_level.shape[1]):
gens = range(1, generations+1)
plt.plot(gens, attacker_data_level[:, i], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Level '+str(i+1))
plt.ylabel('Attack rate')
plt.xlabel('Generation #')
plt.legend(loc='upper right')
plt.savefig('attack_rate_level_evolution.pdf')
# Attacker type evolution
plt.figure(5)
for i in range(0, attacker_data_type.shape[1]):
gens = range(1, generations+1)
plt.plot(gens, attacker_data_type[:, i], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Type '+type_names[i])
plt.ylabel('Attack rate')
plt.xlabel('Generation #')
plt.legend(loc='upper right')
plt.savefig('attack_rate_type_evolution.pdf')
# Defender level evolution
plt.figure(6)
for i in range(0, defender_data_level.shape[1]):
gens = range(1, generations+1)
plt.plot(gens, defender_data_level[:, i], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Level '+str(i+1))
plt.ylabel('Defence rate')
plt.xlabel('Generation #')
plt.legend(loc='upper right')
plt.savefig('defence_rate_level_evolution.pdf')
# Defender type evolution
plt.figure(7)
for i in range(0, defender_data_type.shape[1]):
gens = range(1, generations+1)
plt.plot(gens, defender_data_type[:, i], marker='o',
markevery=markfreq,
linewidth=linewidth,
label='Type: '+type_names[i])
plt.ylabel('Defence rate')
plt.xlabel('Generation #')
plt.legend(loc='upper right')
plt.savefig('defence_rate_type_evolution.pdf')
plt.show()