V
- the type of FeatureVector handled by this AlgorithmD
- the type of Distance used by this AlgorithmN
- the type of node used in the spatial index structureE
- the type of entry used in the spatial node@Title(value="K-Nearest Neighbor Join") @Description(value="Algorithm to find the k-nearest neighbors of each object in a spatial database") public class KNNJoin<V extends NumberVector<?>,D extends Distance<D>,N extends SpatialNode<N,E>,E extends SpatialEntry> extends AbstractDistanceBasedAlgorithm<V,D,DataStore<KNNList<D>>>
Modifier and Type | Class and Description |
---|---|
static class |
KNNJoin.Parameterizer<V extends NumberVector<?>,D extends Distance<D>,N extends SpatialNode<N,E>,E extends SpatialEntry>
Parameterization class.
|
private class |
KNNJoin.Task
Task in the processing queue.
|
Modifier and Type | Field and Description |
---|---|
(package private) int |
k
The k parameter.
|
static OptionID |
K_ID
Parameter that specifies the k-nearest neighbors to be assigned, must be an
integer greater than 0.
|
private static Logging |
LOG
The logger for this class.
|
DISTANCE_FUNCTION_ID
Constructor and Description |
---|
KNNJoin(DistanceFunction<? super V,D> distanceFunction,
int k)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private D |
computeStopDistance(List<KNNHeap<D>> heaps)
Compute the maximum stop distance.
|
TypeInformation[] |
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query.
|
protected Logging |
getLogger()
Get the (STATIC) logger for this class.
|
private List<KNNHeap<D>> |
initHeaps(SpatialPrimitiveDistanceFunction<V,D> distFunction,
N pr)
Initialize the heaps.
|
private void |
processDataPagesDouble(SpatialPrimitiveDoubleDistanceFunction<? super V> df,
N pr,
N ps,
List<DoubleDistanceKNNHeap> pr_heaps,
List<DoubleDistanceKNNHeap> ps_heaps)
Processes the two data pages pr and ps and determines the k-nearest
neighbors of pr in ps.
|
private void |
processDataPagesOptimize(SpatialPrimitiveDistanceFunction<V,D> distFunction,
List<? extends KNNHeap<D>> pr_heaps,
List<? extends KNNHeap<D>> ps_heaps,
N pr,
N ps)
Processes the two data pages pr and ps and determines the k-nearest
neighbors of pr in ps.
|
WritableDataStore<KNNList<D>> |
run(Database database,
Relation<V> relation)
Joins in the given spatial database to each object its k-nearest neighbors.
|
getDistanceFunction
makeParameterDistanceFunction, run
private static final Logging LOG
public static final OptionID K_ID
int k
public KNNJoin(DistanceFunction<? super V,D> distanceFunction, int k)
distanceFunction
- Distance functionk
- k parameterpublic WritableDataStore<KNNList<D>> run(Database database, Relation<V> relation)
database
- Database to processrelation
- Relation to processprivate List<KNNHeap<D>> initHeaps(SpatialPrimitiveDistanceFunction<V,D> distFunction, N pr)
distFunction
- Distance functionpr
- Node to initialize forprivate void processDataPagesOptimize(SpatialPrimitiveDistanceFunction<V,D> distFunction, List<? extends KNNHeap<D>> pr_heaps, List<? extends KNNHeap<D>> ps_heaps, N pr, N ps)
distFunction
- the distance to usepr
- the first data pageps
- the second data pagepr_heaps
- the knn lists for each data object in prps_heaps
- the knn lists for each data object in ps (if ps != pr)private void processDataPagesDouble(SpatialPrimitiveDoubleDistanceFunction<? super V> df, N pr, N ps, List<DoubleDistanceKNNHeap> pr_heaps, List<DoubleDistanceKNNHeap> ps_heaps)
df
- the distance function to usepr
- the first data pageps
- the second data pagepr_heaps
- the knn lists for each data objectps_heaps
- the knn lists for each data object in psprivate D computeStopDistance(List<KNNHeap<D>> heaps)
heaps
- Heaps listpublic TypeInformation[] getInputTypeRestriction()
AbstractAlgorithm
getInputTypeRestriction
in interface Algorithm
getInputTypeRestriction
in class AbstractAlgorithm<DataStore<KNNList<D extends Distance<D>>>>
protected Logging getLogger()
AbstractAlgorithm