-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlap_check.py
More file actions
72 lines (63 loc) · 2.88 KB
/
overlap_check.py
File metadata and controls
72 lines (63 loc) · 2.88 KB
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
#!/usr/bin/env python3
import itertools
from collections import Counter
import pandas as pd
# read in the train and test set
# see how many overlaps there are
all_pref_models = [
"stratification__args__weight=0.5",
"URN-R",
"IC",
"IAC",
"identity",
"MALLOWS-RELPHI-R",
"single_peaked_conitzer",
"single_peaked_walsh",
"euclidean__args__dimensions=3_-_space=gaussian_ball",
"euclidean__args__dimensions=10_-_space=gaussian_ball",
"euclidean__args__dimensions=3_-_space=uniform_ball",
"euclidean__args__dimensions=10_-_space=uniform_ball",
"euclidean__args__dimensions=3_-_space=gaussian_cube",
"euclidean__args__dimensions=10_-_space=gaussian_cube",
"euclidean__args__dimensions=3_-_space=uniform_cube",
"euclidean__args__dimensions=10_-_space=uniform_cube",
"mixed"
]
header = ["# Alternatives", "# Winners", "Distribution", "Overlap Count", "Overlap Percent"]
rows = []
for dist in all_pref_models:
for m in [5, 6, 7]:
for committee_size in range(1, m):
base_path = "data/"
filepath = f"n_profiles=25000-num_voters=50-m={m}-committee_size={committee_size}-pref_dist={dist}-axioms=all"
test_suffix = "-TEST.csv"
train_suffix = "-TRAIN.csv"
test_path = base_path + filepath + test_suffix
train_path = base_path + filepath + train_suffix
try:
test_df = pd.read_csv(test_path)
train_df = pd.read_csv(train_path)
# how many Profile entries in test_df are in train_df?
train = train_df["Profile"].to_numpy()
train_profiles = []
test = test_df["Profile"].to_numpy()
test_sets = set()
overlap_count = 0
for profile_idx in range(len(train)):
train_pr = Counter(eval(train[profile_idx]))
train_profiles.append(str(train_pr))
test_pr = Counter(eval(test[profile_idx]))
test_sets.add(str(test_pr))
# Check how many of the train sets appear in the test sets
for train_profile in train_profiles:
if train_profile in test_sets:
overlap_count += 1
# overlap_count = len(set(test_df['Profile']).intersection(set(train_df['Profile'])))
print(f"m={m}, committee_size={committee_size}, dist={dist}")
print(f"Total overlaps: {overlap_count}")
print(f"Percentage overlap: {(overlap_count / len(train_profiles)) * 100:.2f}%\n")
rows.append([m, committee_size, dist, overlap_count, round(overlap_count / len(test_df), 4)])
except Exception as f:
print(f"Exception: {f}")
df = pd.DataFrame(data=rows, columns=header)
df.to_csv("overlap_amounts_all_distributions.csv", index=False)