com.kpro.algorithm
Class Reduction_KNN

java.lang.Object
  extended by com.kpro.algorithm.ReductionAlgorithm
      extended by com.kpro.algorithm.Reduction_KNN

public class Reduction_KNN
extends ReductionAlgorithm

A k-nearest-neighbors algorithm class. create it and call run on it to get the nearest k neighbors to the object passed to run().

Version:
29.09.11.1
Author:
ngerstle

Field Summary
private  DistanceMetric distanceMetric
           
private  int k
           
 
Fields inherited from class com.kpro.algorithm.ReductionAlgorithm
extraArgs, pdb
 
Constructor Summary
Reduction_KNN(DistanceMetric distanceMetric, PolicyDatabase database, java.lang.String[] extraArgs)
          creates a kNearestNeighbors algorithm to use
 
Method Summary
 java.util.ArrayList<PolicyObject> reduce(PolicyObject newPO)
          the method that returns the closest k objects to the parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

distanceMetric

private DistanceMetric distanceMetric

k

private int k
Constructor Detail

Reduction_KNN

public Reduction_KNN(DistanceMetric distanceMetric,
                     PolicyDatabase database,
                     java.lang.String[] extraArgs)
creates a kNearestNeighbors algorithm to use

Parameters:
distanceMetric - the class defining distance between objects
database - the database of objects to operate on
extraArgs - from the config file
Method Detail

reduce

public java.util.ArrayList<PolicyObject> reduce(PolicyObject newPO)
the method that returns the closest k objects to the parameter. works by sorting elements by distance from passed object, and passing the first k elements.

Specified by:
reduce in class ReductionAlgorithm
Parameters:
newPO - the new PolicyObject the thing to find the neighbors of
Returns:
ArrayList an arraylist of size k of the nearest neighbors