Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect outliers using LOF #904

Merged
merged 1 commit into from
Sep 18, 2022
Merged

Detect outliers using LOF #904

merged 1 commit into from
Sep 18, 2022

Conversation

urschrei
Copy link
Member

@urschrei urschrei commented Sep 10, 2022

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

Still draft due to:

  • perf: two of the LRD passes look very similar. I need to figure out whether this can be tidied up, or whether it's ultimately not going to affect perf much Can't think of a particularly more elegant way to do this
  • Tests, tests, tests
  • Other geometries / collections?

@urschrei urschrei marked this pull request as ready for review September 11, 2022 10:48
@urschrei urschrei requested a review from frewsxcv September 11, 2022 10:48
// sum neighbour set LRD scores
let lrd_scores: T = neighbours
.iter()
.map(|(neighbour, _)| local_reachability_densities[neighbour.data])
Copy link
Member Author

@urschrei urschrei Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect there's a way to calculate LRDs for a subset (the point's neighbours) as we go, but I can't get it right so we're stuck with local_reachability_densities and a redundant kth_dist calculation for now. I think it would ultimately end up being two passes over the data anyway, but it might use less space.

@urschrei
Copy link
Member Author

urschrei commented Sep 11, 2022

The paper notes that in order to calculate outliers in a robust fashion it might be necessary to calculate an "ensemble" using a range of nearest-neighour values. Since the r*-tree is expensive to fill and can be re-used, it would make sense to have a "prepared outlier calculator" API that holds on to the tree, allowing you to pass in a new k_neighbours value and getting a re-calculated dataset back out – a dataset is guaranteed to have the same dimensions (one LofScore entry per input point), so it will be easy to either aggregate scores once you've run it over a range of input neighbour sizes, or calculate them as you go in order to save space if you know what aggregate measure will give you good results.

All suggestions for an API gratefully received.

@urschrei
Copy link
Member Author

urschrei commented Sep 12, 2022

The paper notes that in order to calculate outliers in a robust fashion it might be necessary to calculate an "ensemble" using a range of nearest-neighour values. Since the r*-tree is expensive to fill and can be re-used, it would make sense to have a "prepared outlier calculator" API that holds on to the tree, allowing you to pass in a new k_neighbours value and getting a re-calculated dataset back out – a dataset is guaranteed to have the same dimensions (one LofScore entry per input point), so it will be easy to aggregate scores once you've run it over a range of input neighbour sizes

This is done!

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I have some questions, but all my suggestions were minor and should be considered "take it or leave it".

@urschrei
Copy link
Member Author

All review comments addressed, I think.

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Not sure if you were looking for more reviews, so I'll leave it to you if you want to merge it.

@urschrei
Copy link
Member Author

Thanks for the review! I think it's in good shape now but I'll leave it open for a couple of days / until @frewsxcv has kicked the tires on it.

@urschrei urschrei force-pushed the lof branch 3 times, most recently from ed2bddc to 0db5263 Compare September 17, 2022 10:49
Outlier detection is an unsupervised algorithm for detecting outliers
in groups of points (in the abstract sense) by computing local reachability density based on a specified number of neighbours.
@urschrei
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 18, 2022

Build succeeded:

@bors bors bot merged commit 8ee3a0a into georust:main Sep 18, 2022
@urschrei urschrei deleted the lof branch February 14, 2025 21:00
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.

2 participants