Repository navigation
fix(analysis): grade CSR/PB confidence on periodicity strength - #410
Merged
Merged
Conversation
_find_dominant_cycle only searches lags inside the cycle range, so the cycle-range confidence bonus was always earned: CSR confidence never fell below 0.7 and periodic breathing never below 0.6. Replace it with the autocorrelation peak's strength above the detection gate. Stored confidences change, so a new pattern_detector identity key and a format_version bump to 5 mark existing analysis rows stale.
The biased autocorrelation peaks near (N - lag) / N even for a perfect cycle, so the periodicity grade favoured short cycles; rescale the peak before grading (detection gating still uses the raw autocorrelation). The periodic-breathing detector's use of the grade had no test, and the pattern detector still described clustering it never did.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSR and periodic-breathing confidence had a fixed floor.
_find_dominant_cycleonly searches autocorrelation lags inside the cycle range, so the "cycle length in range" bonus in_calculate_csr_confidence(+0.2) and_calculate_periodic_confidence(+0.1) was earned on every detection. CSR confidence never fell below 0.7 and periodic breathing never below 0.6, so that part of the score carried no information.The bonus is replaced with a graded periodicity term,
_periodicity_strength. It measures how far the autocorrelation peak that picked the dominant cycle clears the detection gate (autocorr_threshold), scaled to 0–1 and weighted 0.2 for CSR and 0.1 for periodic breathing on a 0.5 base. Two details:(N - lag) / N, and long cycles would grade weaker than short ones._find_dominant_cyclereturns the peak rescaled byN / (N - lag)for grading. Detection still gates on the raw autocorrelation, so which windows are detected doesn't change.0.5 + weight * periodicity_strength + bonus * earned, clipped to 1.0, so all bonuses earned gives exactly 1.0. A non-finite strength grades as 0.Gating, cycle lengths, episode boundaries and merging are unchanged, so only
confidencevalues move, and none go up.periodic_breathing_pctis computed from episode durations and doesn't change. On seeded synthetic waxing/waning signals, compared withmain:csr_detectioncsr_episodesperiodic_breathingperiodic_breathing_episodesOn the recorded fixtures (all three detection modes), the full
AnalysisResultis identical tomain; none of those sessions produces a CSR or periodic-breathing detection.Also in
pattern_detector.pyandconstants.py, in the spirit of #354: the module and class docstrings no longer claim clustering or positional-event detection, the class example checks forNone, and the unusedCLUSTER_THRESHOLD_SECONDS,MIN_EVENTS_FOR_POSITIONALandMIN_CLUSTER_SIZEconstants are removed.Release note: stored confidences change, so
AlgorithmIdentitygains apattern_detectorkey (PATTERN_DETECTOR_ALGO_VERSION = "v1") andformat_versiongoes from 4 to 5. This marks every stored analysisSTALE_VERSION. After deploy, re-run analysis per profile withsnore analysis run --from 2000-01-01 --user <email> --profile <name>.pattern_detectoris not inCROSS_VERSION_REFUSAL_KEYS, because CSR/PB confidence feeds no cross-epoch distribution.Closes #354