InputType - Type of data upon which the KNearestNeighbor operates,
something like Vector, Double, or StringOutputType - Output of the evaluator, like Matrix, Double, Stringpublic abstract class AbstractKNearestNeighbor<InputType,OutputType> extends AbstractNearestNeighbor<InputType,OutputType> implements KNearestNeighbor<InputType,OutputType>
divergenceFunctionDEFAULT_K| Constructor and Description |
|---|
AbstractKNearestNeighbor(int k,
DivergenceFunction<? super InputType,? super InputType> divergenceFunction,
Summarizer<? super OutputType,? extends OutputType> averager)
Creates a new instance of KNearestNeighbor
|
| Modifier and Type | Method and Description |
|---|---|
AbstractKNearestNeighbor<InputType,OutputType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
protected abstract java.util.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
|
addgetDivergenceFunction, setDivergenceFunctionequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitadd, getData, getDivergenceFunctionpublic AbstractKNearestNeighbor(int k,
DivergenceFunction<? super InputType,? super InputType> divergenceFunction,
Summarizer<? super OutputType,? extends OutputType> averager)
k - Number of neighbors to consider, must be greater than zerodivergenceFunction - Divergence function that determines how "far" two objects are apartaverager - Creates a single object from a collection of datapublic AbstractKNearestNeighbor<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 DefaultDivergenceFunctionContainer<InputType,InputType>public int getK()
getK in interface KNearestNeighbor<InputType,OutputType>public void setK(int k)
setK in interface KNearestNeighbor<InputType,OutputType>k - Number of neighbors to consider, must be greater than zeropublic Summarizer<? super OutputType,? extends OutputType> getAverager()
getAverager in interface KNearestNeighbor<InputType,OutputType>public void setAverager(Summarizer<? super OutputType,? extends OutputType> averager)
setAverager in interface KNearestNeighbor<InputType,OutputType>averager - Creates a single object from a collection of dataprotected abstract java.util.Collection<OutputType> computeNeighborhood(InputType key)
key - Input to find the nearest neighbors of.public OutputType evaluate(InputType input)
Evaluatorevaluate in interface Evaluator<InputType,OutputType>input - The input to evaluate.