00001 /*!@file Learn/test-Bayes.C test the Bayes network class 00002 */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Learn/test-Bayes.C $ 00036 // $Id: test-Bayes.C 7040 2006-08-25 16:48:09Z rjpeters $ 00037 // 00038 00039 #include "Component/ModelManager.H" 00040 #include "Image/Image.H" 00041 #include "Learn/Bayes.H" 00042 00043 int main() 00044 { 00045 00046 Bayes bn(4, 2); //constract a bayes network with 4 featuers and 2 classes 00047 00048 00049 std::vector<double> FV(4); 00050 00051 //Class 0 00052 FV[0] = 752; FV[1] = 265; FV[2] = 700; FV[3] = 271; bn.learn(FV, 0u); 00053 FV[0] = 895; FV[1] = 355; FV[2] = 812; FV[3] = 288; bn.learn(FV, 0u); 00054 FV[0] = 893; FV[1] = 352; FV[2] = 790; FV[3] = 298; bn.learn(FV, 0u); 00055 FV[0] = 814; FV[1] = 326; FV[2] = 790; FV[3] = 296; bn.learn(FV, 0u); 00056 FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u); 00057 FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u); 00058 FV[0] = 478; FV[1] = 385; FV[2] = 750; FV[3] = 394; bn.learn(FV, 0u); 00059 FV[0] = 532; FV[1] = 405; FV[2] = 750; FV[3] = 401; bn.learn(FV, 0u); 00060 FV[0] = 565; FV[1] = 47 ; FV[2] = 710; FV[3] = 142; bn.learn(FV, 0u); 00061 FV[0] = 689; FV[1] = 127; FV[2] = 955; FV[3] = 162; bn.learn(FV, 0u); 00062 00063 //Class 1 00064 FV[0] = 576; FV[1] = 726; FV[2] = 287; FV[3] =719; bn.learn(FV, 1); 00065 FV[0] = 718; FV[1] = 783; FV[2] = 300; FV[3] =536; bn.learn(FV, 1); 00066 FV[0] = 859; FV[1] = 724; FV[2] = 270; FV[3] =480; bn.learn(FV, 1); 00067 FV[0] = 839; FV[1] = 512; FV[2] = 246; FV[3] =657; bn.learn(FV, 1); 00068 FV[0] = 746; FV[1] = 343; FV[2] = 250; FV[3] =710; bn.learn(FV, 1); 00069 FV[0] = 660; FV[1] = 527; FV[2] = 272; FV[3] =763; bn.learn(FV, 1); 00070 FV[0] = 704; FV[1] = 621; FV[2] = 263; FV[3] =713; bn.learn(FV, 1); 00071 FV[0] = 684; FV[1] = 836; FV[2] = 287; FV[3] =213; bn.learn(FV, 1); 00072 FV[0] = 678; FV[1] = 800; FV[2] = 377; FV[3] =220; bn.learn(FV, 1); 00073 FV[0] = 624; FV[1] = 697; FV[2] = 494; FV[3] =238; bn.learn(FV, 1); 00074 00075 00076 LINFO("Class 0"); 00077 for(uint i=0; i<bn.getNumFeatures(); i++) 00078 LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(0, i), bn.getStdevSq(0, i)); 00079 00080 LINFO("Class 1"); 00081 for(uint i=0; i<bn.getNumFeatures(); i++) 00082 LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(1, i), bn.getStdevSq(1, i)); 00083 00084 LINFO("Class 0 frq %i prob %f", bn.getClassFreq(0), bn.getClassProb(0)); 00085 LINFO("Class 1 frq %i prob %f", bn.getClassFreq(1), bn.getClassProb(1)); 00086 00087 00088 //New FV to classify 00089 FV[0] = 750; FV[1] = 269; FV[2] = 720; FV[3] = 291; 00090 int cls = bn.classify(FV); //classify a given FV 00091 LINFO("FV1 belongs to class %i", cls); 00092 00093 FV[0] = 458; FV[1] = 381; FV[2] = 350; FV[3] = 392; 00094 cls = bn.classify(FV); //classify a given FV 00095 LINFO("FV2 belongs to class %i", cls); 00096 00097 00098 bn.save("Bayes.net"); 00099 00100 bn.load("Bayes.net"); 00101 00102 LINFO("Class 0"); 00103 for(uint i=0; i<bn.getNumFeatures(); i++) 00104 LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(0, i), bn.getStdevSq(0, i)); 00105 00106 LINFO("Class 1"); 00107 for(uint i=0; i<bn.getNumFeatures(); i++) 00108 LINFO("Feature %i: mean %f, stddevSq %f", i, bn.getMean(1, i), bn.getStdevSq(1, i)); 00109 00110 LINFO("Class 0 frq %i prob %f", bn.getClassFreq(0), bn.getClassProb(0)); 00111 LINFO("Class 1 frq %i prob %f", bn.getClassFreq(1), bn.getClassProb(1)); 00112 00113 00114 //New FV to classify 00115 FV[0] = 750; FV[1] = 269; FV[2] = 720; FV[3] = 291; 00116 cls = bn.classify(FV); //classify a given FV 00117 LINFO("FV1 belongs to class %i", cls); 00118 00119 FV[0] = 458; FV[1] = 381; FV[2] = 350; FV[3] = 392; 00120 cls = bn.classify(FV); //classify a given FV 00121 LINFO("FV2 belongs to class %i", cls); 00122 } 00123 00124 00125 // ###################################################################### 00126 /* So things look consistent in everyone's emacs... */ 00127 /* Local Variables: */ 00128 /* indent-tabs-mode: nil */ 00129 /* End: */