주기 실회기 검증과 G7 종료계약 보강

This commit is contained in:
Yun Chan 2026-08-09 23:37:19 +09:00
parent 83590e9ef7
commit 7b4955c3fc
23 changed files with 2916 additions and 117 deletions

View file

@ -32,7 +32,7 @@ class G7EvidenceProvenance(BaseModel):
@model_validator(mode="after")
def require_preregistered_analysis(self) -> "G7EvidenceProvenance":
if self.registered_at > self.held_out_labels_opened_at:
if self.registered_at >= self.held_out_labels_opened_at:
raise ValueError("analysis protocol must precede held-out label access")
return self
@ -62,7 +62,7 @@ class G7PowerPlan(BaseModel):
required_held_out_participants: int = Field(ge=1)
required_held_out_sessions: int = Field(ge=1)
required_paired_axis_observations: int = Field(ge=3)
alpha: float = Field(gt=0.0, le=0.05)
alpha: Literal[0.05] = 0.05
target_power: float = Field(ge=0.8, lt=1.0)
minimally_detectable_gain: float = Field(gt=0.0, le=1.0)
planned_bootstrap_samples: Literal[10000] = 10000
@ -91,10 +91,7 @@ class G7HumanAxisLabel(BaseModel):
labeler_key: str = Field(pattern=r"^[A-Za-z0-9][A-Za-z0-9._:-]{2,127}$")
score: float = Field(ge=0.0, le=1.0)
category: str | None = Field(
default=None,
pattern=r"^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$",
)
category: str = Field(pattern=r"^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$")
class G7ReliabilityClaim(BaseModel):
@ -103,11 +100,7 @@ class G7ReliabilityClaim(BaseModel):
method: Literal["ICC(A,1)"] = "ICC(A,1)"
labeler_keys: tuple[str, ...] = Field(min_length=2)
reported_icc: float = Field(ge=-1.0, le=1.0)
reported_categorical_kappa: float | None = Field(
default=None,
ge=-1.0,
le=1.0,
)
reported_categorical_kappa: float = Field(ge=-1.0, le=1.0)
report_sha256: Sha256 = Field(pattern=r"^[a-f0-9]{64}$")
@model_validator(mode="after")
@ -146,9 +139,6 @@ class G7PairedAxisObservation(BaseModel):
labeler_keys = [item.labeler_key for item in self.labels]
if len(set(labeler_keys)) != len(labeler_keys):
raise ValueError("observation labeler keys must be unique")
has_category = [item.category is not None for item in self.labels]
if any(has_category) and not all(has_category):
raise ValueError("categorical labels must be complete within an observation")
return self
@ -227,7 +217,6 @@ class G7HumanVoiceGainEvidencePack(BaseModel):
participant_by_session: dict[str, str] = {}
axes_by_session: dict[str, set[AllianceAxis]] = {}
categorical_modes: set[bool] = set()
for observation in self.observations:
if split_by_participant.get(observation.participant_key) != "held_out":
raise ValueError("evaluation observations must use held-out participants")
@ -243,16 +232,8 @@ class G7HumanVoiceGainEvidencePack(BaseModel):
row_labelers = {item.labeler_key for item in observation.labels}
if row_labelers != reliability_panel:
raise ValueError("every row must use the declared reliability panel")
categorical_modes.add(observation.labels[0].category is not None)
required_axes: set[AllianceAxis] = {"goal", "task", "bond"}
if any(axes != required_axes for axes in axes_by_session.values()):
raise ValueError("every held-out session must cover goal, task, and bond")
if len(categorical_modes) != 1:
raise ValueError("categorical labels must be all-present or all-absent")
has_categories = True in categorical_modes
if has_categories != (
self.reliability.reported_categorical_kappa is not None
):
raise ValueError("categorical labels and reported kappa must appear together")
return self