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<V,?>,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<V,?>,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 |
logger
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,
boolean doubleOptimize,
N pr) |
private void |
processDataPagesDouble(SpatialPrimitiveDoubleDistanceFunction<? super V> df,
N pr,
N ps,
List<KNNHeap<DoubleDistance>> pr_heaps,
List<KNNHeap<DoubleDistance>> 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,
boolean doubleOptimize,
List<KNNHeap<D>> pr_heaps,
List<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 logger
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) throws IllegalStateException
IllegalStateException
- if not suitable SpatialIndexTree
was
found or the specified distance function is not an instance of
SpatialPrimitiveDistanceFunction
.private List<KNNHeap<D>> initHeaps(SpatialPrimitiveDistanceFunction<V,D> distFunction, boolean doubleOptimize, N pr)
private void processDataPagesOptimize(SpatialPrimitiveDistanceFunction<V,D> distFunction, boolean doubleOptimize, List<KNNHeap<D>> pr_heaps, List<KNNHeap<D>> ps_heaps, N pr, N ps)
distFunction
- the distance to usedoubleOptimize
- Flag whether to optimize for doubles.pr
- 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<KNNHeap<DoubleDistance>> pr_heaps, List<KNNHeap<DoubleDistance>> 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
- public TypeInformation[] getInputTypeRestriction()
AbstractAlgorithm
getInputTypeRestriction
in interface Algorithm
getInputTypeRestriction
in class AbstractAlgorithm<DataStore<KNNList<D extends Distance<D>>>>
protected Logging getLogger()
AbstractAlgorithm