test-NPclassify2.C

Go to the documentation of this file.
00001 /*!@file VFAT/test-NPclassify2.C  Test the non-parametric classifier */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: T Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-NPclassify2.C $
00035 // $Id: test-NPclassify2.C 6003 2005-11-29 17:22:45Z rjpeters $
00036 //
00037 
00038 // ############################################################
00039 // ############################################################
00040 // ##### ---NPclassify---
00041 // ##### non-parametric classifier:
00042 // ##### T. Nathan Mundhenk nathan@mundhenk.com
00043 // ##### Vidhya Navalpakkam - navalpak@usc.edu
00044 // ##### partners full name - email
00045 // ############################################################
00046 // ############################################################
00047 
00048 //This is the start of the execution path for the NPclassify test alg.#include "log.H"
00049 
00050 #include "VFAT/NPclassify2.H"
00051 
00052 
00053 #define INVALS 31
00054 
00055 //! This is the configFile name
00056 char* configFile;
00057 //! This is the configFile object
00058 readConfig configIn(25);
00059 readConfig polySet(25);
00060 //! number of items if training
00061 int itemNumber;
00062 int features;
00063 int datasize;
00064 
00065 int main(int argc, char* argv[])
00066 {
00067   float inVals[INVALS];
00068   // get test file
00069   std::ifstream inFile(argv[1],std::ios::in);
00070   features = (int)atof(argv[2]);
00071   datasize = (int)atof(argv[3]);
00072   for(int i = 0; i < INVALS; i++)
00073   {
00074     inVals[i] = atof(argv[4+i]);
00075   }
00076 
00077   // create operating objects
00078   configIn.openFile("NPclassify.conf");
00079   polySet.openFile("polySet.conf");
00080 
00081   std::string in;
00082   std::vector<float> feature(features,0);
00083   std::vector<std::vector<float> > vectorIn(datasize,feature);
00084 
00085   long featureCount = 0;
00086   int column = 0;
00087   int row = 0;
00088   bool comment = false;
00089 
00090   // convert test file to vector format
00091   //std::cerr << "Parsing config file" << argv[1] << "\n";
00092   while (inFile >> in)
00093   {
00094     if(!in.compare("#")) //comment code # found
00095     {
00096       if(!comment)
00097       {
00098         comment = true;
00099       }
00100       else      //end of comment
00101       {
00102         comment = false;
00103       }
00104     }
00105     if((!comment) && in.compare("#")) //real line found
00106     {
00107       vectorIn[row][column] = atof(in.c_str()) * atof(argv[INVALS+4+column]);
00108       //std::cerr << "Adding " << in << "[" << row << "]"
00109       //    << "[" << column << "]\n";
00110       column++;
00111       if(column == features)
00112       {
00113         column = 0;
00114         row++;
00115         featureCount++;
00116       }
00117     }
00118   }
00119 
00120   // (1) create the NP classify object, input conf files, specify if settings
00121   // are from command line
00122   NPclassify2<float> NP(configIn,polySet,false);
00123   // (2) input any command line arguments if any
00124 
00125   NP.NPinputCommandLineSettings(inVals);
00126 
00127   //----------------------------------------------------------------//
00128 
00129   // classify space using density webs
00130   // (3) specify the size of your space in samples and dimensions
00131   NP.NPresizeSpace(featureCount,features);
00132   // (4) input the current vector into the NP clusterer
00133   NP.NPaddSpace(vectorIn);
00134   // (5) start the alg.
00135   NP.NPclassifySpaceNew(false);
00136   std::cerr << "DONE\n";
00137 
00138   long roots = NP.NPgetStemNumberEdit();
00139   std::cout << roots << "\n";
00140 }
Generated on Sun May 8 08:07:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3