gov.sandia.cognition.learning.algorithm.nearest
Class AbstractKNearestNeighbor<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>
Type Parameters:
InputType - Type of data upon which the KNearestNeighbor 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, KNearestNeighborKDTree

public abstract class AbstractKNearestNeighbor<InputType,OutputType>
extends AbstractNearestNeighbor<InputType,OutputType>
implements KNearestNeighbor<InputType,OutputType>

Partial implementation of KNearestNeighbor.

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

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
AbstractKNearestNeighbor(int k, DivergenceFunction<? super InputType,? super InputType> divergenceFunction, Summarizer<? super OutputType,? extends OutputType> averager)
          Creates a new instance of KNearestNeighbor
 
Method Summary
 AbstractKNearestNeighbor<InputType,OutputType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
protected abstract  Collection<OutputType> computeNeighborhood(InputType key)
          Computes the neighbors to the input key.
 OutputType evaluate(InputType input)
          Evaluates the function on the given input and returns the output.
 Summarizer<? super OutputType,? extends OutputType> getAverager()
          Getter for averager
 int getK()
          Getter for k
 void setAverager(Summarizer<? super OutputType,? extends OutputType> averager)
          Setter for averager
 void setK(int k)
          Setter for k
 
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, getData, getDivergenceFunction
 

Constructor Detail

AbstractKNearestNeighbor

public AbstractKNearestNeighbor(int k,
                                DivergenceFunction<? super InputType,? super InputType> divergenceFunction,
                                Summarizer<? super OutputType,? extends OutputType> averager)
Creates a new instance of KNearestNeighbor

Parameters:
k - Number of neighbors to consider, must be greater than zero
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 AbstractKNearestNeighbor<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.

getK

public int getK()
Getter for k

Specified by:
getK in interface KNearestNeighbor<InputType,OutputType>
Returns:
Number of neighbors to consider, must be greater than zero

setK

public void setK(int k)
Setter for k

Specified by:
setK in interface KNearestNeighbor<InputType,OutputType>
Parameters:
k - Number of neighbors to consider, must be greater than zero

getAverager

public Summarizer<? super OutputType,? extends OutputType> getAverager()
Getter for averager

Specified by:
getAverager in interface KNearestNeighbor<InputType,OutputType>
Returns:
Creates a single object from a collection of data

setAverager

public void setAverager(Summarizer<? super OutputType,? extends OutputType> averager)
Setter for averager

Specified by:
setAverager in interface KNearestNeighbor<InputType,OutputType>
Parameters:
averager - Creates a single object from a collection of data

computeNeighborhood

protected abstract Collection<OutputType> computeNeighborhood(InputType key)
Computes the neighbors to the input key.

Parameters:
key - Input to find the nearest neighbors of.
Returns:
Collection of nearest neighbors.

evaluate

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

Specified by:
evaluate in interface Evaluator<InputType,OutputType>
Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.