gov.sandia.cognition.learning.algorithm.nearest
Class NearestNeighborExhaustive<InputType,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.NearestNeighborExhaustive<InputType,OutputType>
Type Parameters:
InputType - The input type for nearest neighbor.
OutputType - The output type for nearest neighbor.
All Implemented Interfaces:
Evaluator<InputType,OutputType>, NearestNeighbor<InputType,OutputType>, DivergenceFunctionContainer<InputType,InputType>, CloneableSerializable, Serializable, Cloneable

@PublicationReference(author="Wikipedia",
                      title="k-nearest neighbor algorithm",
                      type=WebPage,
                      year=2008,
                      url="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm")
public class NearestNeighborExhaustive<InputType,OutputType>
extends AbstractNearestNeighbor<InputType,OutputType>

The NearestNeighborExhaustive class implements a simple evaluator that looks up a given input object in a collection of input-output pair examples and returns the output associated with the most similar input. Similarity is judged using the given divergence function. This is an implementation of the standard nearest-neighbor algorithm, which is a corner case of the k-nearest neighbor algorithm, implemented in the KNearestNeighbor class.

Since:
2.1
Author:
Justin Basilico
See Also:
KNearestNeighbor, Serialized Form

Nested Class Summary
static class NearestNeighborExhaustive.Learner<InputType,OutputType>
          The NearestNeighborExhaustive.Learner class implements a batch learner for the NearestNeighborExhaustive class.
 
Field Summary
protected  LinkedList<InputOutputPair<? extends InputType,OutputType>> data
          The data that nearest-neighbor is performed over.
 
Fields inherited from class gov.sandia.cognition.learning.function.distance.DefaultDivergenceFunctionContainer
divergenceFunction
 
Constructor Summary
NearestNeighborExhaustive()
          Creates a new instance of NearestNeighborExhaustive.
NearestNeighborExhaustive(DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
          Creates a new instance of NearestNeighborExhaustive.
NearestNeighborExhaustive(DivergenceFunction<? super InputType,? super InputType> divergenceFunction, Collection<? extends InputOutputPair<? extends InputType,OutputType>> data)
          Creates a new instance of NearestNeighborExhaustive.
 
Method Summary
 NearestNeighborExhaustive<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 object to do nearest-neighbor lookup for the given input.
 LinkedList<InputOutputPair<? extends InputType,OutputType>> getData()
          Gets the data from which this computes the nearest neighbors.
 void setData(LinkedList<InputOutputPair<? extends InputType,OutputType>> data)
          Sets the data that the object performs nearest-neighbor lookup on.
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.nearest.AbstractNearestNeighbor
add
 
Methods inherited from class gov.sandia.cognition.learning.function.distance.DefaultDivergenceFunctionContainer
getDivergenceFunction, setDivergenceFunction
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.learning.algorithm.nearest.NearestNeighbor
getDivergenceFunction
 

Field Detail

data

protected LinkedList<InputOutputPair<? extends InputType,OutputType>> data
The data that nearest-neighbor is performed over.

Constructor Detail

NearestNeighborExhaustive

public NearestNeighborExhaustive()
Creates a new instance of NearestNeighborExhaustive.


NearestNeighborExhaustive

public NearestNeighborExhaustive(DivergenceFunction<? super InputType,? super InputType> divergenceFunction)
Creates a new instance of NearestNeighborExhaustive.

Parameters:
divergenceFunction - The divergence function to use.

NearestNeighborExhaustive

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

Parameters:
divergenceFunction - The divergence function to use.
data - The data to perform nearest neighbor over.
Method Detail

clone

public NearestNeighborExhaustive<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,InputType>
Returns:
A clone of this object.

evaluate

public OutputType evaluate(InputType input)
Evaluates the object to do nearest-neighbor lookup for the given input.

Parameters:
input - The input to evaluate.
Returns:
The output associated with the input that is the most similar (least divergent) to the input.

getData

public LinkedList<InputOutputPair<? extends InputType,OutputType>> getData()
Description copied from interface: NearestNeighbor
Gets the data from which this computes the nearest neighbors.

Returns:
Collection of the data Pairs.

setData

public void setData(LinkedList<InputOutputPair<? extends InputType,OutputType>> data)
Sets the data that the object performs nearest-neighbor lookup on.

Parameters:
data - The data to perform nearest-neighbor lookup on.