LiftStatistic.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 #ifndef LIFT_STATISTIC_H
00006 #define LIFT_STATISTIC_H
00007 
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011 #include <assert.h>
00012 #include <iomanip>
00013 #include <map>
00014 
00015 #include <sstream>
00016 
00017 
00024  #include <stdint.h>
00025 #include <iostream>
00026 #include <vector>
00027 #include <list>
00028 
00029 #include "typedefs.h"
00030 
00031 namespace nCenterFocus
00032 {
00033 
00038         class FailedLiftStatistic
00039         {
00040         
00041         private:
00042         
00043                 std::vector<int32_t> failedLiftCount_m;
00044         
00045                 int64_t failedLiftTrialCount;
00046 
00047                 
00048         
00049                 unsigned int maxLift_m;
00050                 unsigned int liftTrials_m;
00051 
00052                 int64_t         testFailureCount_m;
00053         
00054         public:
00055         
00056                 FailedLiftStatistic(unsigned int maxLift, unsigned int liftTrials);
00057                 FailedLiftStatistic();
00058 
00059                 void operator+=(const FailedLiftStatistic & summand);
00060         
00061                 unsigned int getMaxLift()       const  ;
00062                 unsigned int getLiftTrials()    const  ;
00063         
00064 
00065                 
00066                 void            logFailedLift(int currentLiftNr);
00067 
00069                 void            logFailedTests(int count);
00070         
00071                 int32_t         getFailedLiftCount(unsigned int liftNr) const;
00072 
00073                 void            setTestFailureCount();
00074                 int32_t         getTestFailureCount() const;
00075         
00076                 void            setFailedLiftCount(unsigned int liftNr, int32_t count);
00077         
00078                 unsigned short  getMinFailedLiftNr()    const;
00079         
00080                 void    print(std::ostream & os)        const;
00081                 
00082         };
00083  
00084 
00089         class EmptyFailedLiftStatistic
00090         {
00091                 public :
00092                         inline static void              logFailedLift(int currentLiftNr) {};
00093         };
00094         
00095         
00103         class ExtendedFailedLiftStatistic
00104         {
00105         public:
00106 
00107                 typedef std::map<int, std::vector<FailedLiftStatistic >  >  failedLiftStatisticMapType;
00108         private:
00109         
00110 
00115                         mutable unsigned short  maxLift_m;
00116                         mutable unsigned int            liftTrials_m;
00117                         mutable bool bMaxLiftAndLiftTrialsIinitialized_m;
00118                         //int maxJacobianRank_m;
00119                         //std::vector<FailedLiftStatistic > failedLiftStatisticList_m;
00120 
00121                         failedLiftStatisticMapType      failedLiftStatisticMap_m;
00122 
00123                         //std::vector<std::pair<FailedLiftStatistic,int> > failedLiftStatisticList_m;
00124                 
00125                         //mutable std::vector<FailedLiftStatistic > failedLiftStatisticEvaluatedList_m;
00126         
00127                         mutable std::vector<uint64_t> hitLiftInfo_m;
00128 
00129                         mutable std::vector<FailedLiftStatistic >       failedLiftStatisticList_m;
00130         
00133                 template <class FailedLiftStatisticVector>
00134                 unsigned int getMaxLift(FailedLiftStatisticVector               & failedLiftStatisticList ) const; 
00135 
00136                 template <class FailedLiftStatisticVector>
00137                 unsigned int getLiftTrials(FailedLiftStatisticVector            & failedLiftStatisticList ) const;
00138 
00139                 inline void initMaxLiftAndLiftTrials() const;
00140 
00141                 template <class FailedLiftStatisticVector>
00142                 std::vector<FailedLiftStatistic >     getLiftStatisticEvaluatedList(FailedLiftStatisticVector    & failedLiftStatisticList) const;
00143 
00144                 // Auswertung 1: für jeden Punkt minLift. ermitteln. zähle für alle mögliche minLifts, bei wieviel Punkten dieser minLift auftritt.
00145                 
00146                 template <class FailedLiftStatisticVector>
00147                 std::vector<int>        getMinLiftPointStatistic(FailedLiftStatisticVector       & failedLiftStatisticList) const;
00148 
00149                 // Auswertung2: zähle Über alle Punkte das Minimum fuer einen aufgetretenen Wert.
00150 
00151                 template <class FailedLiftStatisticVector>
00152                 std::vector<int>        getMinLiftAllStatistic(FailedLiftStatisticVector         & failedLiftStatisticList) const;
00153 
00154                 template <class FailedLiftStatisticVector>
00155                 std::vector<double>     getAverageLiftAllStatistic(FailedLiftStatisticVector     & failedLiftStatisticList) const;
00156         
00157                 
00158                 template <class FailedLiftStatisticVector>
00159                 std::string     getFailedLiftStatisticValue(  FailedLiftStatisticVector & failedLiftStatisticList )     const ;
00160                 
00161                 std::string             getMinLiftPointStatisticValue(  std::vector<int> &minLiftInfo    )      const ; 
00162                 std::string             getAverageLiftStatisticValue (  std::vector<double> &averageLiftInfo )  const ;
00163 
00164                 //void evaluateHitLiftInfo() const;
00165 
00166         
00167         public:
00168                 ExtendedFailedLiftStatistic();
00169         
00172                         //inline void   logFailedLift(FailedLiftStatistic& failedLiftStatistic);
00174                         inline void     logFailedLift(FailedLiftStatistic& failedLiftStatistic, int jacobianRank);
00181                         inline void printFailedLiftStatistic( std::ostream & os)        const;
00182 
00183 
00185                          void   printMinLiftPointStatistic( std::ostream & os)  const;
00186                         //void  printLiftPointStatistic( std::ostream & os)     const;
00187                 
00191                          void   printSummedMinLiftPointStatistic( std::ostream & os ) const;
00192 
00195                          void   printSummedAverageMinLiftPointStatistic( std::ostream & os ) const;
00196                 
00197                         //void printHitStatistic        ( std::ostream & os ) const;
00198         
00199                          void   print( std::ostream & os )      const;
00200         
00202         };
00203 
00204 
00205         inline void     ExtendedFailedLiftStatistic::logFailedLift(FailedLiftStatistic& failedLiftStatistic, int jacobianRank)
00206         {
00207                 //failedLiftStatisticList_m.push_back(std::pair< failedLiftStatistic, jacobianRank >);
00208                 bMaxLiftAndLiftTrialsIinitialized_m=false;
00209 
00210                 failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.find(jacobianRank);
00211                 if (it == failedLiftStatisticMap_m.end() )
00212                         failedLiftStatisticMap_m[jacobianRank]=std::vector<FailedLiftStatistic >();
00213                 failedLiftStatisticMap_m[jacobianRank].push_back(  failedLiftStatistic);
00214         }
00215 
00216 
00217 
00218         
00219         // Auswertung1: zähle Über alle Punkte das Minimum fuer einen Aufgetretenen wert.
00220         // Ausgabe; für alle liftNr gib aus Minimum ( der Anzahl des Auftretens von FailLiftNr <=liftNr ) gebildet über alle Punkte.
00221         
00222         // Auswertung 2: für jeden munt minLift. ermitteln. zähle für alle mögliche minLifts, bei wieviel Punkten dieser minLift auftritt.
00223         
00225         template <class FailedLiftStatisticVector>
00226         std::vector<FailedLiftStatistic >    ExtendedFailedLiftStatistic::getLiftStatisticEvaluatedList(FailedLiftStatisticVector       & failedLiftStatisticList) const
00227         {
00228 
00229                 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00230                 std::vector<FailedLiftStatistic >  failedLiftStatisticEvaluatedList ;
00231                 failedLiftStatisticEvaluatedList.clear();
00232         
00233                 for (size_t i=0;i<failedLiftStatisticList.size(); i++)
00234                 {
00235                         const FailedLiftStatistic& tmp = failedLiftStatisticList[i];
00236                         failedLiftStatisticEvaluatedList.push_back(  FailedLiftStatistic( maxLift_m, liftTrials_m ) );
00237         
00238                         int32_t failedLiftCount=0;
00239         
00240                         for (unsigned int currMaxLift=1; currMaxLift<= tmp.getMaxLift(); currMaxLift++)
00241                         {
00242                                 failedLiftCount += tmp.getFailedLiftCount( currMaxLift );
00243                                 //std::cerr << "currMaxLift " << currMaxLift << std::endl;
00244                                 //std::cerr << "failedLiftCount " << failedLiftCount << std::endl;
00245                                 // das funktioniert so nicht
00246                                 failedLiftStatisticEvaluatedList[i].setFailedLiftCount(currMaxLift, failedLiftCount );
00247                         }
00248                 }
00249                 return failedLiftStatisticEvaluatedList;
00250         }
00251         
00252         template <class FailedLiftStatisticVector> 
00253         unsigned int ExtendedFailedLiftStatistic::getMaxLift(FailedLiftStatisticVector          & failedLiftStatisticList ) const
00254         {
00255                 unsigned int maxLift=0;
00256                 if (failedLiftStatisticList.size()>0)
00257                 {
00258                         maxLift=failedLiftStatisticList[0].getMaxLift();
00259                         #ifdef SAFE
00260                                 for (size_t i=1; i<failedLiftStatisticList.size(); i++ )
00261                                 {
00262                                         assert( maxLift    == failedLiftStatisticList[i].getMaxLift() );
00263                                 }
00264                         #endif
00265                 }
00266                 return maxLift;
00267         }
00268         
00269         template <class FailedLiftStatisticVector> 
00270         unsigned int ExtendedFailedLiftStatistic::getLiftTrials(FailedLiftStatisticVector               & failedLiftStatisticList ) const
00271         {
00272 
00273                 unsigned int liftTrials=0;
00274 
00275                 if (failedLiftStatisticList.size()>0)
00276                 {
00277                         liftTrials=failedLiftStatisticList[0].getLiftTrials();
00278                         #ifdef SAFE
00279                                 for (size_t i=1; i<failedLiftStatisticList.size(); i++ )
00280                                 {
00281                                         assert( liftTrials    == failedLiftStatisticList[i].getLiftTrials() );
00282                                 }
00283                         #endif
00284                 }
00285                 return liftTrials;
00286         }
00287 
00288         template <class FailedLiftStatisticVector>
00289         std::vector<int>        ExtendedFailedLiftStatistic::getMinLiftAllStatistic(FailedLiftStatisticVector           & failedLiftStatisticList ) const
00290         {
00291 
00292                 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00293 
00294                 std::vector<int> minSumLiftInfo;
00295                 minSumLiftInfo.clear();
00296         
00297                 if (failedLiftStatisticList.size()==0)
00298                         return  minSumLiftInfo;
00299                 
00300 
00301                 minSumLiftInfo.resize(maxLift_m + 1, 0);
00302         
00303                 std::vector< FailedLiftStatistic >      evaluatedList=getLiftStatisticEvaluatedList(failedLiftStatisticList  );
00304                 
00305                 for (unsigned int currLift=1; currLift<=maxLift_m; currLift++)
00306                 {
00307                         short minOccurred=evaluatedList[0].getFailedLiftCount(currLift);
00308                         for (size_t i=1; i< evaluatedList.size(); i++ )
00309                         {
00310                                 if (evaluatedList[i].getFailedLiftCount(currLift) < minOccurred)
00311                                         minOccurred = evaluatedList[i].getFailedLiftCount(currLift);
00312                         }
00313                         minSumLiftInfo[currLift] = minOccurred;
00314                 }
00315                 return minSumLiftInfo;
00316         }
00317         
00318         inline void ExtendedFailedLiftStatistic::initMaxLiftAndLiftTrials() const
00319         {
00320                 failedLiftStatisticList_m.clear();
00321                 for (failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.begin(); it!=failedLiftStatisticMap_m.end(); it++)
00322                 {
00323                                 for (size_t i=0;i< (*it).second.size(); i++)
00324                                         failedLiftStatisticList_m.push_back( (*it).second[i] );
00325                 }
00326 
00327                 maxLift_m               =  getMaxLift(failedLiftStatisticList_m);
00328                 liftTrials_m    =  getLiftTrials(failedLiftStatisticList_m);
00329                 bMaxLiftAndLiftTrialsIinitialized_m = true;
00330         }
00331         
00332         
00333         template <class FailedLiftStatisticVector>
00334         std::vector<double>     ExtendedFailedLiftStatistic::getAverageLiftAllStatistic(FailedLiftStatisticVector       & failedLiftStatisticList) const
00335         {
00336                 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00337                 std::vector<double> avereageLiftInfo;
00338         
00339                 avereageLiftInfo.clear();
00340                 if (failedLiftStatisticList.size()==0)
00341                         return  avereageLiftInfo;
00342                 
00343 
00344                 avereageLiftInfo.resize(maxLift_m+1, 0);
00345         
00346                 std::vector< FailedLiftStatistic >      evaluatedList=getLiftStatisticEvaluatedList(failedLiftStatisticList);
00347                 
00348                 //std::cerr << "failedLiftStatisticEvaluatedList_m.size() " << failedLiftStatisticEvaluatedList_m.size() << std::endl;
00349                 //std::cerr << "failedLiftStatisticList_m[0].getLiftTrials() " <<failedLiftStatisticList_m[0].getLiftTrials() << std::endl;
00350         
00351                 for (int currLift=1; currLift<=maxLift_m; currLift++)
00352                 {
00353                         for (size_t currentNonsmoothPointIdx =0; currentNonsmoothPointIdx < evaluatedList.size(); currentNonsmoothPointIdx++ )
00354                         {
00355                                 avereageLiftInfo[currLift] += evaluatedList[currentNonsmoothPointIdx].getFailedLiftCount( currLift );
00356                         }
00357                         //std::cerr << "currLift  " << currLift << std::endl;
00358                         //std::cerr << "avereageLiftInfo_m[currLift]  " << avereageLiftInfo_m[currLift] << std::endl;
00359                         avereageLiftInfo[currLift] /= evaluatedList.size()*1.0;
00360                         avereageLiftInfo[currLift]/=  failedLiftStatisticList[0].getLiftTrials();
00361                 }
00362                 return avereageLiftInfo;
00363         }
00364         
00365         template <class FailedLiftStatisticVector>
00366         std::vector<int>        ExtendedFailedLiftStatistic::getMinLiftPointStatistic(FailedLiftStatisticVector  & failedLiftStatisticList) const
00367         {
00368                 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00369                 std::vector<int> minLiftInfo;
00370                 minLiftInfo.clear(); 
00371         
00372                 if (failedLiftStatisticList.size()==0) 
00373                         return minLiftInfo;
00374                 
00375                 std::cerr << "getMinLiftPointStatistic, maxLift" <<  maxLift_m << std::endl;
00376                 
00377                 minLiftInfo.resize( maxLift_m + 1 ,0 );
00378         
00379                 for (size_t failedLiftPointIdx=0;failedLiftPointIdx<failedLiftStatisticList.size(); failedLiftPointIdx++)
00380                 {
00381                         assert( failedLiftStatisticList[failedLiftPointIdx].getMinFailedLiftNr() < minLiftInfo.size() );
00382                         minLiftInfo[ failedLiftStatisticList[failedLiftPointIdx].getMinFailedLiftNr() ] ++;
00383                 }
00384                 return minLiftInfo;
00385         }
00386 
00387         
00388         template <class FailedLiftStatisticVector>
00389         std::string ExtendedFailedLiftStatistic::getFailedLiftStatisticValue(  FailedLiftStatisticVector   & failedLiftStatisticList    )       const
00390         {
00391 
00392                 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00393                 std::stringstream strstream;
00394         
00395                 if (failedLiftStatisticList.size()==0) 
00396                         return std::string("{}");
00397                  
00398                 std::cerr << "getFailedLiftStatisticValue, maxLift" <<  maxLift_m << std::endl;
00399         
00400                 std::cerr << "getFailedLiftStatisticValue, liftTrials" <<  liftTrials_m << std::endl;
00401 
00402                 FailedLiftStatistic localFailedLiftStatistic(maxLift_m, liftTrials_m);
00403         
00404                 for (size_t i=0;i<failedLiftStatisticList.size();i++)
00405                 {
00406                         localFailedLiftStatistic += failedLiftStatisticList[i];
00407                 }
00408         
00409                 strstream << "  {" ;
00410         
00411                 bool first=true;
00412         
00413                 for (unsigned int i=1; i<=maxLift_m; i++ )
00414                 {
00415                         if (localFailedLiftStatistic.getFailedLiftCount(i)      >0 )
00416                         {
00417                                 if (! first)
00418                                         strstream << "," ;
00419                                 else
00420                                         first=false;
00421                                 strstream << "\t( " << std::setw(3) << i <<", " << std::setw(5) <<      localFailedLiftStatistic.getFailedLiftCount(i) << "\t )\n";
00422                         }
00423                 }
00424                 strstream << "}"<< std::endl;
00425                 return strstream.str();
00426                 }
00427         
00428         
00429 
00430 }
00431 
00432 #endif
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3