{"record":{"id":"8e4b66f734abaefa","repo":"rohitg00/ai-engineering-from-scratch","slug":"candidate-and-baseline-lengths-disagree","errorCode":null,"errorMessage":"candidate and baseline lengths disagree","messagePattern":"candidate and baseline lengths disagree","errorType":"exception","errorClass":"PairingError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/53-result-evaluator/code/main.py","lineNumber":156,"sourceCode":"    bt = math.exp(log_bt)\n    if x < (a + 1.0) / (a + b + 2.0):\n        return bt * _lentz_betacf(a, b, x) / a\n    return 1.0 - bt * _lentz_betacf(b, a, 1.0 - x) / b\n\n\ndef two_sided_t_p_value(t_stat: float, df: int) -> float:\n    \"\"\"Two sided p value for a t statistic with df degrees of freedom.\"\"\"\n    if df <= 0:\n        return 1.0\n    x = df / (df + t_stat * t_stat)\n    p = regularised_incomplete_beta(df / 2.0, 0.5, x)\n    return max(0.0, min(1.0, p))\n\n\ndef paired_t_test(candidate: list[float], baseline: list[float]) -> tuple[float, float | None, int]:\n    \"\"\"Return (mean_diff, p_value, n). p_value is None when n < 2.\"\"\"\n    if len(candidate) != len(baseline):\n        raise PairingError(\"candidate and baseline lengths disagree\")\n    n = len(candidate)\n    if n < 2:\n        if n == 0:\n            return 0.0, None, 0\n        return float(candidate[0] - baseline[0]), None, n\n    diffs = np.array(candidate) - np.array(baseline)\n    mean_diff = float(diffs.mean())\n    var_diff = float(diffs.var(ddof=1))\n    if var_diff == 0.0:\n        return mean_diff, (0.0 if mean_diff != 0.0 else 1.0), n\n    t_stat = mean_diff / math.sqrt(var_diff / n)\n    p = two_sided_t_p_value(t_stat, n - 1)\n    return mean_diff, p, n\n\n\ndef _pair_by_seed(\n    candidates: list[ExperimentResultLike],\n    baselines: list[ExperimentResultLike],","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/53-result-evaluator/code/main.py#L138-L174","documentation":"Error \"candidate and baseline lengths disagree\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/53-result-evaluator/code/main.py:156 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}