gov.sandia.cognition.learning.algorithm.nearest
Class NearestNeighborKDTree<InputType extends Vectorizable,OutputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.distance.DefaultDivergenceFunctionContainer<InputType,InputType>
          extended by gov.sandia.cognition.learning.algorithm.nearest.AbstractNearestNeighbor<InputType,OutputType>
              extended by gov.sandia.cognition.learning.algorithm.nearest.NearestNeighborKDTree<InputType,OutputType>
Type Parameters:
InputType - Type of Vectorizable data upon which we determine similarity.
OutputType - Output of the evaluator, like Matrix, Double, String
All Implemented Interfaces:
Evaluator<InputType,OutputType>, NearestNeighbor<InputType,OutputType>, DivergenceFunctionContainer<InputType,InputType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
NearestNeighborKDTree.Learner

public class NearestNeighborKDTree<InputType extends Vectorizable,OutputType>
extends AbstractNearestNeighbor<InputType,OutputType>

A KDTree-based implementation of the nearest neighbor algorithm. This algorithm has a O(n log(n)) construction time and a O(log(n)) evaluate time.

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Nested Class Summary
static class NearestNeighborKDTree.Learner<InputType extends Vectorizable,OutputType>
          This is a BatchLearner interface for creating a new NearestNeighbor from a given dataset, simply a pass-through to the constructor of NearestNeighbor
 
Field Summary
 
Fields inherited from class gov.sandia.cognition.learning.function.distance.DefaultDivergenceFunctionContainer
divergenceFunction
 
Constructor Summary
NearestNeighborKDTree()
          Creates a new instance of NearestNeighborKDTree.
NearestNeighborKDTree(KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data, DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
          Creates a new instance of NearestNeighborKDTree
 
Method Summary
 NearestNeighborKDTree<InputType,OutputType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 OutputType evaluate(InputType input)
          Evaluates the function on the given input and returns the output.
 KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> getData()
          Getter for data
 Metric<? super InputType> getDivergenceFunction()
          Setter for distanceFunction
 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.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.nearest.AbstractNearestNeighbor
add
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NearestNeighborKDTree

public NearestNeighborKDTree()
Creates a new instance of NearestNeighborKDTree.


NearestNeighborKDTree

public NearestNeighborKDTree(KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data,
                             DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
Creates a new instance of NearestNeighborKDTree

Parameters:
data - Underlying data for the classifier
divergenceFunction - Divergence function that determines how "far" two objects are apart
Method Detail

clone

public NearestNeighborKDTree<InputType,OutputType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object 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.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class DefaultDivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>
Returns:
A clone of this object.

getDivergenceFunction

public Metric<? super InputType> getDivergenceFunction()
Setter for distanceFunction

Specified by:
getDivergenceFunction in interface NearestNeighbor<InputType extends Vectorizable,OutputType>
Specified by:
getDivergenceFunction in interface DivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>
Overrides:
getDivergenceFunction in class DefaultDivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>
Returns:
Distance metric that determines how "far" two objects are apart, where lower values indicate two objects are more similar.

setDivergenceFunction

public void setDivergenceFunction(DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
Description copied from class: DefaultDivergenceFunctionContainer
Sets the divergence function used by this object.

Overrides:
setDivergenceFunction in class DefaultDivergenceFunctionContainer<InputType extends Vectorizable,InputType extends Vectorizable>
Parameters:
divergenceFunction - The divergence function.

setDivergenceFunction

public void setDivergenceFunction(Metric<? super InputType> divergenceFunction)
Sets the Metric to use.

Parameters:
divergenceFunction - Metric that determines closeness.

getData

public KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> getData()
Getter for data

Returns:
KDTree that holds the data to search for neighbors.

setData

public void setData(KDTree<InputType,OutputType,InputOutputPair<? extends InputType,OutputType>> data)
Setter for data

Parameters:
data - KDTree that holds the data to search for neighbors.

evaluate

public OutputType evaluate(InputType input)
Description copied from interface: Evaluator
Evaluates the function on the given input and returns the output.

Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.