rhscope.bench.compare

Head-to-head detector comparison.

Benchmarks give you one number per detector. Research questions usually want more than that:

  • Where do two detectors disagree?

  • When they disagree, which one is right against a ground-truth label?

  • How correlated are their scores - are they redundant or complementary?

compare_detectors() runs every detector on the same bench, builds an agreement matrix, surfaces the top disagreements, and renders a markdown report. Useful for triage (“is my probe better than the judge?”), for ensemble design (low-correlation detectors compose best), and for reproducible head-to-head numbers in a paper.

class rhscope.bench.compare.DisagreementCase(index, prompt, response, label, detector_a, detector_b, score_a, score_b, correct_a, correct_b)[source]

Bases: object

One example on which two detectors disagree about hacking.

Variables:
  • index (int) – Position in the bench.

  • prompt (str) – Prompt text.

  • response (str) – Response text (truncated to 240 chars for reports).

  • label (bool) – Ground-truth True / False hacking label.

  • detector_a (str) – Name of detector A.

  • detector_b (str) – Name of detector B.

  • score_a (float) – Score from A.

  • score_b (float) – Score from B.

  • correct_a (bool) – Whether A’s prediction matches the label.

  • correct_b (bool) – Whether B’s prediction matches the label.

Parameters:
index: int
prompt: str
response: str
label: bool
detector_a: str
detector_b: str
score_a: float
score_b: float
correct_a: bool
correct_b: bool
to_dict()[source]
Return type:

dict[str, Any]

class rhscope.bench.compare.DetectorComparison(detector_names, scores, labels, thresholds, aurocs, agreement, correlation, top_disagreements=<factory>, dataset_name='')[source]

Bases: object

Full head-to-head comparison across N detectors.

Variables:
  • detector_names (list[str]) – Ordered list of N detector names.

  • scores (numpy.ndarray) – (N, M) matrix of raw detector scores on M examples.

  • labels (numpy.ndarray) – (M,) ground-truth labels (1 = hacking).

  • thresholds (numpy.ndarray) – (N,) Youden-J optimal thresholds per detector.

  • aurocs (numpy.ndarray) – (N,) per-detector pooled AUROC.

  • agreement (numpy.ndarray) – (N, N) matrix of pairwise agreement rates at the per-detector optimal thresholds.

  • correlation (numpy.ndarray) – (N, N) Pearson correlation between raw scores.

  • top_disagreements (list[rhscope.bench.compare.DisagreementCase]) – Cases where two detectors disagreed most strongly, sorted by combined “wrongness” score.

  • dataset_name (str) – Human-readable identifier of the source bench.

Parameters:
detector_names: list[str]
scores: ndarray
labels: ndarray
thresholds: ndarray
aurocs: ndarray
agreement: ndarray
correlation: ndarray
top_disagreements: list[DisagreementCase]
dataset_name: str = ''
to_dict()[source]

JSON-serializable summary. Omits the full score matrix for size.

Return type:

dict[str, Any]

save_json(path, *, indent=2)[source]
Parameters:
Return type:

Path

summary(*, max_disagreements=5)[source]

Render a markdown head-to-head report.

Parameters:

max_disagreements (int)

Return type:

str

save_summary(path)[source]
Parameters:

path (str | Path)

Return type:

Path

rhscope.bench.compare.compare_detectors(detectors, bench, *, limit=None, max_disagreements=10)[source]

Run every detector on the same bench and build a head-to-head report.

Parameters:
  • detectors (Mapping[str, Detector]) – Named detectors to compare. Keys become display labels.

  • bench (RHDetectBench) – Source RHDetectBench. Must have at least one example of each class.

  • limit (int | None) – Optional cap on examples per detector.

  • max_disagreements (int) – Keep the top-K disagreement cases in the result.

Returns:

A DetectorComparison with scores, agreement + correlation matrices, and the most informative disagreement examples.

Return type:

DetectorComparison