def formulate_expectation(self, word): now = utilities.milliseconds(datetime.datetime.now()) activation = self.activation(word.times) retrieval_prob = self.retrieval_probability(activation, CogModule.THRESHOLD, CogModule.NOISE) retrieval_latency = self.retrieval_latency(CogModule.LATENCY, activation) self.expectation = self.get_expectation_name(retrieval_prob) status = str(retrieval_prob) + ': ' emotion = None if self.expectation == 'positive': status += 'Expecting right answer.' emotion = CogModule.EXPECT_POS[0] elif self.expectation == 'none': status += 'Expecting nothing.' elif self.expectation == 'negative': status += 'Expecting wrong answer' emotion = CogModule.EXPECT_NEG[0] else: print 'Wrong expectation value', self.expectation self.logger.log(' Formulate expectation: prob={0:.2f}% latency={1:.2f}s : ({2},{3})'.format(retrieval_prob, retrieval_latency, self.expectation, emotion)) return (status, utilities.emotion_by_name(emotion))
def update_emo_status(self, data): ''' Gets a string of emotion values received from wasabi and updates the internal emotion dictionary 1. Try: Always show dominating emotion ''' # Update emotion status: current = self.extract(data) for emo in self.emo_status.keys(): if emo in current.keys(): self.emo_status[emo] = current[emo] else: self.emo_status[emo] = 0 # Get dominating emotion: primary_emo = self.get_primary_emotion() # Check for change: if (not self.dominating_emo or (primary_emo and self.dominating_emo and primary_emo.name != self.dominating_emo.name)): #self.logger.log(' Dominating emotion changed to {}'.format(primary_emo)) self.dominating_emo = primary_emo emotion = utilities.emotion_by_name(primary_emo.name) # Send to MARC: if self.marc: if emotion.FREQUENCE <= self.count: self.count = 0 self.marc.show(emotion) else: self.count += 1
def check(self, correct, expectation): ''' Task evaluation according to the emotional reaction. Sends an emotional input to wasabi and text back to the agent correct: correctness of the given answer: true / false expecation: of the answer before answer was given: negative / none / positive ''' emotion = 'None' impulse = 0 reactions = {'negative': {1: EmoModule.REACT_NEG_RIGHT, 0: EmoModule.REACT_NEG_WRONG, 2: EmoModule.REACT_NEG_NONE}, 'none': {1: EmoModule.REACT_NONE_RIGHT, 0: EmoModule.REACT_NONE_WRONG, 2: EmoModule.REACT_NONE_NONE}, 'positive': {1:EmoModule.REACT_POS_RIGHT, 0:EmoModule.REACT_POS_WRONG, 2:EmoModule.REACT_POS_NONE}} surprise, emotion, impulse = reactions[expectation][correct] self.logger.log(' Reaction: surprise:{}, emotion={}, impulse={}'.format(surprise, emotion, impulse)) if surprise: self.trigger(Surprise()) if self.use_wasabi: if emotion != 'None': self.trigger(utilities.emotion_by_name(emotion)) if impulse != 0: print 'IMPULSE IS NEG', impulse self.impulse(impulse) else: self.show_static_emotion(utilities.emotion_by_name(emotion, impulse)) # TODO(How to wait here until first wasabi message is received?) return self.get_primary_emotion()
def get_primary_emotion(self): ''' Get dominating emotion: ''' # TODO(wait here for next received message) if self.expressing: primary_emo = '' highest_imp = 0 for emotion in self.emo_status.keys(): if math.fabs(self.emo_status[emotion]) >= math.fabs(highest_imp): primary_emo = emotion highest_imp = self.emo_status[emotion] if highest_imp == 0: primary_emotion = 'concentrated' return utilities.emotion_by_name(primary_emo, impulse = highest_imp) else: return self.static_emotion
def resolve_expectation(self, correct): ''' Cognitive reaction to correctness and times of a given word. ''' reaction = 'none' if self.expectation == 'negative': if correct == 1: reaction = CogModule.EXPECT_NEG[2] elif correct == 0 or correct == 2: reaction = CogModule.EXPECT_NEG[1] else: print 'WRONG CORRECT VALUE', correct elif self.expectation == 'positive': if correct == 1: reaction = CogModule.EXPECT_POS[1] elif correct == 0 or correct == 2: reaction = CogModule.EXPECT_POS[2] else: print 'WRONG CORRECT VALUE', correct str_answer = ['false', 'correct', 'notgiven'][correct] self.logger.log(' Reaction to expectation={} and answer={}: {}'.format(self.expectation, correct, reaction)) return utilities.emotion_by_name(reaction)