gov.sandia.cognition.learning.algorithm.nearest
Class KNearestNeighborExhaustive<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.AbstractKNearestNeighbor<InputType,OutputType>
                  extended by gov.sandia.cognition.learning.algorithm.nearest.KNearestNeighborExhaustive<InputType,OutputType>
Type Parameters:
InputType - Type of data upon which the KNearestNeighborExhaustive operates, something like Vector, Double, or String
OutputType - Output of the evaluator, like Matrix, Double, String
All Implemented Interfaces:
Evaluator<InputType,OutputType>, KNearestNeighbor<InputType,OutputType>, NearestNeighbor<InputType,OutputType>, DivergenceFunctionContainer<InputType,InputType>, CloneableSerializable, Serializable, Cloneable
Direct Known Subclasses:
KNearestNeighborExhaustive.Learner

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

A generic k-nearest-neighbor classifier. This classifier simply looks at the nearest "k" neighbors to a point and returns the average of them. Thus, the learner is trivial, but the lookups (evaluations) are expensive. For example, with k=1, then k-nearest-neighbor simply returns the nearest data point to a given input. And so forth.

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

Nested Class Summary
static class KNearestNeighborExhaustive.Learner<InputType,OutputType>
          This is a BatchLearner interface for creating a new KNearestNeighborExhaustive from a given dataset, simply a pass-through to the constructor of KNearestNeighborExhaustive
protected  class KNearestNeighborExhaustive.Neighbor
          Holds neighbor information used during the evaluate method and is put into a priority queue.
 
Field Summary
 
Fields inherited from class gov.sandia.cognition.learning.function.distance.DefaultDivergenceFunctionContainer
divergenceFunction
 
Fields inherited from interface gov.sandia.cognition.learning.algorithm.nearest.KNearestNeighbor
DEFAULT_K
 
Constructor Summary
KNearestNeighborExhaustive()
          Creates a new instance of KNearestNeighborExhaustive.
KNearestNeighborExhaustive(int k, Collection<? extends InputOutputPair<? extends InputType,OutputType>> data, DivergenceFunction<? super InputType,? super InputType> divergenceFunction, Summarizer<? super OutputType,? extends OutputType> averager)
          Creates a new instance of KNearestNeighborExhaustive
 
Method Summary
 KNearestNeighborExhaustive<InputType,OutputType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
protected  Collection<OutputType> computeNeighborhood(InputType key)
          Computes the neighbors to the input key.
 Collection<InputOutputPair<? extends InputType,OutputType>> getData()
          Gets the data from which this computes the nearest neighbors.
 void setData(Collection<InputOutputPair<? extends InputType,OutputType>> data)
          Setter for data
 
Methods inherited from class gov.sandia.cognition.learning.algorithm.nearest.AbstractKNearestNeighbor
evaluate, getAverager, getK, setAverager, setK
 
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
add, getDivergenceFunction
 

Constructor Detail

KNearestNeighborExhaustive

public KNearestNeighborExhaustive()
Creates a new instance of KNearestNeighborExhaustive.


KNearestNeighborExhaustive

public KNearestNeighborExhaustive(int k,
                                  Collection<? extends InputOutputPair<? extends InputType,OutputType>> data,
                                  DivergenceFunction<? super InputType,? super InputType> divergenceFunction,
                                  Summarizer<? super OutputType,? extends OutputType> averager)
Creates a new instance of KNearestNeighborExhaustive

Parameters:
k - Number of neighbors to consider, must be greater than zero
data - Underlying data for the classifier
divergenceFunction - Divergence function that determines how "far" two objects are apart
averager - Creates a single object from a collection of data
Method Detail

clone

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

computeNeighborhood

protected Collection<OutputType> computeNeighborhood(InputType key)
Description copied from class: AbstractKNearestNeighbor
Computes the neighbors to the input key.

Specified by:
computeNeighborhood in class AbstractKNearestNeighbor<InputType,OutputType>
Parameters:
key - Input to find the nearest neighbors of.
Returns:
Collection of nearest neighbors.

getData

public Collection<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(Collection<InputOutputPair<? extends InputType,OutputType>> data)
Setter for data

Parameters:
data - Underlying data for the classifier