-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_old.py
90 lines (73 loc) · 3.08 KB
/
main_old.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
expt_ssim_sum = {}
expt_count = {}
for df in pd.read_csv(VIDEO_SENT, sep=',', chunksize=1000000):
# Raw ssim to db: -10.0 * log10( 1 - raw_ssim );
ssim_sum = df.loc[:, ("expt_id", "ssim_index")].groupby(
"expt_id").agg(['sum', 'count'])
for expt_id, r in ssim_sum.iterrows():
if expt_id in expt_ssim_sum:
expt_ssim_sum[expt_id] += r.loc["ssim_index"].loc["sum"]
expt_count[expt_id] += r.loc["ssim_index"].loc["count"]
else:
expt_ssim_sum[expt_id] = r.loc["ssim_index"].loc["sum"]
expt_count[expt_id] = r.loc["ssim_index"].loc["count"]
print(expt_ssim_sum.keys())
# not group abr
# expt_ssim_mean = {k: expt_ssim_sum[k] / expt_count[k]
# for k in expt_ssim_sum.keys()}
# group abr
groups = {}
for expt_id in expt_count.keys():
g = expt_set[expt_id]["group"]
if g not in groups:
groups[g] = set()
groups[g].add(expt_id)
expt_group_count = {g: sum(expt_count[e]
for e in groups[g]) for g in groups.keys()}
expt_group_ssim_mean = {g: sum(expt_ssim_sum[e] for e in groups[g]) / expt_group_count[g]
for g in groups.keys()}
expt_ssim_mean = {
k: expt_group_ssim_mean[expt_set[k]["group"]] for k in expt_ssim_sum.keys()}
# second pass to calculate std
expt_ssim_var_sum = {}
for df in pd.read_csv(VIDEO_SENT, sep=',', chunksize=1000000):
df["ssim_var"] = (df["expt_id"].map(
expt_ssim_mean) - df["ssim_index"]) ** 2
ssim_sum = df.loc[:, ("expt_id", "ssim_var")].groupby(
"expt_id").agg(['sum'])
for expt_id, r in ssim_sum.iterrows():
if expt_id in expt_ssim_var_sum:
expt_ssim_var_sum[expt_id] += r.loc["ssim_var"].loc["sum"]
else:
expt_ssim_var_sum[expt_id] = r.loc["ssim_var"].loc["sum"]
print(expt_ssim_var_sum.keys())
# not group abr
expt_ssim_std = {k: (expt_ssim_var_sum[k] / expt_count[k]) ** .5
for k in expt_ssim_var_sum.keys()}
# group abr
expt_group_ssim_std = {g: (sum(expt_ssim_var_sum[e] for e in groups[g]) / expt_group_count[g]) ** .5
for g in groups.keys()}
sorted_groups = sorted(groups.keys())
num_groups = len(sorted_groups)
data_dict = {}
for y in range(num_groups):
g = sorted_groups[y]
z95 = st.norm.ppf(.975)
lower = ssim2db(
expt_group_ssim_mean[g] - z95 * expt_group_ssim_std[g] / (expt_group_count[g] ** .5))
upper = ssim2db(
expt_group_ssim_mean[g] + z95 * expt_group_ssim_std[g] / (expt_group_count[g] ** .5))
plt.plot((lower, upper), (y, y), 'ro-', color='orange')
plt.yticks(range(num_groups), sorted_groups)
plt.show()
print("time used: ", time.time() - t_start)
sum = 0
for df in pd.read_csv(VIDEO_SENT, sep=',', chunksize=1000000):
# Raw ssim to db: -10.0 * log10( 1 - raw_ssim );
ssim_sum = df.loc[:, ("expt_id", "ssim_index")].groupby(
"expt_id").agg(['sum', 'count'])
for expt_id, r in ssim_sum.iterrows():
sum += r.loc["ssim_index"].loc["count"]
sum_ack = 0
for df in pd.read_csv(VIDEO_ACKED, sep=',', chunksize=1000000):
sum_ack += len(df)