class KNN

This machine implements the K-nearest-neighbors (KNN) algorithm.

Inheritance:


Public Fields

[more]int K
The number of nearest neighbors.
[more]real* distances
For each nearest neighbor, keeps its distance to the current input
[more]int* indices
For each nearest neighbor, keeps its index in the dataset
[more]DataSet* data
The dataset that contains the potential neaghbors
[more]int* real_examples
the indices of the training examples

Public Methods

[more] KNN(DataSet* data_, int K_)
[more]virtual void setK(int K_)
change the value of K


Inherited from Machine:

Public Fields

oint n_inputs
oint n_outputs
oList* outputs

Public Methods

ovirtual void forward(List* inputs)
ovirtual void reset()


Inherited from Object:

Public Methods

ovirtual void init()
ovoid addOption(const char* name, int size, void* ptr, const char* help="", bool is_allowed_after_init=false)
ovoid addIOption(const char* name, int* ptr, int init_value, const char* help="", bool is_allowed_after_init=false)
ovoid addROption(const char* name, real* ptr, real init_value, const char* help="", bool is_allowed_after_init=false)
ovoid addBOption(const char* name, bool* ptr, bool init_value, const char* help="", bool is_allowed_after_init=false)
ovoid setOption(const char* name, void* ptr)
ovoid setIOption(const char* name, int option)
ovoid setROption(const char* name, real option)
ovoid setBOption(const char* name, bool option)
ovirtual void loadFILE(FILE* file)
ovirtual void saveFILE(FILE* file)
ovoid load(const char* filename)
ovoid save(const char* filename)


Documentation

This machine implements the K-nearest-neighbors (KNN) algorithm. Given a dataset (in the constructor), the forward method returns for a given input the average of the outputs of the K nearest examples (in the input space, using the Euclidean distance). As a side effect, the machine also keep the table of distances of the K-nearest-neighbors.

oint K
The number of nearest neighbors. Controls the capacity of the machine

oreal* distances
For each nearest neighbor, keeps its distance to the current input

oint* indices
For each nearest neighbor, keeps its index in the dataset

oDataSet* data
The dataset that contains the potential neaghbors

oint* real_examples
the indices of the training examples

o KNN(DataSet* data_, int K_)

ovirtual void setK(int K_)
change the value of K


This class has no child classes.
Author:
Samy Bengio (bengio@idiap.ch)

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.