-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_netsz_itt_acc.py
182 lines (160 loc) · 5.61 KB
/
draw_netsz_itt_acc.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
'''
the results of this script is determined as an experiment part for the publication
this script aims at figuring out the relationship between iterative times and network size
'''
import numpy as np
from cutils import random_initialize, set_c, set_dis
from dp_avg_consensus import dp_avg_consensus, direct_cal_diff
from cgeograph import gen_draw_geograph
import matplotlib.pyplot as plt
import datetime
from matplotlib.lines import Line2D
q_ = 0 # one-shot adding
s_ = 1.0
dp_eps_ = 0.3
c_ = set_c(dp_eps_, q_, s_)
size_list = [50, 100, 150, 200, 225, 250, 275, 300]
def cmp_netsz_iternumbers(unique_id, dp_eps_):
fig = plt.figure()
plt.rc('text', usetex=True)
plt.rc('font', family='Times New Roman', weight='normal', size=14)
plt.rcParams['mathtext.fontset'] = 'stix'
# set_xscale only supported in add_subplot
ax = fig.add_subplot(111)
mean_cord = []
for n in size_list:
# for n in [5]:
q = [q_ for _ in range(n)]
s = [s_ for _ in range(n)]
c = [c_ for _ in range(n)]
state = random_initialize(n, 50, 100)
G, fig_id = gen_draw_geograph(n, set_dis(n), unique_id)
y_cord = []
for _ in range(20):
records = dp_avg_consensus(G,
fig_id,
c,
q,
s,
state=np.matrix(state).transpose())
y_cord.append(records.shape[1])
ax.scatter([n for _ in range(20)],
y_cord,
marker='D',
s=160,
facecolors='none',
edgecolors='black')
mean_cord.append(np.mean(y_cord))
ax.scatter(size_list,
mean_cord,
marker='o',
s=80,
color='none',
edgecolors='g',
linewidth=3)
ax.plot(size_list, mean_cord, c='b', lw=1)
# custom legend
legend_elements = [
Line2D([0], [0],
c='none',
marker='D',
markerfacecolor='none',
markeredgecolor='black',
label='Iterative Times of Each Run (PE-IDA)',
markersize=9),
Line2D([0], [0],
c='none',
marker='o',
markerfacecolor='none',
markeredgewidth=3,
markeredgecolor='g',
label='Iterative Times of IDA algorithm',
markersize=9)
]
ax.legend(handles=legend_elements, prop={'size': 15})
plt.xticks([50, 100, 150, 200, 225, 250, 275, 300],
fontsize=20,
weight='bold')
plt.yticks(fontsize=20, weight='bold')
plt.xlabel(r"$|\mathcal{V}|$", fontsize=20)
plt.ylabel(r"Iterative Times", fontsize=25, weight='bold')
ax.grid(ls=':')
ax.set_aspect(1.0 / ax.get_data_ratio() * 0.6)
# plt.show()
# plt.show()
fig_id = unique_id + "_eps_" + str(dp_eps_).replace('.', '') + "_szitt"
plt.savefig("../final_exp_publication/netsz_acc_itertnum/" + fig_id +
'.pdf',
bbox_inches="tight",
pad_inches=0.01)
def cmp_netsz_accuracy(unique_id, dp_eps_):
fig = plt.figure()
plt.rc('text', usetex=True)
plt.rc('font', family='Times New Roman', weight='normal', size=14)
plt.rcParams['mathtext.fontset'] = 'stix'
# set_xscale only supported in add_subplot
ax = fig.add_subplot(111)
mean_cord = []
for n in size_list:
# for n in [5]:
state = random_initialize(n, 50, 100)
G, _ = gen_draw_geograph(n, set_dis(n), unique_id)
y_cord = []
for _ in range(20):
y_cord.append(direct_cal_diff(n, s_, c_))
ax.scatter(
[n for _ in range(20)],
y_cord,
marker='P',
s=160,
# color="#007dff",
# linewidth=2,
color='none',
edgecolors='black')
mean_cord.append(np.mean(y_cord))
ax.scatter(size_list,
mean_cord,
marker='o',
s=80,
color='none',
edgecolors='b',
linewidth=3)
ax.plot(size_list, mean_cord, c='b', lw=1)
# custom legend
legend_elements = [
Line2D([0], [0],
c='none',
marker='P',
markerfacecolor='none',
markeredgecolor='black',
label='Error of Each Run',
markersize=9),
Line2D([0], [0],
c='none',
marker='o',
markerfacecolor='none',
markeredgewidth=3,
markeredgecolor='b',
label='Empirical Mean',
markersize=9)
]
ax.legend(handles=legend_elements, prop={'size': 15})
ax.grid(ls=':')
plt.xticks([50, 100, 150, 200, 225, 250, 275, 300],
fontsize=20,
weight='bold')
plt.yticks(fontsize=20, weight='bold')
# plt.yticks([1, 2])
plt.xlabel(r"$|\mathcal{V}|$", fontsize=20)
plt.ylabel(r"$|x^{*} - \bar{\mathbf{x}}|$", fontsize=25)
ax.set_aspect(1.0 / ax.get_data_ratio() * 0.6)
# plt.show()
fig_id = unique_id + "_eps_" + str(dp_eps_).replace('.', '') + "_szacc"
plt.savefig("../final_exp_publication/netsz_acc_itertnum/" + fig_id +
'.pdf',
bbox_inches="tight",
pad_inches=0.01)
for e in [0.01, 0.1, 1, 10]:
unique_id = str(datetime.datetime.now().strftime('%m%d-%H%M%S'))
cmp_netsz_accuracy(unique_id, e)
cmp_netsz_iternumbers(unique_id, e)