Nearest Neighbors
- class discopygal.solvers_infra.nearest_neighbors.NearestNeighbors(metric)
Abstract class represeting the interface a nearest neighbors algorithm should comply.
- Parameters:
metric (
Metric
) – metric to compute nearest neighbors
- fit(points)
Get a list of points (in CGAL Point_2 or Point_d format) and fit some kind of data structure on them.
- get_points()
Return the list of inner points
- k_nearest(point, k)
Given a point, return the k-nearest neighbors to that point.
- class discopygal.solvers_infra.nearest_neighbors.NearestNeighborsCached(nn, max_cache=100)
Wrapper for a nearest neighbor object that also uses cache, and allows for insertion of points in real time. This allows adding points lazily, and only when cache is full then rebuilding the underlying data structure.
- Example:
>>> nn = NearestNeighborsCached(NearestNeighbors_sklearn(metric=Metric_Euclidean)) >>> nn.add_point(Point_d(8, [...]))
- Parameters:
nn (
NearestNeighbors
) – nearest neigbors object to wrapmax_cache – maximum cache size
- add_point(point)
Add a point to the nearest neighbor search
- fit(points)
Get a list of points (in CGAL Point_2 or Point_d format) and fit some kind of data structure on them.
- get_points()
Return the list of inner points
- k_nearest(point, k)
Given a point, return the k-nearest neighbors to that point.
- class discopygal.solvers_infra.nearest_neighbors.NearestNeighbors_CGAL(metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)
CGAL implementation of nearest neighbors
- Parameters:
metric (
Metric
) – metric to compute nearest neighbors
- fit(points)
Get a list of points (in CGAL Point_2 or Point_d format) and fit some kind of data structure on them.
- k_nearest(point, k)
Given a point, return the k-nearest neighbors to that point.
- class discopygal.solvers_infra.nearest_neighbors.NearestNeighbors_sklearn(metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)
Sklearn implementation of nearest neighbors
- Parameters:
metric (
Metric
) – metric to compute nearest neighbors
- fit(points)
Get a list of points (in CGAL Point_2 or Point_d format) and fit some kind of data structure on them.
- k_nearest(point, k)
Given a point, return the k-nearest neighbors to that point.