00001
00002
00004
00005 #include "RangStatistik.h"
00006 #include <stdlib.h>
00007 #include <assert.h>
00008 #include <sstream>
00010
00012
00013 namespace nCenterFocus
00014 {
00015
00016
00018 std::string getMacaulayCompilantObjectName(const std::string &strref)
00019 {
00020 std::stringstream testame(strref);
00021 std::string macaulayCompilantName;
00022 std::string tmp;
00023 while (testame >> tmp >> std::ws)
00024 {
00025 macaulayCompilantName += tmp;
00026 }
00027
00028 if (macaulayCompilantName.length()==0)
00029 macaulayCompilantName=std::string("fullOrSubRankStatistic");
00030 assert( macaulayCompilantName.length()>0);
00031 return macaulayCompilantName;
00032 }
00033
00034
00035
00036
00037
00038 const std::string BaseRankStatistic::fullRankStatisticString("fullRankStatistic");
00039 const std::string BaseRankStatistic::subRankStatisticString("subRankStatistic");
00040
00048
00058 BaseRankStatistic::BaseRankStatistic( std::string name,
00059 int _requestedMinSuccessiveVanishedFocalValues,
00060 int _maxFocalValuesToCompute,
00061 int _maxRank
00062 ):
00063 name_m(name),
00064 maxRank(_maxRank),
00065 maxFocalValuesToCompute(_maxFocalValuesToCompute),
00066 minSuccessiveZeroFocalValues(_requestedMinSuccessiveVanishedFocalValues),
00067 exactVanishedFocalValuesStatistic_m(new long64[_maxFocalValuesToCompute+1] )
00068 {
00069
00070 assert(_requestedMinSuccessiveVanishedFocalValues>=0 && _maxFocalValuesToCompute>=0 && _maxRank>=0 );
00071 init();
00072 }
00073
00074
00075 BaseRankStatistic::BaseRankStatistic(const BaseRankStatistic& ref
00076 ): name_m( ref.name_m ),
00077 maxRank( ref.maxRank ),
00078 maxFocalValuesToCompute( ref.maxFocalValuesToCompute ),
00079 minSuccessiveZeroFocalValues( ref.minSuccessiveZeroFocalValues ),
00080 exactVanishedFocalValuesStatistic_m( new long64[ref.maxFocalValuesToCompute+1] )
00081 {
00082 init();
00083
00084 std::copy( & (ref.exactVanishedFocalValuesStatistic_m[0]),
00085 & (ref.exactVanishedFocalValuesStatistic_m[ maxFocalValuesToCompute +1]),
00086 exactVanishedFocalValuesStatistic_m
00087 );
00088
00089
00090 std::copy( &(ref.jacobianRankCounters_m[0]),
00091 &(ref.jacobianRankCounters_m[arrayLength+1]),
00092 jacobianRankCounters_m
00093 );
00094
00095 }
00096
00097
00098
00099
00101 BaseRankStatistic& BaseRankStatistic::operator=(const BaseRankStatistic& ref)
00102 {
00103 if (&ref != this)
00104 {
00105 delete[] jacobianRankCounters_m;
00106 delete[] exactVanishedFocalValuesStatistic_m;
00107
00108 name_m = ref.name_m;
00109 maxRank = ref.maxRank;
00110
00111 maxFocalValuesToCompute = ref.maxFocalValuesToCompute;
00112 minSuccessiveZeroFocalValues = ref.minSuccessiveZeroFocalValues;
00113
00114 exactVanishedFocalValuesStatistic_m= new long64[maxFocalValuesToCompute+1];
00115 init();
00116
00117 std::copy( & (ref.exactVanishedFocalValuesStatistic_m[0]),
00118 & (ref.exactVanishedFocalValuesStatistic_m[ maxFocalValuesToCompute+1 ]),
00119 exactVanishedFocalValuesStatistic_m
00120 );
00121
00122 std::copy( &( ref.jacobianRankCounters_m[0] ),
00123 &( ref.jacobianRankCounters_m[arrayLength+1] ),
00124 jacobianRankCounters_m
00125 );
00126
00127 }
00128 return *this;
00129 }
00130
00131
00132 inline void BaseRankStatistic::testbounds(int maxbound) const
00133 {
00134 assert( maxbound<=arrayLength);
00135 }
00136
00137 void BaseRankStatistic::init()
00138 {
00139 if (maxFocalValuesToCompute-minSuccessiveZeroFocalValues+1<=0)
00140 {
00141 std::cerr << "maxFocalValues is smaller than minSuccessiveZeroFocalValues + 1:" << std::endl;
00142 std::cerr << "maxFocalValuesToCompute =" << maxFocalValuesToCompute << std::endl;
00143 std::cerr << "minSuccessiveZeroFocalValues =" << minSuccessiveZeroFocalValues << std::endl;
00144 exit(0);
00145 }
00146 arrayLength = (maxRank+1)*(maxFocalValuesToCompute-minSuccessiveZeroFocalValues+1);
00147 assert( maxRank>0);
00148
00149 jacobianRankCounters_m = new long64[ arrayLength+1 ];
00150 clear();
00151 }
00152
00153 void BaseRankStatistic::clear()
00154 {
00155
00156 std::fill( & (exactVanishedFocalValuesStatistic_m[0]),
00157 & (exactVanishedFocalValuesStatistic_m[ maxFocalValuesToCompute+1 ]),
00158 0
00159 );
00160
00161 std::fill( &( jacobianRankCounters_m[0] ),
00162 &( jacobianRankCounters_m[arrayLength+1] ),
00163 0
00164 );
00165 }
00166
00167
00168 BaseRankStatistic::~BaseRankStatistic()
00169 {
00170 delete[] jacobianRankCounters_m;
00171 }
00172
00173
00174 int BaseRankStatistic::getSmallesLoggedNumOfVanishedFocalValues() const
00175 {
00176 return minSuccessiveZeroFocalValues;
00177 }
00178
00179
00180
00181 int BaseRankStatistic::getHighestLoggedNumOfVanishedFocalValues() const
00182 {
00183 return maxFocalValuesToCompute;
00184 }
00185
00186
00187 int BaseRankStatistic::getHighestLoggedJacobianRank() const
00188 {
00189 return maxRank;
00190 }
00191
00192 long64 BaseRankStatistic::getJacobianRankCounter(int index) const
00193 {
00194 #ifdef SAFE
00195 testbounds( index );
00196 #endif
00197 return jacobianRankCounters_m[index];
00198 }
00199
00200
00201 long64& BaseRankStatistic::getJacobianRankCounterRef(int index)
00202 {
00203 #ifdef SAFE
00204 testbounds( index );
00205 #endif
00206 return jacobianRankCounters_m[index];
00207 }
00208
00209
00210
00211 int BaseRankStatistic::getRankStatisticIndex(int successiveVanishedNum, int jacobianRank) const
00212 {
00213 if (! (jacobianRank<=maxRank && jacobianRank>=0))
00214 {
00215 std::cerr << "jacobianRank " << jacobianRank << std::endl;
00216 std::cerr << "maxRank " << maxRank << std::endl;
00217 assert(jacobianRank<=maxRank && jacobianRank>=0);
00218 }
00219 if (!(successiveVanishedNum<=maxFocalValuesToCompute &&
00220 successiveVanishedNum>=minSuccessiveZeroFocalValues))
00221 {
00222 std::cerr << "successiveVanishedFocalValues "<<successiveVanishedNum << std::endl;
00223 std::cerr << "maxFocalValuesToCompute "<<maxFocalValuesToCompute <<std::endl;
00224 std::cerr <<" minSuccessiveZeroFocalValues "<<minSuccessiveZeroFocalValues << std::endl;
00225 }
00226
00227 assert(successiveVanishedNum<=maxFocalValuesToCompute &&
00228 successiveVanishedNum>=minSuccessiveZeroFocalValues);
00229
00230 return (successiveVanishedNum-minSuccessiveZeroFocalValues)*(maxRank+1)+jacobianRank ;
00231 }
00232
00233
00234 long64 BaseRankStatistic::getOccurenceWithGivenNumOfVanishedFocalValues(int successiveVanishedNum) const
00235 {
00236 assert(successiveVanishedNum<=maxFocalValuesToCompute &&
00237 successiveVanishedNum>=minSuccessiveZeroFocalValues);
00238
00239 return exactVanishedFocalValuesStatistic_m [ successiveVanishedNum ];
00240 }
00241
00242
00243 int BaseRankStatistic::getNumOfOccuredJacobianRank(int successiveVanishedNum, int jacobianRank) const
00244 {
00245 return getJacobianRankCounter( getRankStatisticIndex(successiveVanishedNum, jacobianRank) );
00246 }
00247
00248
00249 void BaseRankStatistic::addRankStatistic(int successiveVanishedFocalValues, int jacobianRank)
00250 {
00251
00253
00254 assert(successiveVanishedFocalValues<=maxFocalValuesToCompute &&
00255 successiveVanishedFocalValues>=minSuccessiveZeroFocalValues);
00256
00257 exactVanishedFocalValuesStatistic_m[ successiveVanishedFocalValues ]++;
00258
00260 getJacobianRankCounterRef ( getRankStatisticIndex(successiveVanishedFocalValues, jacobianRank)) ++;
00261 }
00262
00263
00264 std::string BaseRankStatistic::getValueAsString() const
00265 {
00266 std::stringstream ssvalue;
00267
00268 bool firstLine=true;
00269 ssvalue<< "{ ";
00270 for (int vanishedFocalValues=getSmallesLoggedNumOfVanishedFocalValues();
00271 vanishedFocalValues<= getHighestLoggedNumOfVanishedFocalValues();
00272 vanishedFocalValues++ )
00273 {
00274 if (getOccurenceWithGivenNumOfVanishedFocalValues(vanishedFocalValues)>0)
00275 {
00276 if (firstLine)
00277 {
00278 firstLine=false;
00279 }
00280 else
00281 {
00282 ssvalue << ", ";
00283 }
00284 ssvalue << "\n ";
00285 {
00286 ssvalue << "{ " << vanishedFocalValues << ", { ";
00287 ssvalue << getOccurenceWithGivenNumOfVanishedFocalValues(vanishedFocalValues) << ',';
00288 for (int jacobianRank=0; jacobianRank<=maxRank; jacobianRank++)
00289 {
00290 if (jacobianRank>0)
00291 ssvalue << ", ";
00292 ssvalue << getNumOfOccuredJacobianRank(vanishedFocalValues,jacobianRank);
00293 }
00294 ssvalue << " } }";
00295 }
00296 }
00297 }
00298 ssvalue << "\n}";
00299 return ssvalue.str();
00300 }
00301
00302
00303
00311 void BaseRankStatistic::print(std::ostream& os) const
00312 {
00313 os << getMacaulayCompilantObjectName(name_m);
00314 os << " = " << getValueAsString();
00315 os << "; -- Format: ( number of successive vanished focal values,\
00316 {occurrence count, number of jacobi-matrices with rank 0,\
00317 number of jacobi-matrices with rank 1, ..., number of jacobi-matrices with rank 'maxRank'} )";
00318 os << std::endl;
00319 }
00320
00321
00322
00328 RankAndLiftStatistic::RankAndLiftStatistic( std::string name,
00329 int _requestedMinSuccessiveVanishedFocalValues,
00330 int _maxFocalValuesToCompute,
00331 int _maxRank
00332
00333 ) : name_m(name),
00334 rankStatisticPair_m( BaseRankStatistic( name+"_passedLiftTest",
00335 _requestedMinSuccessiveVanishedFocalValues,
00336 _maxFocalValuesToCompute,
00337 _maxRank
00338 ),
00339 BaseRankStatistic( name+"_failedLiftTest",
00340 _requestedMinSuccessiveVanishedFocalValues,
00341 _maxFocalValuesToCompute,
00342 _maxRank
00343 )
00344 )
00345 {}
00346
00347 RankAndLiftStatistic::~RankAndLiftStatistic()
00348 {}
00349
00350 void RankAndLiftStatistic::clear()
00351 {
00352 rankStatisticPair_m.first.clear();
00353 rankStatisticPair_m.second.clear();
00354 }
00355
00356 void RankAndLiftStatistic::addRankStatistic(int successiveVanishedFocalValues, int jacobianRank, bool liftTestPassed)
00357 {
00358 if (liftTestPassed)
00359 rankStatisticPair_m.first.addRankStatistic(successiveVanishedFocalValues,jacobianRank);
00360 else
00361 rankStatisticPair_m.second.addRankStatistic(successiveVanishedFocalValues,jacobianRank);
00362 }
00363
00365 void RankAndLiftStatistic::print(std::ostream &os) const
00366 {
00367 os << getMacaulayCompilantObjectName(name_m) << " = {" << rankStatisticPair_m.first.getValueAsString() ;
00368 os << " , " << rankStatisticPair_m.second.getValueAsString() ;
00369 os << " }; -- Format: {RankstatisticforPassedLiftTest,RankstatisticForFailedLiftTest}, \
00370 RankstatisticFormat: ( number of successive vanished focal values, \
00371 {occurrence count, number of jacobi-matrices with rank 0, \
00372 number of jacobi-matrices with rank 1, ..., number of jacobi-matrices with rank 'maxRank'} )";
00373 os << std::endl;
00374 }
00375
00376
00377 };