KNN

The KNN module implements a K Nearest Neighbors System. It has inputs for simultaneous learning and choosing of neighbors. The underlying data structure used is a KD-Tree.

Example XML definition

A simple example

  <module
      class = "KNN"
      name = "KNN"
  />

Parameters

NameDescriptionTypeDefault
classThe class name for the module; must be "KNN".string
nameThe name of this instance of the module.string
kHow many neighbors to look for.int5
distance_typeType of distance calculation. Euclidian is the usual sqrt(sum of squares), manhattan is just the addition of differences in all the dimensions.choices:
euclidian
manhattan
euclidian
auto_rebuildAutomatically check if some sub tree can be balanced after an insert.booltrue
minimum_tree_size_for_rebuildWill not auto rebuild smaller sub trees than this.int100
unbalanced_tree_size_ratio_limitDefines what is considered unbalanced. The ratio means ratio between the sizes of the left and right sub trees of a tree.float2.4
verbosePrint some info.boolfalse
check_for_clonesDont insert an example if it is already in the tree.boolfalse

Module Connections

Inputs

NameDescription
INPUTThe coordinates of a target to look for neighbors for.
T_INPUTTraining input. The coordinates of an example to learn/store.
T_OUTPUTTraining output. The class values of the example to learn/store
LEARNLearns from T_INPUT/T_OUTPUT if this is > 0.

Outputs

NameDescription
INPUT_TABLEA matrix of the coordinates of the neighbors that were found around the last INPUT.
OUTPUT_TABLEA matrix of the class values of the neighbors that were found around the last INPUT.
DISTANCE_TABLEAn array of the distances of the neighbors that were found around the last INPUT. NOTE: When it was not possible to find K neighbors (the tree was smaller than size K nodes) the distances for the neighbors that were not found is set to -1.0

Author

Alexander Kolodziej
LUCS

Files

KNN.h
KNN.cc
KD_Tree.ccc
KD_Tree.h
KNN.ikc

blog comments powered by Disqus