⚡ Bolt: Optimize KNN classification with select_nth_unstable_by and squared distance#145
⚡ Bolt: Optimize KNN classification with select_nth_unstable_by and squared distance#145teerthsharma wants to merge 1 commit into
Conversation
…quared distance Co-authored-by: teerthsharma <78080953+teerthsharma@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Optimized the$O(k \cdot N)$ bubble sort with Rust's $O(N)$ average time to find the $k$ nearest neighbors. Also replaced exact Euclidean distance computations using $k$ values. Eliminating $O(N)$ selection greatly reduces computational overhead.$O(k \cdot N)$ to $O(N)$ and eliminates the
KNNClassifier::predictmethod by replacing the manualselect_nth_unstable_by, which operates inlibm::sqrtwith squared distance comparisons to avoid the expensive square root operation in the hot loop.🎯 Why: In high-performance ML routines, finding the nearest neighbors can become a significant bottleneck, especially for large datasets or high
sqrtand using📊 Impact: Reduces prediction time complexity from
libm::sqrtoverhead in the distance calculation loop.🔬 Measurement: Verify the behavior via
cargo test --offline classificationinside thecrates/aether-coredirectory to ensure existing perceptron and logistic regression logic works, and ensureselect_nth_unstable_byreturns correct nearest neighbors.PR created automatically by Jules for task 11381027091103256586 started by @teerthsharma