rorshi commited on
Commit
65ed704
·
1 Parent(s): aabeb2d

Complete 감정 회복 속도 차등화

Browse files
Files changed (2) hide show
  1. npc_social_network/npc/npc_base.py +14 -7
  2. test.ipynb +10 -7
npc_social_network/npc/npc_base.py CHANGED
@@ -138,22 +138,29 @@ class NPC:
138
  return [m.content for m in self.memory_store.get_all_memories()]
139
 
140
  # 특정 감정을 감정 상태에 반영 (카테고리 기반)
141
- def update_emotion(self, emotion: str, strength: int = 1):
142
  if emotion in self._emotion_buffer:
143
  self._emotion_buffer[emotion] += strength
 
144
 
145
  # 시간이 지남에 따라 모든 감정이 서서히 감소
146
  def decay_emotion(self):
147
- for emotion in self._emotion_buffer:
148
- rate = self.emotion_decay_rate.get(emotion, 1.0)
149
- self._emotion_buffer[emotion] = max(0.0, self._emotion_buffer[emotion] - rate)
 
 
 
150
 
151
  # 정수 기반 출력용 감정 상태 반환
152
  def get_current_emotion_state(self):
153
  display_state = {cat: {} for cat in self.emotion_state}
154
- for cat in self.emotion_state:
155
- for emo in self.emotion_state[cat]:
156
- display_state[cat][emo] = float(self._emotion_buffer[emo])
 
 
 
157
  return display_state
158
 
159
  # 현재 가장 강한 감정 반환 (전체 감정 중 최댓값 1개)
 
138
  return [m.content for m in self.memory_store.get_all_memories()]
139
 
140
  # 특정 감정을 감정 상태에 반영 (카테고리 기반)
141
+ def update_emotion(self, emotion: str, strength: float = 1.0):
142
  if emotion in self._emotion_buffer:
143
  self._emotion_buffer[emotion] += strength
144
+ self._emotion_buffer[emotion] = max(0.0, self._emotion_buffer[emotion])
145
 
146
  # 시간이 지남에 따라 모든 감정이 서서히 감소
147
  def decay_emotion(self):
148
+ for emotion_key in self._emotion_buffer:
149
+ rate = self.emotion_decay_rate.get(emotion_key, 1.0)
150
+
151
+ self._emotion_buffer[emotion_key] -= rate
152
+ if self._emotion_buffer[emotion_key] < 0:
153
+ self._emotion_buffer[emotion_key] = 0.0
154
 
155
  # 정수 기반 출력용 감정 상태 반환
156
  def get_current_emotion_state(self):
157
  display_state = {cat: {} for cat in self.emotion_state}
158
+ for cat_name, emotions_in_cat in self.emotion_state.items():
159
+ for emo_name in emotions_in_cat:
160
+ if emo_name in self._emotion_buffer:
161
+ display_state[cat_name][emo_name] = self._emotion_buffer[emo_name]
162
+ else:
163
+ display_state[cat_name][emo_name] = 0.0
164
  return display_state
165
 
166
  # 현재 가장 강한 감정 반환 (전체 감정 중 최댓값 1개)
test.ipynb CHANGED
@@ -2754,7 +2754,7 @@
2754
  },
2755
  {
2756
  "cell_type": "code",
2757
- "execution_count": null,
2758
  "id": "ac67ce84",
2759
  "metadata": {},
2760
  "outputs": [
@@ -2762,23 +2762,26 @@
2762
  "name": "stdout",
2763
  "output_type": "stream",
2764
  "text": [
 
 
 
2765
  "초기 감정 상태:\n",
2766
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n",
2767
  "\n",
2768
  "[1회 decay 후]\n",
2769
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n",
2770
  "\n",
2771
  "[2회 decay 후]\n",
2772
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n",
2773
  "\n",
2774
  "[3회 decay 후]\n",
2775
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n",
2776
  "\n",
2777
  "[4회 decay 후]\n",
2778
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n",
2779
  "\n",
2780
  "[5회 decay 후]\n",
2781
- "{'core_positive': {'joy': 0, 'satisfaction': 0, 'gratitude': 0, 'calm': 0, 'anticipation': 0, 'pride': 0, 'connectedness': 0}, 'core_negative': {'sadness': 0, 'anger': 0, 'anxiety': 0, 'disgust': 0, 'fear': 0, 'regret': 0, 'frustration': 0}, 'social_emotion': {'jealousy': 0, 'shame': 0, 'guilt': 0, 'compassion': 0, 'awe': 0, 'empathy': 0}, 'cognitive_state': {'confusion': 0, 'nervousness': 0, 'apathy': 0, 'excitement': 0, 'immersion': 0, 'skepticism': 0}}\n"
2782
  ]
2783
  }
2784
  ],
 
2754
  },
2755
  {
2756
  "cell_type": "code",
2757
+ "execution_count": 1,
2758
  "id": "ac67ce84",
2759
  "metadata": {},
2760
  "outputs": [
 
2762
  "name": "stdout",
2763
  "output_type": "stream",
2764
  "text": [
2765
+ "[DEBUG] update_emotion: Attempting to update 'anger' by 1.0.\n",
2766
+ "[DEBUG] update_emotion: Attempting to update 'fear' by 1.0.\n",
2767
+ "[DEBUG] update_emotion: Attempting to update 'pride' by 1.0.\n",
2768
  "초기 감정 상태:\n",
2769
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 1.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 1.0, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 1.0, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n",
2770
  "\n",
2771
  "[1회 decay 후]\n",
2772
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 0.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 0.5, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 0.4, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n",
2773
  "\n",
2774
  "[2회 decay 후]\n",
2775
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 0.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 0.0, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 0.0, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n",
2776
  "\n",
2777
  "[3회 decay 후]\n",
2778
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 0.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 0.0, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 0.0, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n",
2779
  "\n",
2780
  "[4회 decay 후]\n",
2781
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 0.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 0.0, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 0.0, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n",
2782
  "\n",
2783
  "[5회 decay 후]\n",
2784
+ "{'core_positive': {'joy': 0.0, 'satisfaction': 0.0, 'gratitude': 0.0, 'calm': 0.0, 'anticipation': 0.0, 'pride': 0.0, 'connectedness': 0.0}, 'core_negative': {'sadness': 0.0, 'anger': 0.0, 'anxiety': 0.0, 'disgust': 0.0, 'fear': 0.0, 'regret': 0.0, 'frustration': 0.0}, 'social_emotion': {'jealousy': 0.0, 'shame': 0.0, 'guilt': 0.0, 'compassion': 0.0, 'awe': 0.0, 'empathy': 0.0}, 'cognitive_state': {'confusion': 0.0, 'nervousness': 0.0, 'apathy': 0.0, 'excitement': 0.0, 'immersion': 0.0, 'skepticism': 0.0}}\n"
2785
  ]
2786
  }
2787
  ],