All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
face_contour_detector::learing::k_nearest_neighbour Namespace Reference

Implementation of the k-nearest-neighbour algorithm. More...


def euclidean_distance
 Calculate the euclidean distance of two n-dimensional points.
def k_nearest_neighbours
 Find for point it's k nearest neighours in the iterable object points

Detailed Description

Implementation of the k-nearest-neighbour algorithm.

Fabian Wenzelmann

Function Documentation

Calculate the euclidean distance of two n-dimensional points.

The euclidean distance for two points $p = (p_1, p_2, \dots, p_n)$ and $q = (q_1, q_2, \dots, q_n)$ is defined as follows: $ ED(p, q) = \sqrt{ \sum\limits_{i=1}^n (q_i - p_i)^2 } $

Definition at line 11 of file

def face_contour_detector.learing.k_nearest_neighbour.k_nearest_neighbours (   point,
  key = lambda x: x,
  key2 = None,
  distance = euclidean_distance 

Find for point it's k nearest neighours in the iterable object points

pointthe reference points which near neighbours you want to find
pointsiterable object of other points (distance to point is calculated for each point in this "set")
kdefines how many neighbours are found in the result list (if the length of the list is smaller than k a list of points is returned)
keythe distance function is not called on point and a point in points directly. The key function is called on point and the result is passed to the distance function
key2similar to key but this function is applied to each point in the points "set". Default is None which means that key is used. The advantage of having to key functions is that we can apply different functions on point and all other points.
distancea distance function that defines a float distance between two points. The distance function is applied to key(point) and key2(p) where p is a point form points. Default is euclidean_distance
List with the k nearest neighbours of point in points point is the reference point the distance is calculated form. points is the iterable object with all other points. Calculates a list containing the k-nearest neighbours of point in points. If len(points) < k the list has length len(points).

Definition at line 28 of file

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends

Author(s): Fabian Wenzelmann and Julian Schmid
autogenerated on Wed Dec 26 2012 16:18:19