//! compare two labels and fill in missing labels void ShadeShapeMatch::fillMissingLabels(Labels &upLabels, Labels &dbLabels) { map<String,pair<int,float> > &upMap = upLabels.getMap(); map<String,pair<int,float> > &dbMap = dbLabels.getMap(); map<String,int> &upShadeLevelMap = upLabels.getShadeLevelMap(); map<String,int> &dbShadeLevelMap = dbLabels.getShadeLevelMap(); map<String,int> &upShapeNumMap = upLabels.getShapeMap(); map<String,int> &dbShapeNumMap = dbLabels.getShapeMap(); for(auto it=upMap.begin(); it!=upMap.end(); it++) { String label = it->first; if(dbMap.find(label)==dbMap.end()) { dbMap[label] = std::make_pair(0,0.0); dbShadeLevelMap[label] = upLabels.getShadeLevel(label); dbShapeNumMap[label] = upLabels.getShapeNum(label); } } for(auto it=dbMap.begin(); it!=dbMap.end(); it++) { String label = it->first; if(upMap.find(label)==upMap.end()) { upMap[label] = std::make_pair(0,0.0); upShadeLevelMap[label] = dbLabels.getShadeLevel(label); upShapeNumMap[label] = dbLabels.getShapeNum(label); } } }
//! dot product using holder's inequality //! TR1 //! applies shape shift penalties during calculations for the shapes shifted float ShadeShapeMatch::dotProduct(Labels &upLabels, Labels &dbLabels) { ShapeMatch spm; ShadeMatch sdm; if(upLabels.size()!=dbLabels.size()) { cout << "ShapeMatch::dotProduct(): upLabels && dbLabels not same size!!!" << endl; exit(1); } float numerSum = 0.0; float denomSumUP = 0.0; float denomSumDB = 0.0; map<String,pair<int,float> > upMap = upLabels.getMap(); map<String,pair<int,float> > dbMap = dbLabels.getMap(); this->shapeTranslateCount.resize(spm.numOfShapes(),vector<int>(spm.numOfShapes(),0)); // 10 shapes for(auto itUP=upMap.begin(), itDB=dbMap.begin(); itUP!=upMap.end(), itDB!=dbMap.end(); itUP++, itDB++) { String label = itUP->first; float penalty = 1.0; int shapeNum = upLabels.getShapeNum(label); if(shapeNum==-1) shapeNum = dbLabels.getShapeNum(label); if(upLabels.isShapeShifted(label)) { int prevShapeNum = upLabels.getPrevShapeNum(label); if(prevShapeNum>=0 && shapeNum>=0) { penalty = spm.getShiftPenalty(prevShapeNum,shapeNum); } else { printf("ShadeShapeMatch::dotProduct() %s label does not exist!\n",itUP->first.c_str()); printf("PrevShapeNum: %d, :CurrShapeNum: %d\n",prevShapeNum,shapeNum); } } int shadeLevel = upLabels.getShadeLevel(label); float shadeWeight = sdm.applyShadeWeights(shadeLevel); float shapeWeight = spm.applyShapeWeight(shapeNum); numerSum += (itUP->second.second * itDB->second.second) * penalty * shadeWeight * shapeWeight; denomSumUP += pow(itUP->second.second,2); denomSumDB += pow(itDB->second.second,2); } float denomSum = sqrt(denomSumUP) * sqrt(denomSumDB); float results = numerSum / denomSum; return results; }