Skip to content

sense_drift: surface threshold_method (n_permutations re-thresholds, not just add a p-value)#1

Merged
jturner-uofl merged 1 commit into
mainfrom
fix/sense-drift-threshold-transparency-pr
Jun 17, 2026
Merged

sense_drift: surface threshold_method (n_permutations re-thresholds, not just add a p-value)#1
jturner-uofl merged 1 commit into
mainfrom
fix/sense-drift-threshold-transparency-pr

Conversation

@jturner-uofl

Copy link
Copy Markdown
Owner

What

Adds SenseDriftResult.threshold_method ("control_chart" | "permutation_null") so the result records which thresholding regime produced the flags.

Why

Passing n_permutations > 0 does more than attach a p-value: it switches the flag threshold from the in-sample control chart (μ + kσ) to a null-calibrated percentile of the label-shuffle distribution. Those two thresholds differ, so the same data can yield a different set of flagged periods — and therefore a different change_type / drift_terms. Previously this regime switch was silent; a caller comparing a canonical run to a permutation run had no programmatic way to see that the thresholding method itself had changed.

Changes

  • SenseDriftResult.threshold_method: str — new field recording the regime.
  • Docstrings on sense_drift and SenseDriftResult now state that n_permutations switches the thresholding method, not just the p-value.
  • 3 regression tests:
    • test_threshold_method_is_surfaced — the label is set correctly in each regime.
    • test_permutation_switches_threshold_not_just_pvalue — the two regimes use different thresholds.
    • test_permutation_mode_is_deterministic — both regimes reproduce run-to-run under a fixed random_state.

Not changed

No change to the detection math. The regime switch is deterministic (not RNG non-determinism). Backward compatible — additive field only.

pytest tests/unit/test_semantic_drift.py → 24 passed.

…not just add a p-value)

Passing n_permutations switches the flag threshold from the in-sample
control chart to a null-calibrated percentile, which can flag a different
set of periods and therefore change change_type/drift_terms — previously
this was silent. Add SenseDriftResult.threshold_method ('control_chart' |
'permutation_null'), document the behavior on sense_drift and the result
class, and add regression tests. No change to the detection math; the
switch is deterministic (not RNG non-determinism).
@jturner-uofl jturner-uofl merged commit 2ddfbdd into main Jun 17, 2026
7 of 8 checks passed
@jturner-uofl jturner-uofl deleted the fix/sense-drift-threshold-transparency-pr branch June 17, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant