Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AltNeuralNetI.cxx

Go to the documentation of this file.
00001 
00002 // $Id: AltNeuralNetI.cxx,v 1.3 2003/12/09 12:08:25 costas Exp $
00003 //
00004 // AltNeuralNetI.cxx
00005 //
00006 //   -- Neural Net Input abstract base class
00007 //   -- This is adapted for AltReco from my Neural Network Foundation Classes
00008 //      (NNFC) package that I use for some of my Neural Net analyses.
00009 //      NNFC is not intended to be part of the minos offline, so I just adapted
00010 //      this single file here.
00011 //
00012 // Costas Andreopoulos <C.V.Andreopoulos@rl.ac.uk>
00013 // CCLRC, Rutherford Appleton Laboratory
00014 // July 01, 2003
00016 
00017 #include<sstream>
00018 #include<cassert>
00019 
00020 #include "AltNeuralNetI.h"
00021 
00022 #include "LeakChecker/Lea.h"
00023 #include "MessageService/MsgService.h"
00024 
00025 ClassImp(AltNeuralNetI)
00026 
00027 //_______________________________________________________________________________
00028 CVSID("$Id: AltNeuralNetI.cxx,v 1.3 2003/12/09 12:08:25 costas Exp $");
00029 //_______________________________________________________________________________
00030 AltNeuralNetI::AltNeuralNetI() :
00031 TNamed()
00032 {
00033   MSG("AltNeuralNet",Msg::kDebug) 
00034                        << "Begin of AltNeuralNetI::AltNeuralNetI() ctor" << endl;
00035   LEA_CTOR;
00036 }
00037 //_______________________________________________________________________________
00038 AltNeuralNetI::AltNeuralNetI(const char * name, const char * title) :
00039 TNamed(name, title)
00040 {
00041   MSG("AltNeuralNet",Msg::kDebug) 
00042      << "Begin of AltNeuralNetI::AltNeuralNetI(const char *, const char * ) ctor" 
00043      << endl;
00044 
00045   fTitle = std::string(title);
00046       
00047   LEA_CTOR;
00048 }
00049 //_______________________________________________________________________________
00050 AltNeuralNetI::AltNeuralNetI(const AltNeuralNetI & cneti):
00051 TNamed(cneti.GetName(), cneti.GetTitle())
00052 {
00053   MSG("AltNeuralNet",Msg::kDebug) 
00054      << "Begin of AltNeuralNetI::AltNeuralNetI(const AltNeuralNetI & cneto) ctor" 
00055      << endl;
00056          
00057   LEA_CTOR;
00058 }
00059 //_______________________________________________________________________________
00060 AltNeuralNetI::~AltNeuralNetI()
00061 {
00062   MSG("AltNeuralNet",Msg::kDebug) 
00063                       << "Begin of AltNeuralNetI::~AltNeuralNetI() dtor" << endl;
00064                            
00065   LEA_DTOR;
00066 }
00067 //_______________________________________________________________________________
00068 void AltNeuralNetI::printI(const Option_t * opt) 
00069 {
00070   MSG("AltNeuralNet",Msg::kVerbose) << "Printing Neural Net Pattern" << endl;
00071   std::string option(opt);
00072   
00073   std::map<std::string, double>::iterator input_iter;
00074 
00075   if( option.find("FULL") > 0 ) {                       
00076   
00077      for( input_iter = fSinglePattern.begin(); 
00078                              input_iter != fSinglePattern.end(); ++input_iter) {
00079                  
00080          MSG("AltNeuralNet",Msg::kVerbose)
00081            << (*input_iter).first << "..............." << (*input_iter).second 
00082            << endl;
00083      }
00084   
00085   } else {
00086        std::string values = "--> ";
00087        std::ostringstream o;
00088        
00089        for(input_iter = fSinglePattern.begin(); 
00090                              input_iter != fSinglePattern.end(); ++input_iter) {
00091                  
00092            o << (*input_iter).second;
00093            values.append( o.str() ); 
00094            values += " / ";              
00095        }
00096        MSG("AltNeuralNet",Msg::kVerbose) << values << endl;
00097   }  
00098 }
00099 //_______________________________________________________________________________  
00100 void AltNeuralNetI::setInputVar(std::string varName, double varValue)
00101 {
00102   assert( fSinglePattern.count(varName) == 1 );
00103   fSinglePattern[varName] = varValue;
00104 }
00105 //_______________________________________________________________________________
00106 double AltNeuralNetI::getInputVar(std::string varName)
00107 {
00108   assert( fSinglePattern.count(varName) == 1 );
00109   std::map<std::string, double>::iterator var = fSinglePattern.find(varName);
00110   return (*var).second;      
00111 }
00112 //_______________________________________________________________________________
00113 double AltNeuralNetI::getTarget(void) const {  return fTarget; }
00114 //_______________________________________________________________________________
00115 void AltNeuralNetI::normalizeInputs(std::map<std::string, double> norm_consts)
00116 {
00117 // value --> norm_const * value;
00118 
00119   for(std::map<std::string, double>::iterator iterNorm = 
00120                norm_consts.begin(); iterNorm != norm_consts.end(); ++iterNorm) {
00121         
00122       assert( fSinglePattern.count( (*iterNorm).first ) == 1 );  
00123       //fSinglePattern[ (*iterNorm).first ) ] *= (*iterNorm).second;                    
00124   }
00125   
00126   if(! isWithinLimits() ) {
00127      MSG("AltNeuralNet",Msg::kWarning) 
00128                            << "Input pattern values not in [0,1] range" << endl;
00129      printI("FULL");     
00130   }
00131 }
00132 //_______________________________________________________________________________
00133 void AltNeuralNetI::copyInputsToArray(float * inputs)
00134 {
00135   int pos = 0;
00136   std::map<std::string, double>::iterator input_iter;
00137 
00138   for(input_iter = fSinglePattern.begin();
00139                input_iter != fSinglePattern.end(); ++input_iter) 
00140                                    inputs[pos++] = (float) (*input_iter).second;   
00141 }
00142 //_______________________________________________________________________________
00143 void AltNeuralNetI::raiseSignalFlag(void) { fTarget = kSignal;}
00144 //_______________________________________________________________________________
00145 void AltNeuralNetI::raiseBackgroundFlag(void){  fTarget = kBackground;}
00146 //_______________________________________________________________________________
00147 bool AltNeuralNetI::isSignal(void) const { return fTarget == kSignal; }
00148 //_______________________________________________________________________________
00149 bool AltNeuralNetI::isBackground(void) const { return fTarget == kBackground; }
00150 //_______________________________________________________________________________
00151 bool AltNeuralNetI::isWithinLimits(void) 
00152 {
00153   bool within_limits = true;
00154   
00155   for(std::map<std::string, double>::iterator input_iter = 
00156      fSinglePattern.begin(); input_iter != fSinglePattern.end(); ++input_iter) {
00157      
00158          within_limits = within_limits && ( (*input_iter).second >= 0. &&
00159                                             (*input_iter).second <= 1.  );
00160    }                         
00161   return within_limits;
00162 }
00163 //_______________________________________________________________________________
00164 void AltNeuralNetI::resetPattern(void)
00165 {
00166   for(std::map<std::string, double>::iterator iter = 
00167                 fSinglePattern.begin(); iter != fSinglePattern.end(); ++iter) {
00168                        
00169       fSinglePattern.erase( (*iter).first );
00170   }  
00171   assert( fSinglePattern.size() == 0);
00172 }
00173 //_______________________________________________________________________________
00174 void AltNeuralNetI::resetPatternValues(void)
00175 {
00176   for(std::map<std::string, double>::iterator iter = 
00177        fSinglePattern.begin(); iter != fSinglePattern.end(); ++iter) 
00178                                                            (*iter).second = 0.0;
00179 }
00180 //_______________________________________________________________________________
00181 int AltNeuralNetI::getNumberOfInputs(void) const {
00182                                            return (int) fSinglePattern.size(); }
00183 //_______________________________________________________________________________
00184 std::vector<std::string> AltNeuralNetI::getInputNames(void) 
00185 {
00186   std::vector<std::string> names;
00187   std::map<std::string, double>::iterator input_iter;
00188   
00189   for(input_iter = fSinglePattern.begin();
00190                       input_iter != fSinglePattern.end(); ++input_iter)         
00191                                          names.push_back( (*input_iter).first );    
00192   return names;
00193 }
00194 //_______________________________________________________________________________
00195 void AltNeuralNetI::initPattern(const std::string * var_names, const int n_vars)
00196 {
00197   for(int ivar=0; ivar<n_vars; ivar++)
00198          fSinglePattern.insert(
00199                   std::map<std::string, double>::value_type(var_names[ivar],-1));
00200 }
00201 //_______________________________________________________________________________

Generated on Mon Feb 15 11:06:21 2010 for loon by  doxygen 1.3.9.1