LazySearch¶
Exact nearest neighbors using a lazy search estrategy.
Parameters¶
-
window_size
Type → int
Default →
50
Size of the sliding window use to search neighbors with.
-
min_distance_keep
Type → float
Default →
0.0
The minimum distance (similarity) to consider adding a point to the window. E.g., a value of 0.0 will add even exact duplicates.
-
dist_func
Type → DistanceFunc | FunctionWrapper | None
Default →
None
A distance function which accepts two input items to compare. If not set, use the Minkowski distance with
p=2
.
Methods¶
append
Add a point to the window, optionally with extra metadata.
Parameters
- item — 'typing.Any'
- extra — 'typing.Any | None' — defaults to
None
- kwargs
search
Find the n_neighbors
closest points to item
, along with their distances.
Parameters
- item — 'typing.Any'
- n_neighbors — 'int'
- kwargs
update
Update the window with a new point, only added if > min distance.
If min distance is 0, we do not need to do the calculation. The item (and extra metadata) will not be added to the window if it is too close to an existing point.
Parameters
- item — 'typing.Any'
- n_neighbors — 'int' — defaults to
1
- extra — 'typing.Any | None' — defaults to
None
Returns
A boolean (true/false) to indicate if the point was added.
Notes¶
Updates are by default stored by the FIFO (first in first out) method, which means that when the size limit is reached, old samples are dumped to give room for new samples. This is circular, meaning that older points are dumped first. This also gives the implementation a temporal aspect, because older samples are replaced with newer ones.
The parameter min_dinstance_keep
controls the addition of new items to the
window - items that are far enough away (> min_distance_keep) are added to
the window. Thus a value of 0 indicates that we add all points, and
increasing from 0 makes it less likely we will keep a new item.