Definition at line 120 of file ConfusionMatrix.h. References conceptSimTable, Impala::Core::Table::Bayes::DumpMatrix(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Get1(), Impala::Core::Table::SimilarityTableSet::GetName(), Impala::Core::Table::SimilarityTableSet::GetSimTable(), Impala::Core::Table::AnnotationTableSet::GetTable(), mAnnoTabSet, Impala::Core::Table::Bayes::mConceptNum, Impala::Core::Table::Bayes::mConceptSet, mConceptSimSet, mConfusionMatrix, mFeatureName, mQuidTable, Impala::Core::Table::Bayes::mSetName, Impala::Core::Table::Bayes::mTableSize, SaveConfigurationMatrix(), Impala::Core::Table::TableTem< Col1T, Col2T, Col3T, Col4T, Col5T, Col6T, Col7T, Col8T, Col9T >::Set1(), and Impala::Core::Table::Bayes::tabConcept. 00121 { 00122 std::cout << std::endl; 00123 std::cout << "DumpConfusionMatrix() - my own tool" << std::endl; 00124 std::cout << std::endl; 00125 00126 // load annotation and similarity tables 00127 for (int c=0 ; c< mConceptNum ; c++) 00128 { 00129 tabConcept[c] = mAnnoTabSet->GetTable(c); 00130 00131 std::cout << "table " << c << ", name = " << mConceptSimSet->GetName(c) << std::endl; 00132 conceptSimTable[c] = mConceptSimSet->GetSimTable(c); 00133 } 00134 00135 // get the mean of each concept list 00136 Real64* pMean = new Real64[mConceptNum]; 00137 memset(pMean,0,sizeof(Real64)*mConceptNum); 00138 for (int c=0 ; c<mConceptNum ; c++) 00139 { 00140 Real64 fSum = 0; 00141 for (int i=0 ; i<mTableSize ; i++) 00142 { 00143 Quid quid = mQuidTable->Get1(i); 00144 Real64 sim = conceptSimTable[c]->Get1(i); 00145 fSum += sim; 00146 } 00147 pMean[c] = fSum/mTableSize; 00148 } 00149 00150 // get the variance of each concept list 00151 Real64* pStd = new Real64[mConceptNum]; 00152 memset(pStd,0,sizeof(Real64)*mConceptNum); 00153 for (int c=0 ; c<mConceptNum ; c++) 00154 { 00155 Real64 fSum = 0; 00156 for (int i=0 ; i<mTableSize ; i++) 00157 { 00158 Quid quid = mQuidTable->Get1(i); 00159 Real64 sim = conceptSimTable[c]->Get1(i); 00160 fSum += pow(sim - pMean[c],2); 00161 } 00162 pStd[c] = sqrt(fSum/(mTableSize-1)); 00163 } 00164 00165 // dump the old data distribution 00166 std::cout << std::endl; 00167 std::cout << "Before gaussian normalization:" << std::endl; 00168 for (int c=0; c<mConceptNum; c++ ) 00169 { 00170 printf(" (mean,std) = (%.10f, %.10f)\n", pMean[c], pStd[c]); 00171 } 00172 00173 // do the gaussian normalization of the similarity table 00174 for (int c=0 ; c<mConceptNum ; c++) 00175 { 00176 Real64 fSum = 0; 00177 for (int i=0 ; i<mTableSize ; i++) 00178 { 00179 Quid quid = mQuidTable->Get1(i); 00180 Real64 old_score = conceptSimTable[c]->Get1(i); 00181 Real64 new_score = (old_score - pMean[c])/pStd[c]; 00182 00183 // set the normalized value as the new score 00184 conceptSimTable[c]->Set1(i,new_score); 00185 } 00186 } 00187 00188 // check the updated data distribution 00189 memset(pMean,0,sizeof(Real64)*mConceptNum); 00190 memset(pStd,0,sizeof(Real64)*mConceptNum); 00191 for (int c=0 ; c<mConceptNum ; c++) 00192 { 00193 Real64 fSum = 0; 00194 for (int i=0 ; i<mTableSize ; i++) 00195 { 00196 Quid quid = mQuidTable->Get1(i); 00197 Real64 sim = conceptSimTable[c]->Get1(i); 00198 fSum += sim; 00199 } 00200 pMean[c] = fSum/mTableSize; 00201 } 00202 00203 // get the variance of each concept list 00204 for (int c=0 ; c<mConceptNum ; c++) 00205 { 00206 Real64 fSum = 0; 00207 for (int i=0 ; i<mTableSize ; i++) 00208 { 00209 Quid quid = mQuidTable->Get1(i); 00210 Real64 sim = conceptSimTable[c]->Get1(i); 00211 fSum += pow(sim - pMean[c],2); 00212 } 00213 pStd[c] = sqrt(fSum/(mTableSize-1)); 00214 } 00215 00216 // dump the normalized data distribution 00217 std::cout << "After gaussian normalization:" << std::endl; 00218 for (int c=0; c<mConceptNum; c++ ) 00219 { 00220 printf(" (mean,std) = (%.10f, %.10f)\n", pMean[c], pStd[c]); 00221 } 00222 00223 delete []pMean; 00224 delete []pStd; 00225 00226 // loop for all the key-frames in the table 00227 int nDupLabels = 0; 00228 for (int i=0 ; i<mTableSize ; i++) 00229 { 00230 Quid quid = mQuidTable->Get1(i); 00231 00232 // for keyframe i: find the highest score among all concepts 00233 Real64 fMaxValue = -1; 00234 int nDetect = -1; 00235 00236 for (int c=0 ; c<mConceptNum ; c++) 00237 { 00238 //String concept = mConceptSimSet->GetName(c); 00239 //std::cout << concept << ", "; 00240 Real64 sim = conceptSimTable[c]->Get1(i); 00241 if (sim>fMaxValue) 00242 { 00243 fMaxValue = sim; 00244 nDetect = c; 00245 } 00246 } 00247 00248 // for keyframe i: find the ground truth that concept keyframe i belongs to 00249 int nTruth = -1; 00250 int count = 0; 00251 for (int c=0 ; c<mConceptNum ; c++) 00252 { 00253 //String concept = mConceptSimSet->GetName(c); 00254 //std::cout << concept << ", "; 00255 if ( tabConcept[c]->IsPositive(i) ) 00256 { 00257 nTruth = c; 00258 count ++; 00259 } 00260 } 00261 // be sure that only one unique label 00262 00263 if (count == 0) // nTruth == -1 00264 { 00265 // no ground truth for current key-frame 00266 continue; 00267 } 00268 else if (count > 1) 00269 { 00270 //std::cout << "Warning: there are " << count << " labels for shot " << i << std::endl; 00271 nDupLabels++; 00272 } 00273 00274 int nCorrect = 0; 00275 int nError = 0; 00276 00277 // mConfusionMatrix[i=nTruth][j=nDetect]: 00278 // 1) A row (fixed i) stores all the predicted results for concept i 00279 // 2) A column (fixed j) stores all the ground truth of concept j 00280 // 3) the sum of a column j should be the total number of positive samples for concept j (before normalization) 00281 if (nDetect == nTruth) 00282 { 00283 mConfusionMatrix[nTruth][nTruth] += 1.0; 00284 nCorrect ++; 00285 00286 } 00287 else 00288 { 00289 // re-corrected order for row/column 00290 mConfusionMatrix[nTruth][nDetect] += 1.0; 00291 nError ++; 00292 } 00293 } 00294 00295 std::cout << "Duplicated Labels: " << nDupLabels << std::endl; 00296 00297 DumpMatrix("Confusion Matrix", mConfusionMatrix, mConceptNum, mConceptNum, false); 00298 00299 String outfileInt = "./ConfusionMatrix/" + mSetName + "_" + mConceptSet + "_" + mFeatureName + "_int.txt"; 00300 SaveConfigurationMatrix(outfileInt.c_str(), false); 00301 00302 // normalizations: sum of a column y (fixed x) is 1 00303 // mConfusionMatrix[x=nTruth][y=nDetect]: 00304 for (int x=0 ; x<mConceptNum; x++) 00305 { 00306 Real64 sum = 0; 00307 for (int y=0 ; y<mConceptNum ; y++) 00308 sum += mConfusionMatrix[x][y]; 00309 00310 if (sum < 0) continue; 00311 00312 for (int y=0 ; y<mConceptNum ; y++) 00313 mConfusionMatrix[x][y] /= sum; 00314 } 00315 00316 printf("The sum of each column (actual class)\n"); 00317 for (int x=0 ; x<mConceptNum; x++) 00318 { 00319 Real64 sum = 0; 00320 for (int y=0 ; y<mConceptNum ; y++) 00321 sum += mConfusionMatrix[x][y]; 00322 00323 printf("%.5f ", sum); 00324 } 00325 printf("\n"); 00326 00327 DumpMatrix("Confusion Matrix", mConfusionMatrix, mConceptNum, mConceptNum); 00328 00329 String outfile = "./ConfusionMatrix/" + mSetName + "_" + mConceptSet + "_" + mFeatureName + "_3f.txt"; 00330 SaveConfigurationMatrix(outfile.c_str()); 00331 00332 int x=0; 00333 }
Here is the call graph for this function:
|