// Can use this function to get likelihood with a topgauss double TopGauss::get(MixtureGD & UBM,FeatureServer &fs,String & featureFilename,Config & config){ StatServer ss(config); String labelSelectedFrames =config.getParam("labelSelectedFrames"); unsigned long begin=fs.getFirstFeatureIndexOfASource(featureFilename); fs.seekFeature(begin); SegServer segmentsServer; LabelServer labelServer; initializeClusters(featureFilename,segmentsServer,labelServer,config); // __android_log_print(ANDROID_LOG_DEBUG, "TopGauss::get", " Feature file %s \n", featureFilename.c_str()); verifyClusterFile(segmentsServer,fs,config); unsigned long codeSelectedFrame=labelServer.getLabelIndexByString(labelSelectedFrames); SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); MixtureGDStat &acc=ss.createAndStoreMixtureStat(UBM); Seg *seg; // current selected segment selectedSegments.rewind(); unsigned long t=0; //cnt frames acc.resetLLK(); unsigned long idxBegin=0; while((seg=selectedSegments.getSeg())!=NULL){ unsigned long begin=seg->begin()+fs.getFirstFeatureIndexOfASource(seg->sourceName()); fs.seekFeature(begin); Feature f; idxBegin=this->frameToIdx(t); for (unsigned long idxFrame=0;idxFrame<seg->length();idxFrame++){ fs.readFeature(f); //unsigned long idx=this->frameToIdx(t); unsigned long nbg=_nbg[t]; ULongVector index; double sumNonSelectedWeights=_snsw[t]; double sumNonSelectedLLK=_snsl[t]; for (unsigned long i=0;i<nbg;i++) { index.addValue(_idx[idxBegin+i]); } char c[100]; sprintf(c,"%d",(int)index.size()); config.setParam("topDistribsCount",c); // this should be high enough if (t==0) {acc.computeAndAccumulateLLK(f,1.0,DETERMINE_TOP_DISTRIBS);acc.resetLLK();} // to remove in ALIZE, this is to init the LKvector ss.setTopDistribIndexVector(index, sumNonSelectedWeights, sumNonSelectedLLK); acc.computeAndAccumulateLLK(f,1.0,USE_TOP_DISTRIBS); idxBegin+=nbg; t++; } } //ss.deleteMixtureStat(acc); if (t!=_nt || idxBegin !=_nbgcnt) cout << "W: t("<<t<<") != _nt(" <<_nt<<")"<<"W: idxBegin("<<idxBegin<<") != _nbgcnt(" <<_nbgcnt<<")"<<endl; return acc.getMeanLLK(); }
void cms(String & featureFileName,FeatureServer &fs,Config &config) { unsigned long begin=fs.getFirstFeatureIndexOfASource(featureFileName); fs.seekFeature(begin); SegServer segmentsServer; LabelServer labelServer; initializeClusters(featureFileName,segmentsServer,labelServer,config); verifyClusterFile(segmentsServer,fs,config); unsigned long codeSelectedFrame=labelServer.getLabelIndexByString(config.getParam("labelSelectedFrames")); SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); selectedSegments.rewind(); RealVector <double> mean,cov; FrameAccGD frameAccu; frameAccu.reset(); accumulateStatFrame(frameAccu,fs, selectedSegments, config); mean = frameAccu.getMeanVect(); // Get the mean vector cov = frameAccu.getStdVect(); // Get the std vector computeZeroOne(mean,cov,fs, selectedSegments, config); }
// Main init function double TopGauss::compute(MixtureGD & UBM,FeatureServer &fs,String & featureFilename,Config & config){ StatServer ss(config); MixtureGDStat &acc=ss.createAndStoreMixtureStat(UBM); unsigned long _mixsize=UBM.getDistribCount(); String labelSelectedFrames =config.getParam("labelSelectedFrames"); unsigned long begin=fs.getFirstFeatureIndexOfASource(featureFilename); fs.seekFeature(begin); SegServer segmentsServer; LabelServer labelServer; initializeClusters(featureFilename,segmentsServer,labelServer,config); // __android_log_print(ANDROID_LOG_DEBUG, "TopGauss::compute", " Feature file %s \n", featureFilename.c_str()); verifyClusterFile(segmentsServer,fs,config); unsigned long codeSelectedFrame=labelServer.getLabelIndexByString(labelSelectedFrames); SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame); acc.resetLLK(); double topD=config.getParam("topGauss").toDouble(); if (verbose) {if(topD<1.0) cout << "LLK %="<< topD << "% ";else cout << "Top-"<<topD<<" ";} // Class values _nt=totalFrame(selectedSegments); _nbg.setSize(_nt); _idx.setSize(0);_snsw.setSize(0); _snsl.setSize(0); _nbg.setAllValues(0); _idx.setAllValues(0);_snsw.setAllValues(0.0);_snsl.setAllValues(0.0); _nbgcnt=0; Seg *seg; // current selected segment selectedSegments.rewind(); unsigned long t=0; //cnt frames while((seg=selectedSegments.getSeg())!=NULL){ unsigned long begin=seg->begin()+fs.getFirstFeatureIndexOfASource(seg->sourceName()); fs.seekFeature(begin); Feature f; for (unsigned long idxFrame=0;idxFrame<seg->length();idxFrame++){ fs.readFeature(f); double llk=acc.computeAndAccumulateLLK(f,1.0,DETERMINE_TOP_DISTRIBS); const LKVector &topV=ss.getTopDistribIndexVector(); double lk_tot=exp(llk); double val=0.0; if (topD<1.0) { for(unsigned long j=0;j<_mixsize;j++){ if (val > topD*lk_tot) break; val+=(topV[j].lk); _nbg[t]++; } } else _nbg[t]=(unsigned long)topD; _nbgcnt+=_nbg[t]; double snsw=1.0; double snsl=lk_tot; for(unsigned long j=0;j<_nbg[t];j++) { _idx.addValue(topV[j].idx); snsw -=UBM.weight(topV[j].idx); snsl -=topV[j].lk; } _snsw.addValue(snsw); if (snsl < EPS_LK) _snsl.addValue(EPS_LK); else _snsl.addValue(snsl); t++; } } if (t!=_nt) cout << "W: t("<<t<<") != _nt(" <<_nt<<")"<<endl; return acc.getMeanLLK(); }