face_contour_detector::learing::k_nearest_neighbour Namespace Reference

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

## Functions

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.

## Function Documentation

 def face_contour_detector.learing.k_nearest_neighbour.euclidean_distance ( p1, p2 )

Calculate the euclidean distance of two n-dimensional points.

The euclidean distance for two points and is defined as follows: Definition at line 11 of file k_nearest_neighbour.py.

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

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

Parameters:
 point the reference points which near neighbours you want to find points iterable object of other points (distance to point is calculated for each point in this "set") k defines 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) key the 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 key2 similar 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. distance a 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
Returns:
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 k_nearest_neighbour.py.

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