Repository navigation
Count unparsed lines in their own slots in SCVS and ECVC - #448
Open
viktorbeck98 wants to merge 1 commit into
Open
viktorbeck98 wants to merge 1 commit into
viktorbeck98 wants to merge 1 commit into
Conversation
count_events indexed its list with the eventID, so a line without a template (eventID -1) landed in the last slot built so far through negative indexing, and a line without a message (-2) could raise IndexError. ECVC also counted at detection with events_vec, which put -1 into another column than training did, so ECVC alerted on windows SCVS had learned. count_events now uses slot 0 for -2, slot 1 for -1 and slot e+2 for event e, and raises ValueError below -2. ECVCOp.events_vec counts with count_events and pads to the matrix width, so every ECVC alert is an SCVS alert on the same windows and training data. Count vectors saved by an earlier version use the old layout: retrain after upgrading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ipmach
approved these changes
Nov 24, 2026
This branch has not been deployed
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.
Task
Follow-up to #439 (CountVectorDetector, SCVS). SCVS and ECVC counted unparsed lines into another event's slot, and into different slots from each other.
Description
count_eventsindexed its list with the eventID, so a line without a template (eventID -1) went through Python's negative indexing into the last slot built so far: the highest eventID seen earlier in the window, or event 0 when -1 came first. The result depended on the order of the lines. A line without a message field (eventID -2,NO_MESSAGE_EVENT_IDin the JSON parser) raisedIndexErrorwhen no event above 0 preceded it in the window.ECVC learned its vectors with
count_eventsbut counted at detection withevents_vec, which put -1 into the last column of the learned matrix. So a window ECVC learned in training could look new at detection, and ECVC alerted on windows SCVS had learned.This PR:
count_eventsgives each unparsed ID its own slot: slot 0 counts eventID -2, slot 1 eventID -1, slot e + 2 eventID e. An ID below -2 raisesValueErrorinstead of folding silently.ECVCOp.events_veccounts withcount_eventsand pads to the matrix width, so ECVC counts a window at detection exactly as in training. Every ECVC alert is now an SCVS alert on the same windows and training data.Effect on data without unparsed lines: none. SCVS's keys stay consistent with each other. ECVC's vectors gain two leading zero columns, which leaves every distance, the sort order of the learned vectors, the validation split and the threshold unchanged.
Compatibility: count vectors saved by an earlier version use the old layout, without the two leading slots. Restored SCVS/ECVC state then matches no window counted with this version, so retrain after upgrading.
test_pre_tracker_state.pypins this: the old ECVC fixture restores to the fresh count vectors without their two leading slots, with the same threshold.Evidence: on BGL (time split, train fraction 0.1, window 10), 107,828 test windows were flagged by ECVC but not by SCVS, every one of them holding at least one eventID -1 line; at the other train fractions the same held. On datasets without unparsed lines the two detectors' alerts already nested. With this change, at train fraction 0.1, all 28,292 distinct test windows that SCVS learned are also learned by ECVC, so no ECVC-only alert remains.
How Has This Been Tested?
tests/test_utils/test_sequence_encoding.py::TestCountEvents: slot layout, an unparsed line is not another event, order independence,ValueErrorbelow -2.tests/test_detectors/test_ecvc_detector.py::TestUnparsedLines: ECVC and SCVS never alert on a learned window that holds -1 or -2 lines;[3, -1]is not[3, 3]; on random streams with -1 (and with -2) every ECVC alert is an SCVS alert, for threshold methodsmeananddefault(equal alert sets fordefault).test_build_one_vec_counts_like_count_events.count_events/build_count_vec/build_one_vectests updated to the new layout.test_ecvc_rebuilds_the_same_count_vectorsbecametest_ecvc_rebuilds_the_old_count_vectors(see Compatibility).uv run pytest -q --run-ignored: 1124 passed, 45 skipped, 0 failed.prek run --files <changed files>: all hooks pass.Checklist
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.