rorshi commited on
Commit
7b26e52
Β·
1 Parent(s): ef82d45

Complete step 6

Browse files
npc_social_network/npc/emotion_config.py CHANGED
@@ -3,79 +3,88 @@
3
 
4
  # 고차원 감정 μƒνƒœ μ •μ˜ (GoEmotions 기반, λ³΄μ—¬μ£ΌκΈ°μš©)
5
  EMOTION_STATE_TEMPLATE = {
6
- # κΈ°λ³Έ μ •μ„œ (긍정)
7
- "core_positive":{
8
- "joy": 0, # 기쁨
9
- "satisfaction": 0, # 만쑱
10
- "gratitude": 0, # 감사
11
- "calm": 0, # ν‰μ˜¨
12
- "anticipation": 0, # κΈ°λŒ€
13
- "pride": 0, # μžλΆ€μ‹¬
14
- "connectedness": 0 # μœ λŒ€κ°
15
- },
16
- # κΈ°λ³Έ μ •μ„œ (λΆ€μ •)
17
- "core_negative": {
18
- "sadness": 0, # μŠ¬ν””
19
- "anger": 0, # λΆ„λ…Έ
20
- "anxiety": 0, # λΆˆμ•ˆ
21
- "disgust": 0, # 혐였
22
- "fear": 0, # 곡포
23
- "regret": 0, # ν›„νšŒ
24
- "frustration": 0 # 쒌절
25
- },
26
- # μ‚¬νšŒμ  감정
27
- "social_emotion": {
28
- "jealousy": 0, # 질투
29
- "shame": 0, # μˆ˜μΉ˜μ‹¬
30
- "guilt": 0, # 죄책감
31
- "compassion": 0, # 동정심
32
- "awe": 0, # 경외심
33
- "empathy": 0 # 곡감
34
- },
35
- # 인지적 μƒνƒœ
36
- "cognitive_state": {
37
- "confusion": 0, # ν˜Όλž€
38
- "nervousness": 0, # κΈ΄μž₯
39
- "apathy": 0, # 무관심
40
- "excitement": 0, # ν₯λΆ„
41
- "immersion": 0, # λͺ°μž…
42
- "skepticism": 0 # 회의
43
- }
44
- }
45
 
46
  # 감정별 회볡 속도 (ms λ‹¨μœ„κ°€ μ•„λ‹Œ λ‹¨μœ„λ‹Ή κ°μ†Œ 속도)
47
  EMOTION_DECAY_RATE = {
48
- # κΈ°λ³Έ μ •μ„œ (긍정)
49
- "joy": 1, # 기쁨
50
- "satisfaction": 1, # 만쑱
51
- "gratitude": 1, # 감사
52
- "calm": 1, # ν‰μ˜¨
53
- "anticipation": 1, # κΈ°λŒ€
54
- "pride": 1, # μžλΆ€μ‹¬
55
- "connectedness": 1, # μœ λŒ€κ°
56
 
57
- # κΈ°λ³Έ μ •μ„œ (λΆ€μ •) - 느림
58
- "sadness": 0.2, # μŠ¬ν””
59
- "anger": 0.5, # λΆ„λ…Έ
60
- "anxiety": 0.4, # λΆˆμ•ˆ
61
- "disgust": 0.8, # 혐였
62
- "fear": 0.6, # 곡포
63
- "regret": 0.3, # ν›„νšŒ
64
- "frustration": 0.5, # 쒌절
65
 
66
- # μ‚¬νšŒμ  감정
67
- "jealousy": 0.4, # 질투
68
- "shame": 0.4, # μˆ˜μΉ˜μ‹¬
69
- "guilt": 0.4, # 죄책감
70
- "compassion": 1, # 동정심
71
- "awe": 1, # 경외심
72
- "empathy": 1, # 곡감
73
 
74
- # 인지적 μƒνƒœ
75
- "confusion": 0.8, # ν˜Όλž€
76
- "nervousness": 0.7, # κΈ΄μž₯
77
- "apathy": 0.4, # 무관심
78
- "excitement": 1.2, # ν₯λΆ„
79
- "immersion": 1.0, # λͺ°μž…
80
- "skepticism": 0.5, # 회의
81
- }
 
 
 
 
 
 
 
 
 
 
3
 
4
  # 고차원 감정 μƒνƒœ μ •μ˜ (GoEmotions 기반, λ³΄μ—¬μ£ΌκΈ°μš©)
5
  EMOTION_STATE_TEMPLATE = {
6
+ # κΈ°λ³Έ μ •μ„œ (긍정)
7
+ "core_positive":{
8
+ "joy": 0, # 기쁨
9
+ "satisfaction": 0, # 만쑱
10
+ "gratitude": 0, # 감사
11
+ "calm": 0, # ν‰μ˜¨
12
+ "anticipation": 0, # κΈ°λŒ€
13
+ "pride": 0, # μžλΆ€μ‹¬
14
+ "connectedness": 0 # μœ λŒ€κ°
15
+ },
16
+ # κΈ°λ³Έ μ •μ„œ (λΆ€μ •)
17
+ "core_negative": {
18
+ "sadness": 0, # μŠ¬ν””
19
+ "anger": 0, # λΆ„λ…Έ
20
+ "anxiety": 0, # λΆˆμ•ˆ
21
+ "disgust": 0, # 혐였
22
+ "fear": 0, # 곡포
23
+ "regret": 0, # ν›„νšŒ
24
+ "frustration": 0 # 쒌절
25
+ },
26
+ # μ‚¬νšŒμ  감정
27
+ "social_emotion": {
28
+ "jealousy": 0, # 질투
29
+ "shame": 0, # μˆ˜μΉ˜μ‹¬
30
+ "guilt": 0, # 죄책감
31
+ "compassion": 0, # 동정심
32
+ "awe": 0, # 경외심
33
+ "empathy": 0 # 곡감
34
+ },
35
+ # 인지적 μƒνƒœ
36
+ "cognitive_state": {
37
+ "confusion": 0, # ν˜Όλž€
38
+ "nervousness": 0, # κΈ΄μž₯
39
+ "apathy": 0, # 무관심
40
+ "excitement": 0, # ν₯λΆ„
41
+ "immersion": 0, # λͺ°μž…
42
+ "skepticism": 0 # 회의
43
+ }
44
+ }
45
 
46
  # 감정별 회볡 속도 (ms λ‹¨μœ„κ°€ μ•„λ‹Œ λ‹¨μœ„λ‹Ή κ°μ†Œ 속도)
47
  EMOTION_DECAY_RATE = {
48
+ # κΈ°λ³Έ μ •μ„œ (긍정)
49
+ "joy": 1, # 기쁨
50
+ "satisfaction": 1, # 만쑱
51
+ "gratitude": 1, # 감사
52
+ "calm": 1, # ν‰μ˜¨
53
+ "anticipation": 1, # κΈ°λŒ€
54
+ "pride": 1, # μžλΆ€μ‹¬
55
+ "connectedness": 1, # μœ λŒ€κ°
56
 
57
+ # κΈ°λ³Έ μ •μ„œ (λΆ€μ •) - 느림
58
+ "sadness": 0.2, # μŠ¬ν””
59
+ "anger": 0.5, # λΆ„λ…Έ
60
+ "anxiety": 0.4, # λΆˆμ•ˆ
61
+ "disgust": 0.8, # 혐였
62
+ "fear": 0.6, # 곡포
63
+ "regret": 0.3, # ν›„νšŒ
64
+ "frustration": 0.5, # 쒌절
65
 
66
+ # μ‚¬νšŒμ  감정
67
+ "jealousy": 0.4, # 질투
68
+ "shame": 0.4, # μˆ˜μΉ˜μ‹¬
69
+ "guilt": 0.4, # 죄책감
70
+ "compassion": 1, # 동정심
71
+ "awe": 1, # 경외심
72
+ "empathy": 1, # 곡감
73
 
74
+ # 인지적 μƒνƒœ
75
+ "confusion": 0.8, # ν˜Όλž€
76
+ "nervousness": 0.7, # κΈ΄μž₯
77
+ "apathy": 0.4, # 무관심
78
+ "excitement": 1.2, # ν₯λΆ„
79
+ "immersion": 1.0, # λͺ°μž…
80
+ "skepticism": 0.5, # 회의
81
+ }
82
+
83
+ # κ°œμ„± ν…œν”Œλ¦Ώ(0~1 λ²”μœ„)
84
+ PERSONALITY_TEMPLATE = {
85
+ "sensitive" : 0.8, # 감정 λ°˜μ‘ 강도 증가
86
+ "stoic": 0.2, # 감정 λ°˜μ‘ λ‘”ν™”
87
+ "positive_bias": 0.6, # 긍정 감정에 민감
88
+ "negative_bias": 0.4, # λΆ€μ • 감정에 민감
89
+ "sociality" : 0.5, # μ‚¬νšŒμ  감정 민감
90
+ }
npc_social_network/npc/npc_base.py CHANGED
@@ -2,7 +2,7 @@
2
  from .npc_memory import Memory, MemoryStore
3
  from .npc_emotion import EmotionManager
4
  from .npc_behavior import BehaviorManager
5
- from .emotion_config import EMOTION_STATE_TEMPLATE, EMOTION_DECAY_RATE
6
 
7
  # NPC 클래슀 μ •μ˜
8
  class NPC:
@@ -10,23 +10,25 @@ class NPC:
10
  NPC 클래슀
11
  NPC에 λŒ€ν•œ κΈ°λ³Έ 정보λ₯Ό 객체화
12
  """
13
- def __init__(self, name, job, path, image):
14
  self.name = name
15
  self.job = job
16
  self.path = path
17
  self.image = image
18
  self.current_index = 0
 
19
 
20
  # npc κΈ°μ–΅
21
  self.memory_store = MemoryStore()
22
- # 감정 μƒνƒœ 및 감정 κ΄€λ¦¬μž μ΄ˆκΈ°ν™”
23
  self.emotion_state = EMOTION_STATE_TEMPLATE
24
  self.emotion_decay_rate = EMOTION_DECAY_RATE
25
- self.emotion = EmotionManager(self.emotion_state, self.emotion_decay_rate)
 
 
26
 
27
  # 행동 κ΄€λ¦¬μž
28
  self.behavior = BehaviorManager()
29
-
30
  # λ‚΄λΆ€: float 감정 수치 κ΄€λ¦¬μš© 버퍼
31
  self._emotion_buffer = self.emotion.get_buffer()
32
 
 
2
  from .npc_memory import Memory, MemoryStore
3
  from .npc_emotion import EmotionManager
4
  from .npc_behavior import BehaviorManager
5
+ from .emotion_config import EMOTION_STATE_TEMPLATE, EMOTION_DECAY_RATE, PERSONALITY_TEMPLATE
6
 
7
  # NPC 클래슀 μ •μ˜
8
  class NPC:
 
10
  NPC 클래슀
11
  NPC에 λŒ€ν•œ κΈ°λ³Έ 정보λ₯Ό 객체화
12
  """
13
+ def __init__(self, name, job, path, image, personality=None):
14
  self.name = name
15
  self.job = job
16
  self.path = path
17
  self.image = image
18
  self.current_index = 0
19
+ self.personality = personality or {}
20
 
21
  # npc κΈ°μ–΅
22
  self.memory_store = MemoryStore()
23
+ # 감정 μƒνƒœ λ“± 감정 κ΄€λ¦¬μž μ΄ˆκΈ°ν™”
24
  self.emotion_state = EMOTION_STATE_TEMPLATE
25
  self.emotion_decay_rate = EMOTION_DECAY_RATE
26
+ self.personality = personality or PERSONALITY_TEMPLATE
27
+
28
+ self.emotion = EmotionManager(self.emotion_state, self.emotion_decay_rate, self.personality)
29
 
30
  # 행동 κ΄€λ¦¬μž
31
  self.behavior = BehaviorManager()
 
32
  # λ‚΄λΆ€: float 감정 수치 κ΄€λ¦¬μš© 버퍼
33
  self._emotion_buffer = self.emotion.get_buffer()
34
 
npc_social_network/npc/npc_emotion.py CHANGED
@@ -1,29 +1,49 @@
1
  # 감정 μƒνƒœ, 감정 μ—…λ°μ΄νŠΈ, decay 처리
2
  # portfolio/npc_social_network/npc/npc_emotion.py
 
3
 
4
  class EmotionManager:
5
- def __init__(self, emotion_state, decay_rate):
6
  # 고차원 감정 μƒνƒœ (GoEmotions 기반)
7
  self.emotion_state = emotion_state
8
  # 감정별 회볡 속도 (ms λ‹¨μœ„κ°€ μ•„λ‹Œ λ‹¨μœ„λ‹Ή κ°μ†Œ 속도)
9
  self.decay_rate = decay_rate
10
  # λ‚΄λΆ€: float 감정 수치 κ΄€λ¦¬μš© 버퍼
11
- self._emotion_buffer = {emo: 0.0 for cat in emotion_state for emo in emotion_state[cat]}
12
- for cat in emotion_state:
13
- for emo in emotion_state[cat]:
14
- self._emotion_buffer[emo] = float(emotion_state[cat][emo])
15
 
16
  # νŠΉμ • 감정을 감정 μƒνƒœμ— 반영 (μΉ΄ν…Œκ³ λ¦¬ 기반)
17
  def update_emotion(self, emotion: str, strength: float = 1.0):
18
- if emotion in self._emotion_buffer:
19
- self._emotion_buffer[emotion] += strength
20
- self._emotion_buffer[emotion] = max(0.0, self._emotion_buffer[emotion]) # μ΅œμ†Œκ°’μ„ 0으둜 κ³ μ •
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # μ‹œκ°„μ΄ 지남에 따라 λͺ¨λ“  감정이 μ„œμ„œνžˆ κ°μ†Œ
23
  def decay_emotion(self):
24
- for emo in self._emotion_buffer:
25
- rate = self.decay_rate.get(emo, 1.0)
26
- self._emotion_buffer[emo] = max(0.0, self._emotion_buffer[emo] - rate) # μ΅œμ†Œκ°’μ„ 0으둜 κ³ μ •
 
 
 
 
 
27
 
28
  # μ •μˆ˜ 기반 좜λ ₯용 감정 μƒνƒœ λ°˜ν™˜
29
  def get_state(self):
@@ -31,7 +51,9 @@ class EmotionManager:
31
 
32
  # ν˜„μž¬ κ°€μž₯ κ°•ν•œ 감정 λ°˜ν™˜ (전체 감정 쀑 μ΅œλŒ“κ°’ 1개)
33
  def get_dominant_emotion(self):
34
- return max(self._emotion_buffer.items(), key=lambda x: x[1], default=(None, 0.0))[0]
 
 
35
 
36
  def get_buffer(self):
37
  return self._emotion_buffer.copy()
 
1
  # 감정 μƒνƒœ, 감정 μ—…λ°μ΄νŠΈ, decay 처리
2
  # portfolio/npc_social_network/npc/npc_emotion.py
3
+ from .emotion_config import EMOTION_DECAY_RATE
4
 
5
  class EmotionManager:
6
+ def __init__(self, emotion_state, decay_rate, personality = None):
7
  # 고차원 감정 μƒνƒœ (GoEmotions 기반)
8
  self.emotion_state = emotion_state
9
  # 감정별 회볡 속도 (ms λ‹¨μœ„κ°€ μ•„λ‹Œ λ‹¨μœ„λ‹Ή κ°μ†Œ 속도)
10
  self.decay_rate = decay_rate
11
  # λ‚΄λΆ€: float 감정 수치 κ΄€λ¦¬μš© 버퍼
12
+ self._emotion_buffer = {emo: 0.0 for cat in emotion_state.values() for emo in cat}
13
+ self.personality = personality or {}
 
 
14
 
15
  # νŠΉμ • 감정을 감정 μƒνƒœμ— 반영 (μΉ΄ν…Œκ³ λ¦¬ 기반)
16
  def update_emotion(self, emotion: str, strength: float = 1.0):
17
+ if emotion not in self._emotion_buffer:
18
+ print(f"[κ²½κ³ ] '{emotion}'은(λŠ”) μ •μ˜λœ 감정이 μ•„λ‹™λ‹ˆλ‹€.")
19
+ return
20
+
21
+ # κ°œμ„± κ³„μˆ˜ 반영
22
+ multiplier = 1.0
23
+ if emotion in ["joy", "gratitude", "pride"]:
24
+ multiplier *= self.personality.get("positive_bias", 1)
25
+ elif emotion in ["anger", "fear", "regret"]:
26
+ multiplier *= self.personality.get("negative_bias", 1)
27
+
28
+ multiplier *= self.personality.get("sensitive", 1)
29
+
30
+ self._emotion_buffer[emotion] += strength * multiplier
31
+ for category in self.emotion_state:
32
+ if emotion in self.emotion_state[category]:
33
+ self.emotion_state[category][emotion] = int(self._emotion_buffer[emotion])
34
+ break
35
+
36
 
37
  # μ‹œκ°„μ΄ 지남에 따라 λͺ¨λ“  감정이 μ„œμ„œνžˆ κ°μ†Œ
38
  def decay_emotion(self):
39
+ for emotion, value in self._emotion_buffer.items():
40
+ rate = self.decay_rate.get(emotion, 0.5)
41
+ modifier = 1.0 - self.personality.get("stoic", 0)
42
+ self._emotion_buffer[emotion] = max(0.0, value - rate * modifier)
43
+
44
+ for category in self.emotion_state:
45
+ for emotion in self.emotion_state[category]:
46
+ self.emotion_state[category][emotion] = int(self._emotion_buffer[emotion])
47
 
48
  # μ •μˆ˜ 기반 좜λ ₯용 감정 μƒνƒœ λ°˜ν™˜
49
  def get_state(self):
 
51
 
52
  # ν˜„μž¬ κ°€μž₯ κ°•ν•œ 감정 λ°˜ν™˜ (전체 감정 쀑 μ΅œλŒ“κ°’ 1개)
53
  def get_dominant_emotion(self):
54
+ if not self._emotion_buffer:
55
+ return "neutral"
56
+ return max(self._emotion_buffer.items(), key=lambda x: x[1])[0]
57
 
58
  def get_buffer(self):
59
  return self._emotion_buffer.copy()
test.ipynb CHANGED
@@ -2822,7 +2822,7 @@
2822
  },
2823
  {
2824
  "cell_type": "code",
2825
- "execution_count": 5,
2826
  "id": "cc6f2948",
2827
  "metadata": {},
2828
  "outputs": [
@@ -2830,13 +2830,24 @@
2830
  "name": "stdout",
2831
  "output_type": "stream",
2832
  "text": [
2833
- "d:\\private\\Portfolio\\npc_social_network\\npc\\npc_base.py\n"
2834
  ]
2835
  }
2836
  ],
2837
  "source": [
2838
- "import npc_social_network.npc.npc_base as base\n",
2839
- "print(base.__file__)"
 
 
 
 
 
 
 
 
 
 
 
2840
  ]
2841
  }
2842
  ],
 
2822
  },
2823
  {
2824
  "cell_type": "code",
2825
+ "execution_count": 1,
2826
  "id": "cc6f2948",
2827
  "metadata": {},
2828
  "outputs": [
 
2830
  "name": "stdout",
2831
  "output_type": "stream",
2832
  "text": [
2833
+ "감정 평균 강도: 0.96 / λŒ€ν‘œ 감정: fear(0.96)\n"
2834
  ]
2835
  }
2836
  ],
2837
  "source": [
2838
+ "from npc_social_network.npc.npc_base import NPC\n",
2839
+ "\n",
2840
+ "# λ―Όκ°ν•˜κ³  뢀정에 μ·¨μ•½ν•œ 캐릭터\n",
2841
+ "custom_personality = {\n",
2842
+ " \"sensitive\": 1.0,\n",
2843
+ " \"negative_bias\": 1.5,\n",
2844
+ " \"stoic\": 0.1\n",
2845
+ "}\n",
2846
+ "\n",
2847
+ "npc = NPC(\"μ•„λ¦°\", \"farmer\", [(0, 0)], None, personality=custom_personality)\n",
2848
+ "npc.remember(\"λ¬΄μ„œμš΄ μ†Œλ¦¬λ₯Ό λ“€μŒ\", emotion=\"fear\", importance=5)\n",
2849
+ "npc.decay_emotion()\n",
2850
+ "print(npc.summarize_emotional_state())"
2851
  ]
2852
  }
2853
  ],