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 n_outputs
the size of the output vector
[more]int* real_examples
the indices of the training examples

Public Methods

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


Inherited from Machine:

Public Fields

oSequence* outputs

Public Methods

ovirtual void forward(Sequence* sequence)
ovirtual void reset()
ovirtual void setDataSet(DataSet* dataset_)


Inherited from Object:

Public Fields

oAllocator* allocator

Public Methods

ovoid addOption(const char* name, int size, void* ptr, const char* help="")
ovoid addIOption(const char* name, int* ptr, int init_value, const char* help="")
ovoid addROption(const char* name, real* ptr, real init_value, const char* help="")
ovoid addBOption(const char* name, bool* ptr, bool init_value, const char* help="")
ovoid addOOption(const char* name, Object** ptr, Object* init_value, const char* help="")
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)
ovoid setOOption(const char* name, Object* option)
ovirtual void loadXFile(XFile* file)
ovirtual void saveXFile(XFile* file)
ovoid load(const char* filename)
ovoid save(const char* filename)
ovoid* operator new(size_t size, Allocator* allocator_=NULL)
ovoid* operator new(size_t size, Allocator* allocator_, void* ptr_)
ovoid operator delete(void* ptr)


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 n_outputs
the size of the output vector

oint* real_examples
the indices of the training examples

o KNN(int n_outputs_, 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++.