-
Notifications
You must be signed in to change notification settings - Fork 0
/
fusion_test.py
133 lines (118 loc) · 5.47 KB
/
fusion_test.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
import random
import os
from classifiers.template_generator import all_ids
from experiments import print_k_table
from features.word_parser import SentenceParser
from fusion.decsion_fusion import get_actual_designation, is_fake_profile, verdict
from fusion.score_fusion import FusionAlgorithm, ScoreFuser
from performance_evaluation.heatmap import HeatMap, VerifierType, get_user_by_platform
from features.keystroke_features import (
create_kht_data_from_df,
create_kit_data_from_df,
word_hold,
)
import classifiers.verifiers_library as vl
from rich.progress import track
def decision_fusion_test():
correct = 0
ids = all_ids()
for _ in track(range(100)):
enrollment = random.choice(ids)
probe = random.choice(ids)
df = get_user_by_platform(enrollment, 1, None)
sp = SentenceParser(os.path.join(os.getcwd(), "cleaned2.csv"))
word_list = sp.get_words(df)
word_hold_enrollment = word_hold(word_list, df)
kht_enrollment = create_kht_data_from_df(df)
kit_enrollment = create_kit_data_from_df(df, 1)
combined_enrollment = kht_enrollment | kit_enrollment | word_hold_enrollment
df = get_user_by_platform(probe, 1, None)
kht_probe = create_kht_data_from_df(df)
kit_probe = create_kit_data_from_df(df, 1)
word_list = sp.get_words(df)
word_hold_probe = word_hold(word_list, df)
combined_probe = kht_probe | kit_probe | word_hold_probe
v = vl.Verify(combined_enrollment, combined_probe)
print("Enrollment:" + str(enrollment))
print("Probe:" + str(probe))
verdicts = []
verdicts.append(verdict(v.get_abs_match_score(), VerifierType.ABSOLUTE))
verdicts.append(verdict(v.get_similarity_score(), VerifierType.SIMILARITY))
verdicts.append(verdict(v.itad_similarity(), VerifierType.ITAD))
res = is_fake_profile(verdicts)
if res == get_actual_designation(enrollment, probe):
correct += 1
print("Correct fusion classifications = " + str(correct / 100))
def score_fusion_test(fusion_algorithm: FusionAlgorithm):
itad_heatmap = HeatMap(VerifierType.ITAD)
itad_matrix = itad_heatmap.combined_keystroke_matrix(1, 2, None, None, 1)
similarity_heatmap = HeatMap(VerifierType.SIMILARITY)
similarity_matrix = similarity_heatmap.combined_keystroke_matrix(
1, 2, None, None, 1
)
absolute_heatmap = HeatMap(VerifierType.ABSOLUTE)
absolute_matrix = absolute_heatmap.combined_keystroke_matrix(1, 2, None, None, 1)
sf = ScoreFuser(itad_matrix, similarity_matrix, absolute_matrix)
res = sf.find_matrix(fusion_algorithm)
ids = all_ids()
print(fusion_algorithm)
print_k_table(matrix=res, ids=ids)
print(
"________________________________________________________________________________________________________________________________"
)
def platform_fusion_cross_test():
heatmap = HeatMap(VerifierType.SIMILARITY)
similarity_matrix = heatmap.combined_keystroke_matrix(1, 2, None, None, 1)
heatmap = HeatMap(VerifierType.ABSOLUTE)
absolute_matrix = heatmap.combined_keystroke_matrix(1, 2, None, None, 1)
heatmap = HeatMap(VerifierType.ITAD)
itad_matrix = heatmap.combined_keystroke_matrix(1, 2, None, None, 1)
sf = ScoreFuser(itad_matrix, similarity_matrix, absolute_matrix)
for fusion_algorithm in FusionAlgorithm:
res = sf.find_matrix(fusion_algorithm)
ids = all_ids()
print(fusion_algorithm)
print("F vs. I")
print_k_table(matrix=res, ids=ids)
def platform_even_split_fusion_cross_test():
heatmap = HeatMap(VerifierType.SIMILARITY)
similarity_matrix = heatmap.combined_keystroke_matrix(2, 2, [1, 3], [4, 6], 1)
heatmap = HeatMap(VerifierType.ABSOLUTE)
absolute_matrix = heatmap.combined_keystroke_matrix(2, 2, [1, 3], [4, 6], 1)
heatmap = HeatMap(VerifierType.ITAD)
itad_matrix = heatmap.combined_keystroke_matrix(2, 2, [1, 3], [4, 6], 1)
sf = ScoreFuser(itad_matrix, similarity_matrix, absolute_matrix)
res = sf.find_matrix(FusionAlgorithm.MEDIAN)
ids = all_ids()
print("Instagram - even split")
print_k_table(matrix=res, ids=ids)
def single_platform_cross_test():
heatmap = HeatMap(VerifierType.ABSOLUTE)
absolute_matrix = heatmap.combined_keystroke_matrix(2, 1, None, None, 1)
heatmap = HeatMap(VerifierType.SIMILARITY)
similarity_matrix = heatmap.combined_keystroke_matrix(2, 1, None, None, 1)
heatmap = HeatMap(VerifierType.ITAD)
itad_matrix = heatmap.combined_keystroke_matrix(2, 1, None, None, 1)
sf = ScoreFuser(itad_matrix, similarity_matrix, absolute_matrix)
res = sf.find_matrix(FusionAlgorithm.MEAN)
ids = all_ids()
print("I vs. F")
print_k_table(matrix=res, ids=ids)
def dual_platform_fusion_test():
heatmap = HeatMap(VerifierType.ABSOLUTE)
abs_matrix = heatmap.combined_keystroke_matrix([3, 2], 1, None, None, 1)
heatmap = HeatMap(VerifierType.SIMILARITY)
sim_matrix = heatmap.combined_keystroke_matrix([3, 2], 1, None, None, 1)
heatmap = HeatMap(VerifierType.ITAD)
itad_matrix = heatmap.combined_keystroke_matrix([3, 2], 1, None, None, 1)
sf = ScoreFuser(itad_matrix, sim_matrix, abs_matrix)
res = sf.find_matrix(FusionAlgorithm.MEAN)
ids = all_ids()
print("TI")
print_k_table(matrix=res, ids=ids)
res = sf.find_matrix(FusionAlgorithm.MEDIAN)
ids = all_ids()
print("TI")
print_k_table(matrix=res, ids=ids)
if __name__ == "__main__":
platform_even_split_fusion_cross_test()