-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaffective_appraisal.py
247 lines (178 loc) · 7.43 KB
/
affective_appraisal.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
class Appraisal:
def __init__(self):
self.arousal = 0 # Level of being awake
self.valence = 0 # Level of being attracted
self.stance = 0 # Level of being open for interaction
# Range for arousal, valence and stance
self.max = 1
self.min = -1
# Initial emotion
self.emotion = "Neutral"
def __repr__(self):
return "Arousal: {0} \nValence: {1} \nStance: {2} \nEmotion: {3}".format(self.arousal,
self.valence,
self.stance,
self.emotion)
def set_min_max(self):
if self.arousal < self.min:
self.arousal = self.min
elif self.arousal > self.max:
self.arousal = self.max
if self.valence < self.min:
self.valence = self.min
elif self.valence > self.max:
self.valence = self.max
if self.stance < self.min:
self.stance = self.min
elif self.stance > self.max:
self.stance = self.max
def update(self, emotions):
AVS = [0, 0, 0]
for key, value in emotions.items():
if key == "angry":
AVS[0] += value
AVS[1] -= value
AVS[2] -= value
elif key == "disgust":
AVS[0] -= value
AVS[1] -= value
AVS[2] -= value
elif key == "fear":
AVS[0] += value
AVS[1] -= value
AVS[2] += value
elif key == "happy":
AVS[0] += value
AVS[1] += value
AVS[2] += value
elif key == "sad":
AVS[0] -= value
AVS[1] -= value
AVS[2] += value
elif key == "surprise":
AVS[0] += value
AVS[1] += value
#AVS[2] -= value
elif key == "neutral":
AVS[0] -= value
AVS[1] += value
AVS[2] -= value
else:
pass
self.arousal += AVS[0]
self.valence += AVS[1]
self.stance += AVS[2]
Appraisal.set_min_max(self)
#Appraisal.generate_emotion(self)
def generate_emotion(self):
if (self.arousal <= 0.5 and self.arousal >= -0.5) and (self.valence <= 0.5 and self.valence >= -0.5) and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Neutral"
elif self.arousal > 0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Surprise"
elif self.arousal < -0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Tired"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence > 0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Happy"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence < -0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Sad"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance > 0.5:
self.emotion = "Attentive"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance < -0.5:
self.emotion = "Stern"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence < -0.5 and self.stance > 0.5:
self.emotion = "Fear"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence < -0.5 and self.stance < -0.5:
self.emotion = "Anger"
elif self.arousal < -0.5 and self.valence < -0.5 and self.stance < -0.5:
self.emotion = "Disgust"
elif self.arousal < -0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance < -0.5:
self.emotion = "Stern"
elif self.arousal < -0.5 and self.valence > 0.5 and self.stance < -0.5:
self.emotion = "Neutral"
elif self.arousal < -0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance > 0.5:
self.emotion = "Neutral"
elif self.arousal > 0.5 and self.valence > 0.5 and self.stance > 0.5:
self.emotion = "Happy"
elif self.arousal > 0.5 and self.valence < -0.5 and self.stance < -0.5:
self.emotion = "Fear"
elif self.arousal > 0.5 and self.valence < -0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Stern"
elif self.arousal > 0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance < -0.5:
self.emotion = "Attentive"
elif self.arousal < -0.5 and self.valence > 0.5 and self.stance > 0.5:
self.emotion = "Attentive"
elif self.arousal < -0.5 and self.valence > 0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Neutral"
elif self.arousal < -0.5 and self.valence > 0.5 and self.stance < -0.5:
self.emotion = "Tired"
elif self.arousal > 0.5 and self.valence < -0.5 and self.stance > 0.5:
self.emotion = "Attentive"
elif self.arousal > 0.5 and (self.valence <= 0.5 and self.valence >= -0.5) and self.stance > 0.5:
self.emotion = "Sad"
elif self.arousal > 0.5 and self.valence > 0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Attentive"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence > 0.5 and self.stance > 0.5:
self.emotion = "Surprise"
elif self.arousal < -0.5 and self.valence < -0.5 and (self.stance <= 0.5 and self.stance >= -0.5):
self.emotion = "Stern"
elif self.arousal < -0.5 and self.valence < -0.5 and self.stance > 0.5:
self.emotion = "Sad"
elif (self.arousal <= 0.5 and self.arousal >= -0.5) and self.valence > 0.5 and self.stance < -0.5:
self.emotion = "Attentive"
elif self.arousal > 0.5 and self.valence > 0.5 and self.stance < -0.5:
self.emotion = "Surprise"
else:
self.emotion = "Other"
return self.emotion
class Behaviour:
def __init__(self):
#self.regimes = regimes #dict
#self.emotion = emotion #string
#self.objects = objects #dict
self.behaviour = """Search for social interaction."""
self.attention = "person"
def __repr__(self):
return "Behaviour: {0} \nAttention: {1}".format(self.behaviour, self.attention)
def generate_behaviour(self, regimes):
if regimes["Fatigue"] == "Overwhelmed":
self.behaviour = """Avoid stimulis and social interaction, need to rest."""
self.attention = None
elif regimes["Fatigue"] == "Homeostatic" or regimes["Fatigue"] == "Under-stimulated":
if regimes["Social"] == "Overwhelmed":
if regimes["Stimuli"] == "Homeostatic" or regimes["Stimuli"] == "Under-stimulated":
self.behaviour = """Avoid social interaction, search for stimuli to show interest."""
self.attention = "object"
elif regimes["Stimuli"] == "Overwhelmed":
self.behaviour = """Avoid social interaction and stimuli, do sommething."""
self.attention = None
elif regimes["Social"] == "Homeostatic":
if regimes["Stimuli"] == "Homeostatic" or regimes["Stimuli"] == "Overwhelmed":
self.behaviour = """Avoid stimuli, search for social interaction."""
self.attention = "person"
elif regimes["Stimuli"] == "Under-stimulated":
self.behaviour = """Search for stimuli."""
self.attention = self.objects.object
elif regimes["Social"] == "Under-stimulated":
self.behaviour = """Search for social interaction."""
self.attention = "person"
# if self.regimes["Fatigue"] == "Under-stimulated":
# pass
if self.attention is None:
self.activations = {
"Social": -1,
"Stimuli": -1,
"Fatigue": -1
}
elif self.attention == "person":
self.activations = {
"Social": -1,
"Stimuli": 1,
"Fatigue": 1
}
else:
self.activations = {
"Social": 1,
"Stimuli": -1,
"Fatigue": 1
}
return self.activations, self.attention