LiftStatistic.cpp
Go to the documentation of this file.00001
00002 #include "LiftStatistic.h"
00003 #include <sstream>
00004
00005 namespace nCenterFocus
00006 {
00007
00008 FailedLiftStatistic::FailedLiftStatistic
00009 (unsigned int maxLift, unsigned int liftTrials): failedLiftTrialCount( 0 ),
00010 maxLift_m( maxLift ),
00011 liftTrials_m( liftTrials ),
00012 testFailureCount_m(0)
00013 {
00014 failedLiftCount_m.clear();
00015 failedLiftCount_m.resize(maxLift+1, 0 );
00016 }
00017
00018
00019 FailedLiftStatistic::FailedLiftStatistic( ): failedLiftTrialCount( 0 ),
00020 maxLift_m( 0 ),
00021 liftTrials_m( 0 ),
00022 testFailureCount_m(0)
00023 {
00024 failedLiftCount_m.clear();
00025 failedLiftCount_m.resize(maxLift_m+1, 0 );
00026 }
00027
00028
00029 unsigned int FailedLiftStatistic::getMaxLift() const
00030 {
00031 return maxLift_m;
00032 }
00033
00034 unsigned int FailedLiftStatistic::getLiftTrials() const
00035 {
00036 return liftTrials_m;
00037 }
00038
00039 void FailedLiftStatistic::logFailedLift(int currentLiftNr)
00040 {
00041 failedLiftCount_m[currentLiftNr]++;
00042 failedLiftTrialCount++;
00043 assert(failedLiftTrialCount<=liftTrials_m);
00044 }
00045
00046
00047 void FailedLiftStatistic::operator+=(const FailedLiftStatistic & summand)
00048 {
00049 assert(summand.getMaxLift()==maxLift_m);
00050 assert(summand.getLiftTrials()==liftTrials_m);
00051 for (unsigned int currentLiftNr=1; currentLiftNr<=maxLift_m; currentLiftNr++)
00052 {
00053 failedLiftCount_m[currentLiftNr]+= summand.failedLiftCount_m[currentLiftNr];
00054 failedLiftTrialCount += summand.failedLiftCount_m[currentLiftNr];
00055 }
00056 testFailureCount_m += summand.testFailureCount_m;
00057 }
00058
00059
00060 int32_t FailedLiftStatistic::getFailedLiftCount(unsigned int liftNr) const
00061 {
00062 assert( liftNr <= maxLift_m );
00063 return failedLiftCount_m[liftNr];
00064 }
00065
00066
00067 void FailedLiftStatistic::setTestFailureCount()
00068 {
00069 assert(failedLiftTrialCount>0);
00070 assert(liftTrials_m - failedLiftTrialCount>=0);
00071 testFailureCount_m= liftTrials_m - failedLiftTrialCount;
00072 }
00073
00074
00075 int32_t FailedLiftStatistic::getTestFailureCount() const
00076 {
00077
00078 return testFailureCount_m;
00079 }
00080
00081 void FailedLiftStatistic::setFailedLiftCount(unsigned int liftNr, int32_t count)
00082 {
00083 assert( liftNr<=maxLift_m);
00084 failedLiftCount_m[liftNr] = count;
00085 }
00086
00087 unsigned short FailedLiftStatistic::getMinFailedLiftNr() const
00088 {
00089 if (failedLiftCount_m.size()==0)
00090 return 0;
00091
00092 size_t minFailedLiftNr= failedLiftCount_m.size();
00093
00094 for (size_t i=1; i<failedLiftCount_m.size(); i++)
00095 {
00096 if ( failedLiftCount_m[i]>0 )
00097 {
00098 minFailedLiftNr = i;
00099 break;
00100 }
00101 }
00102 if ( minFailedLiftNr== failedLiftCount_m.size() )
00103 return 0;
00104
00105 return minFailedLiftNr;
00106 }
00107
00108
00109 void FailedLiftStatistic::print(std::ostream & os) const
00110 {
00111 os << "FailedLiftStatistic = {" << std::endl ;
00112 os << "-- liftTrials= " << liftTrials_m << std::endl;
00113 os << getTestFailureCount() << ", -- Anzahl( Test hat versagt)" << std::endl;
00114 bool first=true;
00115 for (unsigned int i=1; i<=maxLift_m;i++)
00116 {
00117 if (failedLiftCount_m[i]>0)
00118 {
00119 if (first)
00120 first=false;
00121 else
00122 os << "," ;
00123
00124 os << "( " << i <<", " << failedLiftCount_m[i] << "\t\t )\n";
00125 }
00126 }
00127 os << "};"<< std::endl;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137 ExtendedFailedLiftStatistic::ExtendedFailedLiftStatistic(): maxLift_m(0), liftTrials_m(0), bMaxLiftAndLiftTrialsIinitialized_m(false)
00138 {
00139
00140 }
00141
00142
00143 void ExtendedFailedLiftStatistic::printFailedLiftStatistic( std::ostream & os ) const
00144 {
00145 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00146
00147 os << "ExtFailedLiftStatistic = { \n " ;
00148
00149 std::string rankIndependentLiftStatistic=getFailedLiftStatisticValue( failedLiftStatisticList_m );
00150
00151
00152
00153 os << "--maxLift = " << maxLift_m << ";" << std::endl;
00154 os << "--liftTrials = " << liftTrials_m << ";" << std::endl;
00155
00156 os << rankIndependentLiftStatistic;
00157
00158
00159 for (failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.begin(); it!=failedLiftStatisticMap_m.end(); it++)
00160 {
00161 if (it!=failedLiftStatisticMap_m.begin() )
00162 os << ",";
00163 else
00164 os << " ";
00165 os << "{" << (*it).first << ", " << getFailedLiftStatisticValue( (*it).second ) << "}";
00166 }
00167
00168 os << "};";
00169 }
00170
00171
00172
00173
00174 void ExtendedFailedLiftStatistic::printMinLiftPointStatistic( std::ostream & os) const
00175 {
00176
00177 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00178
00179
00180 std::vector<int> minLiftInfo = getMinLiftPointStatistic( failedLiftStatisticList_m );
00181
00182 os << "minLiftDepthOccurenceCount = {" ;
00183
00184 os << "--maxLift = " << maxLift_m << ";" << std::endl;
00185 os << "--liftTrials = " << liftTrials_m << ";" << std::endl;
00186 os << "--Format: (minLift, #Points with this minLift )" << std::endl;
00187
00188 os << getMinLiftPointStatisticValue(minLiftInfo);
00189
00190 for (failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.begin(); it!=failedLiftStatisticMap_m.end(); it++)
00191 {
00192 if ( it!=failedLiftStatisticMap_m.begin() )
00193 os << ",";
00194 else
00195 os << " ";
00196 os << "{"<< (*it).first << "," << std::endl;
00197 minLiftInfo= getMinLiftPointStatistic( (*it).second );
00198 os << getMinLiftPointStatisticValue(minLiftInfo);
00199 os << "}\n";
00200 }
00201 os << "};"<< std::endl;
00202 }
00203
00204
00205
00206 void ExtendedFailedLiftStatistic::printSummedMinLiftPointStatistic( std::ostream & os ) const
00207 {
00208
00209 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00210
00211
00212 std::vector<int> minLiftInfo = getMinLiftAllStatistic( failedLiftStatisticList_m );
00213
00214 os << "minFailedTrialsForeachLiftDepth = {\n" ;
00215
00216 os << "--maxLift = " << maxLift_m << ";" << std::endl;
00217 os << "--liftTrials = " << liftTrials_m << ";" << std::endl;
00218 os << "--Format: (minLift, #minFailedTrials over all points )" << std::endl;
00219
00220 os << getMinLiftPointStatisticValue(minLiftInfo);
00221
00222 for (failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.begin(); it!=failedLiftStatisticMap_m.end(); it++)
00223 {
00224 if (it!=failedLiftStatisticMap_m.begin() )
00225 os << ",";
00226 else
00227 os << " ";
00228
00229 os << "{"<< (*it).first << "," << std::endl;
00230 minLiftInfo= getMinLiftAllStatistic( (*it).second );
00231 os << getMinLiftPointStatisticValue(minLiftInfo);
00232 os << "}\n";
00233 }
00234 os << "};"<< std::endl;
00235 }
00236
00237
00238
00239 void ExtendedFailedLiftStatistic::printSummedAverageMinLiftPointStatistic( std::ostream & os ) const
00240 {
00241 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00242
00243
00244 std::vector<double> avereageLiftInfo = getAverageLiftAllStatistic( failedLiftStatisticList_m );
00245
00246 os << "averageFailedTrialProbability = { -- for given maxLiftDepth and one liftTrial \n" ;
00247
00248 os << "--maxLift = " << maxLift_m << ";" << std::endl;
00249 os << "--liftTrials = " << liftTrials_m << ";" << std::endl;
00250 os << "-- average probability of failing to identify a nonsmooth point with X liftrials is prob^X " << std::endl;
00251 os << "-- Format : (maxLift, FailedTrialProbability )" << std::endl;
00252
00253 os << getAverageLiftStatisticValue(avereageLiftInfo);
00254
00255 for (failedLiftStatisticMapType::const_iterator it=failedLiftStatisticMap_m.begin(); it!=failedLiftStatisticMap_m.end(); it++)
00256 {
00257 if (it!=failedLiftStatisticMap_m.begin() )
00258 os << ",";
00259 else
00260 os << " ";
00261
00262 os << "{"<< (*it).first << ", -- JacobianRank" << std::endl;
00263 avereageLiftInfo= getAverageLiftAllStatistic( (*it).second );
00264 os << getAverageLiftStatisticValue(avereageLiftInfo);
00265 os << "}\n";
00266 }
00267 os << "};"<< std::endl;
00268 }
00269
00270
00271 void ExtendedFailedLiftStatistic::print( std::ostream & os ) const
00272 {
00273 initMaxLiftAndLiftTrials();
00274 assert(bMaxLiftAndLiftTrialsIinitialized_m);
00275 printFailedLiftStatistic(os);
00276 printMinLiftPointStatistic(os);
00277 printSummedMinLiftPointStatistic(os);
00278 printSummedAverageMinLiftPointStatistic(os);
00279 }
00280
00281
00282
00283 std::string ExtendedFailedLiftStatistic::getMinLiftPointStatisticValue(std::vector<int> &minLiftInfo) const
00284 {
00285 std::stringstream strstream;
00286
00287 bool first=true;
00288
00289 strstream << "{"<< std::endl;
00290 for (size_t i=0; i<minLiftInfo.size(); i++ )
00291 {
00292 if (minLiftInfo[i]>0)
00293 {
00294 if (!first)
00295 strstream << "," ;
00296 else
00297 {
00298 strstream << " " ;
00299 first=false;
00300 }
00301
00302 strstream << "\t( " << std::setw(3) << i <<", " << std::setw(5) << minLiftInfo[i] << "\t )\n";
00303 }
00304 }
00305 strstream << "}"<< std::endl;
00306
00307 return strstream.str();
00308 }
00309
00310
00311 std::string ExtendedFailedLiftStatistic::getAverageLiftStatisticValue(std::vector<double> & averageLiftInfo) const
00312 {
00313 std::stringstream strstream;
00314
00315 bool first=true;
00316
00317 strstream << "{"<< std::endl;
00318 for (size_t i=0; i < averageLiftInfo.size(); i++ )
00319 {
00320 if (averageLiftInfo[i]>0)
00321 {
00322 if (!first)
00323 strstream << "," ;
00324 else
00325 {
00326 strstream << " " ;
00327 first=false;
00328 }
00329
00330 strstream << "( " << std::setw(3)<< i <<", " << std::setw(10) << 1.0- averageLiftInfo[i] << "\t ) -- " << "1 of " << 1.0/(1.0- averageLiftInfo[i] ) << " is not identified \n";
00331 }
00332 }
00333 strstream << "}"<< std::endl;
00334
00335 return strstream.str();
00336 }
00337
00338
00339
00340
00341
00342 };
00343