Fix isolation forest edge cases and improve input validation#8
Merged
Conversation
Member
whilo
commented
Apr 13, 2026
- Use complete binary tree sizing (2^(depth+1)-1 nodes) instead of 2n-1, fixing ArrayIndexOutOfBounds for non-power-of-2 sample sizes
- Cap sample-size to n-rows in training (matches scikit-learn behavior)
- Guard against NaN scores when sample-size=1 (cPsi=0 division)
- Switch to Fisher-Yates partial shuffle for sampling without replacement
- Add column length mismatch validation with clear error messages
- Add explicit nil-column and wrong-type error messages in prepare-features
- Add 8 edge-case tests: single-row, two-rows, sample-size capping, mismatched lengths, missing features, wrong types, NaN inputs, sampling-without-replacement correctness
- Format fixes (query/plan.clj, iforest.clj, iforest_test.clj)
- Use complete binary tree sizing (2^(depth+1)-1 nodes) instead of 2n-1, fixing ArrayIndexOutOfBounds for non-power-of-2 sample sizes - Cap sample-size to n-rows in training (matches scikit-learn behavior) - Guard against NaN scores when sample-size=1 (cPsi=0 division) - Switch to Fisher-Yates partial shuffle for sampling without replacement - Add column length mismatch validation with clear error messages - Add explicit nil-column and wrong-type error messages in prepare-features - Add 8 edge-case tests: single-row, two-rows, sample-size capping, mismatched lengths, missing features, wrong types, NaN inputs, sampling-without-replacement correctness - Format fixes (query/plan.clj, iforest.clj, iforest_test.clj)
- Rewrite resolve-anomaly-expressions to walk all query clauses (SELECT, WHERE, HAVING, ORDER BY) instead of only SELECT - Tree-walk collects unique anomaly expressions, computes each once, and rewrites references throughout the query - WHERE/HAVING use synthetic column name (pre-projection), ORDER BY uses SELECT alias when available (post-projection) - Inject 50 anomalies into --demo taxi data (high fares, zero tips) - Train and register 'taxi_anomaly' model automatically in --demo mode - Add end-to-end tests for WHERE filter, ORDER BY, and deduplication
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.