knn.h

Go to the documentation of this file.
00001 // k-Nearest Neighbour
00002 //
00003 // Bala Amavsai (bala@amavasai.org)
00004 // Fri May 25 12:48:48 BST 2001 
00005 //
00006 
00007 #ifndef K_NEAREST_NEIGHBOUR_H
00008 #define K_NEAREST_NEIGHBOUR_H
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 #include <string>
00013 #include <list>
00014 #include <cstdlib>
00015 #include <cmath>
00016 
00017 namespace mimas {
00018 class knn
00019 {
00020  public:
00021   typedef std::string string;
00022   typedef std::ifstream ifstream;
00023     protected:
00024     std::list<double> dataVector;
00025     std::list< std::list<double> > trainingInputSet;
00026     std::list< std::list<double> > trainingOutputSet;
00027   int inputVectorLength, outputVectorLength;
00028   
00029     public:
00030   //variables that can be changed by the user
00031   int numNeighbours;
00032   
00033   void loadTrainingSet(string fn);
00034   knn()
00035   {
00036       numNeighbours=5;
00037   }
00038 
00039   ~knn()
00040   {
00041   }
00042 };
00043 
00044 void knn::loadTrainingSet(string fn)
00045 {
00046     ifstream infile;
00047     string s;
00048     
00049     infile.open(fn.c_str());
00050 //    assure(infile,fn.c_str());
00051 
00052     while(getline(infile,s))
00053     {
00054   int comment=s.find('#');
00055   if (comment!=(signed)string::npos) s=s.substr(0,comment); 
00056   if (s.length()==0) continue;
00057 
00058   int whitespace=s.find(' ');
00059   int tab=s.find('\t');
00060 
00061   if (whitespace==(signed)string::npos) whitespace=tab;
00062   if ((whitespace>tab) && (tab!=(signed)string::npos)) whitespace=tab;
00063   
00064   std::cerr << std::endl << "Whitespace " << whitespace << std::endl;
00065 
00066 //  std::cerr << std::endl << "Space:tab"<< space << ":" << tab << ":" << std::endl;
00067   
00068   std::cerr << "line " << comment << ":" << s.length() << " " << s << std::endl;
00069     } 
00070     
00071     infile.close();
00072 }
00073 
00074 };
00075 
00076 #endif
00077 
00078 
00079 
00080 
00081 
00082 
00083 

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...