Files
민헌andClaude Fable 5 dfb9ad6e66 초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙
- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117)
- frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시)
- eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋
- results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256)
  ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99
- docker-compose.yml + run.sh: backend+frontend 일괄 기동

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
2026-08-31 13:09:52 +09:00

64 lines
2.2 KiB
Python

"""Q-Table 모델 — 추론 전용 (학습 경로는 이 프로젝트에서 제외)."""
import numpy as np
from typing import Dict
class QTable:
"""
Q-Table은 추상적인 action_id만 다루며,
실제 협상 카드(card_id)는 ActionCardMapper에서 매핑한다.
"""
def __init__(self, state_space_size: int, action_space_size: int):
self.state_space_size = state_space_size
self.action_space_size = action_space_size
self.q_values = np.zeros((state_space_size, action_space_size))
def get_q_value(self, state_index: int, action_id: int) -> float:
self._validate_indices(state_index, action_id)
return float(self.q_values[state_index, action_id])
def get_q_values_for_state(self, state_index: int) -> np.ndarray:
self._validate_state(state_index)
return self.q_values[state_index, :].copy()
def get_best_action(self, state_index: int) -> int:
self._validate_state(state_index)
return int(np.argmax(self.q_values[state_index, :]))
def to_dict(self) -> Dict:
return {
"state_space_size": self.state_space_size,
"action_space_size": self.action_space_size,
"q_values": self.q_values.tolist(),
}
@classmethod
def from_dict(cls, data: Dict) -> "QTable":
q_table = cls(
state_space_size=data["state_space_size"],
action_space_size=data["action_space_size"],
)
q_table.q_values = np.array(data["q_values"])
return q_table
def _validate_state(self, state_index: int):
if state_index < 0 or state_index >= self.state_space_size:
raise ValueError(
f"state_index {state_index} out of range [0, {self.state_space_size})"
)
def _validate_indices(self, state_index: int, action_id: int):
self._validate_state(state_index)
if action_id < 0 or action_id >= self.action_space_size:
raise ValueError(
f"action_id {action_id} out of range [0, {self.action_space_size})"
)
def __repr__(self) -> str:
return (
f"QTable(state_space_size={self.state_space_size}, "
f"action_space_size={self.action_space_size})"
)