"""
Validating Claude as a judge
============================

The study reported in the case-study chapter of the book: psychometric audits
of brightness, facial expression and segmentation quality, swap and
transitivity tests, a judge-substitution comparison with simulated people,
closed-loop sessions and risk-controlled escalation — for two Claude models.
``tools/claude_validation.py`` runs all of it and writes ``results.json``; the
call below runs a smaller version (``scale=0.5``). Expected cost at full scale:
a few US dollars.
"""

# %%
# Run the study
# -------------
import json
import sys

sys.path.insert(0, "tools")
from claude_validation import run_study  # noqa: E402

from easyiec.evaluators import AnthropicClient  # noqa: E402

clients = {m: AnthropicClient(m, effort="low", min_interval=0.2) for m in ["claude-haiku-5-5", "claude-sonnet-5-5"]}
results = run_study(clients, out="claude_study", scale=0.5)
print(json.dumps(results["usage"], indent=1))          # calls, tokens and USD per model
print(results["V5"]["summary"])                          # human share of the calibrated hybrid session

# %%
# A single psychometric audit
# ---------------------------
import easyiec as ei  # noqa: E402
from easyiec.evaluators import LLMJudge  # noqa: E402
from easyiec.problems import JuliaSet  # noqa: E402
from easyiec.validation import psychometric_audit  # noqa: E402

judge = LLMJudge(clients["claude-haiku-5-5"], JuliaSet(), debias="none", image_size=160)
psy = psychometric_audit(judge, JuliaSet(), "brightness", goal="Choose the brighter image.", per_level=8)
print(psy.summary())
ei.viz.plot_psychometric(psy)
