org.android.activityminer.logic.classification
Class KNN

Package class diagram package KNN
java.lang.Object
  extended by org.android.activityminer.logic.classification.KNN
All Implemented Interfaces:
Classifier

public class KNN
extends Object
implements Classifier


Field Summary
private  String[] attributeNames
          The attribute names per point index of a trained KNN instance
private  boolean doNormalize
          The normalization configuration flag.
private  KdTree<Long> kdTree
          The k-dimensional tree.
private  int neighborCount
          The count of neighbors.
private  Normalizer normalizer
          The attribute value normalizer.
 
Constructor Summary
KNN(int neighborCount, boolean doNormalize)
          Constructor
KNN(List<ModelElement> pmmlModelElements, ActivityMinerExtension extension)
          Constructor
 
Method Summary
protected  void addPoint(double[] point, long cId)
          Does add a data point to the tree.
 PredictionResult classify(Activity activity)
          Does classify the given sample
private  void fromPMMLModel(NearestNeighborModel nearestNeighborModel)
          Method to create the classifier model from a PMML nearest neighbor model.
 void fromPMMLModelElements(List<ModelElement> modelElements, ActivityMinerExtension extension)
          Method to create the classifier model from PMML model elements.
 String[] getAttributeNames()
          Getter for the known attribute names
 String getDescription(Context context)
          Getter for a significant description of the configured classifier.
static String getDescription(Context context, int neighborCount, boolean normalized)
          Getter for a significant description of a classifier with the given configuration parameters.
 KdTree<Long> getKdTree()
          Getter for the k-dimensional tree
 int getNeighborCount()
          Getter for the neighbor count
 Normalizer getNormalizer()
          Getter for the normalizer
protected  void prepare(String[] attributeNames, int size)
          Does prepare the classifier.
 List<ModelElement> toPMMLModelElements(Context context, DataDictionary dataDictionary)
          Getter for the PMML model elements.
 void train(Set<? extends Activity> trainingSet)
          Does initialize and train the classifier (internal model creation)
private  void trainPMMLModel(List<Row> rows, String[] orderedAttributeCols)
          Does train the classifier model from PMML data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kdTree

private KdTree<Long> kdTree
The k-dimensional tree.


attributeNames

private String[] attributeNames
The attribute names per point index of a trained KNN instance


neighborCount

private int neighborCount
The count of neighbors.


doNormalize

private boolean doNormalize
The normalization configuration flag.


normalizer

private Normalizer normalizer
The attribute value normalizer.

Constructor Detail

KNN

public KNN(int neighborCount,
           boolean doNormalize)
Constructor

Parameters:
neighborCount - the count of nearest neighbors to use for decision
doNormalize - if true attributes will be normalized to the range of [0,1]

KNN

public KNN(List<ModelElement> pmmlModelElements,
           ActivityMinerExtension extension)
Constructor

Parameters:
pmmlModelElements - the PMML model elements to build from
extension - the activity mine specific extensions
Method Detail

getAttributeNames

public final String[] getAttributeNames()
Getter for the known attribute names

Returns:
the known attribute names

getNeighborCount

public final int getNeighborCount()
Getter for the neighbor count

Returns:
the neighbor count

getKdTree

public final KdTree<Long> getKdTree()
Getter for the k-dimensional tree

Returns:
the k-dimensional tree

getNormalizer

public Normalizer getNormalizer()
Getter for the normalizer

Returns:
the normalizer

train

public final void train(Set<? extends Activity> trainingSet)
Description copied from interface: Classifier
Does initialize and train the classifier (internal model creation)

Specified by:
train in interface Classifier
Parameters:
trainingSet - the training set

prepare

protected final void prepare(String[] attributeNames,
                             int size)
Does prepare the classifier.

Parameters:
attributeNames - the attribute names for the point dimensions
size - the tree size

addPoint

protected final void addPoint(double[] point,
                              long cId)
Does add a data point to the tree.

Parameters:
point - the data point to add
cId - the class identifier

classify

public final PredictionResult classify(Activity activity)
Description copied from interface: Classifier
Does classify the given sample

Specified by:
classify in interface Classifier
Parameters:
activity - the activity to classify
Returns:
the predicted class identifier or -1 if no prediction is made

getDescription

public final String getDescription(Context context)
Description copied from interface: Classifier
Getter for a significant description of the configured classifier.

Specified by:
getDescription in interface Classifier
Parameters:
context - the context
Returns:
the description of this classifier instance

getDescription

public static final String getDescription(Context context,
                                          int neighborCount,
                                          boolean normalized)
Getter for a significant description of a classifier with the given configuration parameters.

Parameters:
context - the context
neighborCount - the neighbor count
normalized - normalization flag
Returns:
the description

toPMMLModelElements

public final List<ModelElement> toPMMLModelElements(Context context,
                                                    DataDictionary dataDictionary)
Description copied from interface: Classifier
Getter for the PMML model elements. The mining schema and the output fields can be ignored, they will be overridden by the calling instance based on the actual configuration.

Specified by:
toPMMLModelElements in interface Classifier
Parameters:
context - the context
dataDictionary - the data dictionary
Returns:
the PMML model

fromPMMLModelElements

public final void fromPMMLModelElements(List<ModelElement> modelElements,
                                        ActivityMinerExtension extension)
Description copied from interface: Classifier
Method to create the classifier model from PMML model elements.

Specified by:
fromPMMLModelElements in interface Classifier
Parameters:
modelElements - the model elements to build model from
extension - the activity mine specific extensions

fromPMMLModel

private final void fromPMMLModel(NearestNeighborModel nearestNeighborModel)
Method to create the classifier model from a PMML nearest neighbor model.

Parameters:
nearestNeighborModel - the knn model

trainPMMLModel

private void trainPMMLModel(List<Row> rows,
                            String[] orderedAttributeCols)
Does train the classifier model from PMML data

Parameters:
rows - the rows with the training data
orderedAttributeCols - the column names in the order of corresponding attribute names