00001 /** 00002 \file Robots/LoBot/misc/LoTTIMap.H 00003 \brief An object to store the LGMD spike rates, predicted 00004 times-to-impact and prediction confidence levels corresponding to each 00005 actual time-to-impact recorded in the log files for the Bayesian TTI 00006 prediction experiments. 00007 00008 The Robolocust TTI algorithm for LGMD-based obstacle avoidance uses a 00009 Bayesian state estimator to predict the time-to-impact given an LGMD 00010 spike rate. To evaluate how well this prediction model works, we 00011 conducted several experiments under varying conditions. 00012 00013 The log files collected during these experiments record various pieces 00014 of relevant information such as the actual time-to-impact between the 00015 robot and a wall straight ahead it towards which the robot is driving, 00016 the artificially generated LGMD spike rate corresponding to the actual 00017 TTI, the time-to-impact predicted by the Bayesian TTI model, the 00018 confidence level of this prediction, etc. 00019 00020 The lobay program is designed to parse the above log files and output 00021 a results file that specifies the average spike rate, predicted TTI 00022 and prediction confidence for each actual TTI recorded in the log 00023 files making up a dataset. 00024 00025 This file defines a class that keeps track of the mapping between the 00026 actual TTI values and the corresponding spike rates, predictions and 00027 confidence levels. Since different individual runs of the robot can 00028 produce slightly different records, we maintain a list of spike rates, 00029 TTI predictions and confidence levels per actual TTI. 00030 00031 Once all the logs in a dataset have been loaded and parsed, we will 00032 write the final results to a file of the following format: 00033 00034 TTI LGMD Spike Rate Predicted TTI Confidence Level 00035 --- --------------- ------------- ---------------- 00036 mean stdev mean stdev mean stdev 00037 00038 NOTE: The informational header shown above won't actually appear in 00039 the results file. Rather, the file will simply contain 7 columns of 00040 floating point numbers. The results file ought to be suitable as 00041 direct input for a program such as gnuplot. 00042 */ 00043 00044 // //////////////////////////////////////////////////////////////////// // 00045 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00046 // by the University of Southern California (USC) and the iLab at USC. // 00047 // See http://iLab.usc.edu for information about this project. // 00048 // //////////////////////////////////////////////////////////////////// // 00049 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00050 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00051 // in Visual Environments, and Applications'' by Christof Koch and // 00052 // Laurent Itti, California Institute of Technology, 2001 (patent // 00053 // pending; application number 09/912,225 filed July 23, 2001; see // 00054 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00055 // //////////////////////////////////////////////////////////////////// // 00056 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00057 // // 00058 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00059 // redistribute it and/or modify it under the terms of the GNU General // 00060 // Public License as published by the Free Software Foundation; either // 00061 // version 2 of the License, or (at your option) any later version. // 00062 // // 00063 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00064 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00065 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00066 // PURPOSE. See the GNU General Public License for more details. // 00067 // // 00068 // You should have received a copy of the GNU General Public License // 00069 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00070 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00071 // Boston, MA 02111-1307 USA. // 00072 // //////////////////////////////////////////////////////////////////// // 00073 // 00074 // Primary maintainer for this file: mviswana usc edu 00075 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/baylog/LoTTIMap.H $ 00076 // $Id: LoTTIMap.H 14083 2010-09-30 13:59:37Z mviswana $ 00077 // 00078 00079 #ifndef LOBOT_BAYLOG_TTI_MAP_DOT_H 00080 #define LOBOT_BAYLOG_TTI_MAP_DOT_H 00081 00082 //------------------------------ HEADERS -------------------------------- 00083 00084 // lobot headers 00085 #include "Robots/LoBot/util/triple.hh" 00086 00087 // Standard C++ headers 00088 #include <ostream> 00089 #include <string> 00090 #include <map> 00091 #include <vector> 00092 00093 //----------------------------- NAMESPACE ------------------------------- 00094 00095 namespace lobot { 00096 00097 //------------------------- CLASS DEFINITION ---------------------------- 00098 00099 /** 00100 \class lobot::TTIMap 00101 \brief A mapping between actual times-to-impact recorded in logs 00102 generated during the Bayesiant TTI prediction experiments and the 00103 corresponding LGMD spike rates, predicted times-to-impact and 00104 prediction confidence levels. 00105 00106 This class maps the actual TTI values read from a Bayesian 00107 time-to-impact prediction experiment's log file to the corresponding 00108 LGMD spike rates, predicted TTI's and confidence levels (also recorded 00109 in the log). 00110 00111 Sometimes, an experiment may record the same actual time-to-impact 00112 multiple times. Each such occurence may be associated with a slightly 00113 different set of values for the predicted TTI, prediction confidence 00114 and LGMD spike rate. Furthermore, the different logs making up a 00115 dataset might record the same values for actual TTI's with slightly 00116 different values for the corresponding predictions and LGMD spike 00117 rate. 00118 00119 Therefore, for each actual TTI, we maintain a list of corresponding 00120 predictions, confidence levels and LGMD spike rates. To figure out the 00121 average-case behaviour of the Bayesian prediction model, we compute 00122 the means and standard deviations of all these lists for each actual 00123 TTI and store the results to a file. 00124 */ 00125 class TTIMap { 00126 // Prevent copy and assignment 00127 TTIMap(const TTIMap&) ; 00128 TTIMap& operator=(const TTIMap&) ; 00129 00130 /// The whole idea behind this class is to keep track of a list of 00131 /// correspondences between actual TTI values recorded in log files 00132 /// and LGMD spike rates, predicted TTI values and prediction 00133 /// confidence levels. These types and data members take care of the 00134 /// details. 00135 //@{ 00136 typedef std::vector<float> List ; 00137 typedef triple<List, List, List> Triple ; 00138 typedef std::map<std::string, Triple> Map ; 00139 typedef Map::value_type MapEntry ; 00140 Map m_map ; 00141 //@} 00142 00143 public: 00144 /// Constructor. 00145 TTIMap() ; 00146 00147 /// This method adds a record parsed from a log file to the map. 00148 void add(float actual_tti, 00149 float lgmd_spike_rate, 00150 float predicted_tti, float prediction_confidence) ; 00151 00152 private: 00153 /// Helper function object to dump a map entry to the specified output 00154 /// stream. 00155 class dump { 00156 std::ostream& os ; 00157 public: 00158 dump(std::ostream&) ; 00159 void operator()(const MapEntry&) const ; 00160 } ; 00161 00162 /// Output operator. It should be used after the whole map has been 00163 /// assembled from all the logs in a dataset. 00164 /// 00165 /// This function will compute the means and standard deviations of 00166 /// all the LGMD spike rates, predicted TTI values and prediction 00167 /// confidence levels corresponding to each actual TTI value and write 00168 /// the results to the supplied stream. 00169 friend std::ostream& operator<<(std::ostream&, const TTIMap&) ; 00170 } ; 00171 00172 //----------------------- NON-MEMBER FUNCTIONS -------------------------- 00173 00174 /// This function writes the given TTIMap to the specified stream, 00175 /// computing the proper averages, etc. as required. It should only be 00176 /// used after the TTIMap has been "fully assembled" by parsing all the 00177 /// log files for a Bayesian TTI prediction experiment dataset. 00178 std::ostream& operator<<(std::ostream&, const TTIMap&) ; 00179 00180 //----------------------------------------------------------------------- 00181 00182 } // end of namespace encapsulating this file's definitions 00183 00184 #endif 00185 00186 /* So things look consistent in everyone's emacs... */ 00187 /* Local Variables: */ 00188 /* indent-tabs-mode: nil */ 00189 /* End: */