00001 /*!@file BPnnet/BPnnet.H header for Back Prop Neural Net */ 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: Philip Williams <plw@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BPnnet/BPnnet.H $ 00035 // $Id: BPnnet.H 4786 2005-07-04 02:18:56Z itti $ 00036 // 00037 #ifndef BPNNET_H_DEFINED 00038 #define BPNNET_H_DEFINED 00039 00040 #include "BPnnet/BPneuron.H" 00041 #include "Image/Image.H" 00042 #include "BPnnet/KnowledgeBase.H" 00043 #include "BPnnet/SimpleVisualObject.H" 00044 00045 template <class T> class Jet; 00046 00047 //! describes structure of a 3 layer back prop neural net 00048 class BPnnet { 00049 public: 00050 //! Constructor 00051 BPnnet(const int numInput, const int numHidden, const KnowledgeBase *kb); 00052 00053 //! Destructor 00054 ~BPnnet(); 00055 00056 //! Initialize all weights to (small) random values 00057 void randomizeWeights(); 00058 00059 //! Normalize weights 00060 void normalizeWeights(); 00061 00062 //! Do one training iteration 00063 /*! returns rms1 = sum of (target output - actual output)^2/n_outputs 00064 for all output layer neurons */ 00065 double train(const Image<float> &in, const SimpleVisualObject& target, 00066 const double learnRate); 00067 00068 //! Attempt to recognize given jet as a certain visual object 00069 bool recognize(const Image<float> &in, SimpleVisualObject &vo); 00070 00071 //! Store 2 matrices of weights to the file "filename" 00072 /*! use this after training a net */ 00073 bool save(const char* filename) const; 00074 00075 //! Assign all weights based on data stored in the file "filename" 00076 /*! returns false if the # of units in each layer do not match the 00077 matrix sizes in the file 00078 */ 00079 bool load(const char* filename); 00080 00081 private: 00082 00083 // Performs forward propogation tasks common to recognition and training 00084 // Used to avoid repetition of code within recognize() and train() methods 00085 void forwardProp(const Image<float> &in); 00086 00087 // layers - 1 dimensional, should these be vectors instead of images? 00088 std::vector<BPneuron> inputLayer; 00089 std::vector<BPneuron> hiddenLayer; 00090 std::vector<BPneuron> outputLayer; 00091 00092 // Weight (i,j) from input neuron i to hidden neuron j 00093 Image<double> weightFromInput; 00094 // Weight (i,j) from hidden neuron i to output neuron j 00095 Image<double> weightToOutput; 00096 00097 int numInputUnits; // number of features in input 00098 int numHiddenUnits; // variable 00099 int numOutputUnits; // number of known visual objects 00100 00101 const KnowledgeBase *itsKb; 00102 }; 00103 00104 #endif 00105 00106 // ###################################################################### 00107 /* So things look consistent in everyone's emacs... */ 00108 /* Local Variables: */ 00109 /* indent-tabs-mode: nil */ 00110 /* End: */