-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeanNormalize.py
More file actions
159 lines (129 loc) · 4.84 KB
/
Copy pathMeanNormalize.py
File metadata and controls
159 lines (129 loc) · 4.84 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
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
import csv
from operator import itemgetter
#gets the global mean of neutral and global mean of max of other
def get_global_mean(facet_file, start_time_list, end_time_list):
neutral = []
other = []
for i in range(len(facet_file)):
facet = facet_file[i]
start_time = start_time_list[i]
end_time = end_time_list[i]
i = [5,6,7,8,9,11,13,12,14]
with open(facet,'r') as file:
reader = csv.reader(file, dialect='excel')
next(reader, None)
for row in reader:
if len(row) < 1:
break
if float(row[0]) > start_time/1000 and float(row[0]) < end_time/1000:
n = float(row[10])
o = [float(row[ind]) for ind in i]
neutral.append(n)
other.append(o)
#global mean
global_mean_neutral = sum(neutral)/len(neutral)
max_other = []
max_ind = []
for o in other:
max_ind.append(max(enumerate(o), key=itemgetter(1))[0])
max_other.append(max(enumerate(o), key=itemgetter(1))[1])
global_mean_other = sum(max_other)/len(max_other)
return global_mean_neutral, global_mean_other
def get_facet_data_all(file, start_time, end_time, global_mean_neutral, global_mean_other):
time = []
neutral = []
confusion = []
other = []
i = [5,6,7,8,9,11,12,14]
with open(file,'r') as file:
reader = csv.reader(file, dialect='excel')
next(reader, None)
for row in reader:
if len(row) < 1:
break
if float(row[0]) > start_time/1000 and float(row[0]) < end_time/1000:
t = float(row[0])*1000
n = float(row[10])
c = float(row[13])
o = [float(row[ind]) for ind in i]
time.append(t)
neutral.append(n)
confusion.append(c)
other.append(o)
#mean normalize value
if global_mean_neutral is None:
avg = sum(neutral)/len(neutral)
else:
avg = global_mean_neutral
mean_norm_neutral = [i-avg for i in neutral]
if global_mean_other is None:
avg = sum(confusion)/len(confusion)
else:
avg = global_mean_other
mean_norm_confusion = [i-avg for i in confusion]
max_other = []
max_ind = []
for o in other:
max_ind.append(max(enumerate(o), key=itemgetter(1))[0])
max_other.append(max(enumerate(o), key=itemgetter(1))[1])
if global_mean_other is None:
avg = sum(max_other)/len(max_other)
else:
avg = global_mean_other
mean_norm_max_other = [i-avg for i in max_other]
l = len(mean_norm_neutral)
emo = []
for i in range(l):
if mean_norm_neutral[i] > mean_norm_max_other[i]:
if mean_norm_neutral[i] > mean_norm_confusion[i]:
emo.append([time[i],'Neutral'])
else:
emo.append([time[i],'Confused'])
else:
if mean_norm_max_other[i] > mean_norm_confusion[i]:
emo.append([time[i],'Other'])
else:
emo.append([time[i],'Confused'])
return emo
def get_facet_data_combined(file, start_time, end_time, global_mean_neutral, global_mean_other):
time = []
neutral = []
other = []
i = [5,6,7,8,9,11,13,12,14]
with open(file,'r') as file:
reader = csv.reader(file, dialect='excel')
next(reader, None)
for row in reader:
if len(row) < 1:
break
if float(row[0]) > start_time/1000 and float(row[0]) < end_time/1000:
t = float(row[0])*1000
n = float(row[10])
o = [float(row[ind]) for ind in i]
time.append(t)
neutral.append(n)
other.append(o)
#mean normalize value
if global_mean_neutral is None:
avg = sum(neutral)/len(neutral)
else:
avg = global_mean_neutral
mean_norm_neutral = [i-avg for i in neutral]
max_other = []
max_ind = []
for o in other:
max_ind.append(max(enumerate(o), key=itemgetter(1))[0])
max_other.append(max(enumerate(o), key=itemgetter(1))[1])
if global_mean_other is None:
avg = sum(max_other)/len(max_other)
else:
avg = global_mean_other
mean_norm_max_other = [i-avg for i in max_other]
l = len(mean_norm_neutral)
emo = []
for i in range(l):
if mean_norm_neutral[i] > mean_norm_max_other[i]:
emo.append([time[i],'Neutral'])
else:
emo.append([time[i],'Other'])
return emo