Statistik.cpp

Go to the documentation of this file.
00001 // Statistik.cpp: Implementierung der Klasse Statistik.
00002 //
00004 
00005 #include <stdlib.h>
00006 
00007 
00008  namespace nCenterFocus
00009 {
00010         
00011 
00012 long64 incrementLong64(long64 i)
00013 {
00014         return ++i;
00015 }
00016 
00027 template <bool safe>
00028 Statistic<safe>::Statistic(     int maxExpectedNumOfVanishedFocalValuesToLog, 
00029                                         int startAt
00030                                         )
00031                                                 :       startAt_m       ( startAt ),
00032                                                         arrayLength     ( maxExpectedNumOfVanishedFocalValuesToLog      +1),
00033                                                         values ( new long64[maxExpectedNumOfVanishedFocalValuesToLog + 1] )
00034 {
00035         assert(startAt<=3 && startAt>=0 && startAt<arrayLength);
00036         assert(maxExpectedNumOfVanishedFocalValuesToLog>=0);
00037         clear();
00038 }
00039 
00040 
00041 template <bool safe>
00042 Statistic<safe>::Statistic(const Statistic & st): 
00043                                                                 startAt_m       ( st.startAt_m   ), 
00044                                                                 arrayLength     ( st.arrayLength ),
00045                                                                 values  ( new long64[arrayLength] )
00046 {
00047         //clear();
00048 
00049         std::copy(      &(st.values[0] ),       & ( st.values[ arrayLength ] ),
00050                                 values);
00051 
00052 }
00053 
00054 
00055 template <bool safe>
00056 inline  void    Statistic<safe>::testbounds(int maxbound)       const
00057 {
00058         if (safe)
00059                 assert( maxbound<arrayLength && maxbound>=0);
00060 }
00061 
00062 
00063 template <bool safe>
00064 Statistic<safe> &        Statistic<safe>::operator=(const Statistic & st)
00065 {
00066         if ( this!=&st )
00067         {
00068                 assert(&st!=NULL);
00069 
00070                 arrayLength      = st.arrayLength;
00071                 startAt_m = st.startAt_m;        
00072                 
00073                 if (values!=NULL) delete[] values;
00074 
00075                 values = new long64[arrayLength];
00076 
00077                 std::copy(      &(st.values[0] ),       & ( st.values[ arrayLength ] ),
00078                                 values
00079                 );
00080 
00081         }
00082         return *this;
00083 }
00084 
00085 
00086 template <bool safe>
00087 void Statistic<safe>::clear()
00088 {
00089                 std::fill(      &(values[0] ),
00090                                 & ( values[ arrayLength ] ),
00091                                 0 
00092                         );
00093 }
00094 
00096 template <bool safe>
00097 inline long64 & Statistic<safe>::getStatisticEntryRef(int index)
00098 {
00099         if (safe)
00100                 testbounds(index);
00101         return values[index];
00102 }
00103 
00105 template <bool safe>
00106 inline  long64  Statistic<safe>::getStatisticEntry(int index)   const
00107 {
00108         if (safe)
00109                 testbounds(index);
00110         return values[index];
00111 }
00112 
00113 
00114 
00116 template <bool safe>
00117 long64 Statistic<safe>::getTrialCountWithGivenNumOfFirstSuccessiveVanishedFocalValues(int FirstSuccessiveVanishedFocalValues)
00118 {
00119         return getStatisticEntry(FirstSuccessiveVanishedFocalValues);           
00120 }
00121 
00122 template <bool safe>
00123 void Statistic<safe>::addStatistic(int successiveStrudelZeroCount)
00124 {
00125         for (int currentFocalValueIndex = startAt_m; currentFocalValueIndex<= successiveStrudelZeroCount; currentFocalValueIndex++)
00126                 getStatisticEntryRef(currentFocalValueIndex) ++;
00127 
00128         // alternative:
00129         // if (safe)            testbounds(successiveStrudelZeroCount);
00130         //std::transform( &values[startAt], &values[ successiveStrudelZeroCount+1 ], incrementLong64 );
00131 }
00132 
00133 template <bool safe>
00134 void Statistic<safe>::addFormula1Try(int characteristic)
00135 {        
00136         if (safe)       
00137                 assert(startAt_m==1);
00138         
00139         getStatisticEntryRef(0) += characteristic;
00140 }
00141 
00142 template <bool safe>
00143 void Statistic<safe>::addFormula1And2Try(int characteristic)
00144 {       
00145         if (safe)       
00146                 assert(startAt_m==2);
00147         
00148         getStatisticEntryRef(0) += characteristic*characteristic;
00149         getStatisticEntryRef(1) += characteristic;
00150 }
00151 
00152 
00153 template <bool safe>
00154 void Statistic<safe>::addFormula1And23Try(int characteristic)
00155 {       
00156         if (safe)
00157                 assert(startAt_m==3);
00158 
00159         getStatisticEntryRef(0) += characteristic*characteristic*characteristic;
00160         getStatisticEntryRef(1) += characteristic*characteristic;
00161 }
00162 
00163 
00165 template <bool safe>
00166 void Statistic<safe>::correctSecondFocalValueStatistic(int vanishedTrials)
00167 {       
00168         if (safe)
00169                 assert(startAt_m==3);
00170 
00171         this->getStatisticEntryRef(2) += vanishedTrials;
00172 }
00173 
00174  
00175 
00176 template <bool safe>
00177 long64  Statistic<safe>::getTrialCount()
00178 {
00179         return getStatisticEntry(0);
00180 }
00181 
00182 template <bool safe>
00183 int  Statistic<safe>::getMaxLoggedSuccessiveVanishedFocalValues()
00184 {
00185         return arrayLength-1;
00186 }
00187 
00189 template <bool safe>
00190 void Statistic<safe>::correctHamiltonComponentStatistic(int focalValueNum, int hamiltonianPointCount    )
00191 {
00192         assert(getMaxLoggedSuccessiveVanishedFocalValues() >=focalValueNum && focalValueNum>=0);
00193         for (int currFocalValueNum=0;currFocalValueNum<arrayLength;currFocalValueNum++)
00194                 getStatisticEntryRef(currFocalValueNum) = hamiltonianPointCount;
00195 }
00196 
00197 
00200 template <bool safe>
00201 void Statistic<safe>::correctNonHamiltonComponentStatistic(int focalValueNum, int vanishedFocalValuesToSubtract )
00202 {
00203         assert(getMaxLoggedSuccessiveVanishedFocalValues() >=focalValueNum);
00204         for (int currFocalValueNum=0;currFocalValueNum<focalValueNum;currFocalValueNum++)
00205                 getStatisticEntryRef(currFocalValueNum)-=vanishedFocalValuesToSubtract;
00206 }
00207 
00208 
00212 template <bool safe>
00213 void Statistic<safe>::print(ostream& o)
00214 {
00215         o << "Statistic = { ";
00216 
00217         o << this->getTrialCount();
00218 
00219         for (int currentFocalValueIndex=1; currentFocalValueIndex<= getMaxLoggedSuccessiveVanishedFocalValues(); currentFocalValueIndex++)
00220         {
00221                 o << ", ";
00222                 o << this->getTrialCountWithGivenNumOfFirstSuccessiveVanishedFocalValues(currentFocalValueIndex);
00223         }
00224                 
00225         o << " }; -- first number: trial count; i.th number: count of trials where the first i focal values vanished " << std::endl;
00226 }
00227 
00228 template <bool safe>
00229 Statistic<safe>::~Statistic()
00230 {
00231         delete[] values;
00232 }
00233 
00234 
00235 };
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3