InputType - Type of Vectorizable data upon which we determine
similarity.OutputType - Output of the evaluator, like Matrix, Double, String@PublicationReference(author="Wikipedia", title="k-nearest neighbor algorithm", type=WebPage, year=2008, url="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm") public class KNearestNeighborKDTree<InputType extends Vectorizable,OutputType> extends AbstractKNearestNeighbor<InputType,OutputType> implements Evaluator<InputType,OutputType>
KDTree,
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
KNearestNeighborKDTree.Learner<InputType extends Vectorizable,OutputType>
This is a BatchLearner interface for creating a new KNearestNeighbor
from a given dataset, simply a pass-through to the constructor of
KNearestNeighbor
|
divergenceFunctionDEFAULT_K| Constructor and Description |
|---|
KNearestNeighborKDTree()
Creates a new instance of KNearestNeighborKDTree
|
KNearestNeighborKDTree(int k,
KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data,
Metric<? super InputType> distanceFunction,
Summarizer<? super OutputType,? extends OutputType> averager)
Creates a new instance of KNearestNeighborKDTree
|
| Modifier and Type | Method and Description |
|---|---|
KNearestNeighborKDTree<InputType,OutputType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
protected java.util.Collection<OutputType> |
computeNeighborhood(InputType key)
Computes the neighbors to the input key.
|
KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> |
getData()
Getter for data
|
Metric<? super InputType> |
getDivergenceFunction()
Setter for distanceFunction
|
void |
rebalance()
Rebalances the internal KDTree to make the search more efficient.
|
void |
setData(KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data)
Setter for data
|
void |
setDivergenceFunction(DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
Sets the divergence function used by this object.
|
void |
setDivergenceFunction(Metric<? super InputType> divergenceFunction)
Sets the Metric to use.
|
evaluate, getAverager, getK, setAverager, setKaddequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddpublic KNearestNeighborKDTree()
public KNearestNeighborKDTree(int k,
KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data,
Metric<? super InputType> distanceFunction,
Summarizer<? super OutputType,? extends OutputType> averager)
k - Number of neighbors to consider, must be greater than zerodata - KDTree that holds the data to search for neighbors.distanceFunction - Distance metric that determines how "far" two objects are apart,
where lower values indicate two objects are more similaraverager - KDTree that holds the data to search for neighbors.public KNearestNeighborKDTree<InputType,OutputType> clone()
AbstractCloneableSerializableObject class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone() to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone() as the basis for your implementation.clone in interface CloneableSerializableclone in class AbstractKNearestNeighbor<InputType extends Vectorizable,OutputType>public Metric<? super InputType> getDivergenceFunction()
getDivergenceFunction in interface NearestNeighbor<InputType extends Vectorizable,OutputType>getDivergenceFunction in interface DivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>getDivergenceFunction in class DefaultDivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>public void setDivergenceFunction(DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
DefaultDivergenceFunctionContainersetDivergenceFunction in class DefaultDivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>divergenceFunction - The divergence function.public void setDivergenceFunction(Metric<? super InputType> divergenceFunction)
divergenceFunction - Metric that determines closeness.public KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> getData()
getData in interface NearestNeighbor<InputType extends Vectorizable,OutputType>public void setData(KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data)
data - KDTree that holds the data to search for neighbors.protected java.util.Collection<OutputType> computeNeighborhood(InputType key)
AbstractKNearestNeighborcomputeNeighborhood in class AbstractKNearestNeighbor<InputType extends Vectorizable,OutputType>key - Input to find the nearest neighbors of.public void rebalance()