00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #if !defined(ALIZE_ComputeNorm_cpp)
00056 #define ALIZE_ComputeNorm_cpp
00057
00058 #include <iostream>
00059 #include <fstream>
00060 #include <cstdio>
00061 #include <cassert>
00062 #include <cmath>
00063 #include <cstdlib>
00064
00065 #include "liatools.h"
00066 #include "ComputeNorm.h"
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 using namespace alize;
00078 using namespace std;
00079
00080
00081 class DistribNorm{
00082 LKVector tabScore;
00083
00084 String *tabIdImp;
00085 Config conf;
00086 public:
00087 void init();
00088 void addScore(double, const String&);
00089 bool computeMeanStd(double &, double&, char,double,double);
00090 unsigned long size();
00091 void print();
00092 DistribNorm(Config &);
00093 ~DistribNorm();
00094 };
00095
00096 void DistribNorm::init(){
00097 tabScore.clear();
00098 }
00099
00100 unsigned long DistribNorm::size(){
00101 return tabScore.size();
00102 }
00103
00104 void DistribNorm::addScore(double d, const String& idImp){
00105 LKVector::type t;
00106 unsigned long ind;
00107
00108
00109
00110 if(tabScore.size() == 0)
00111 ind = (unsigned long)0;
00112 else
00113 ind = (tabScore.size());
00114 t.lk = d;
00115 t.idx = ind;
00116 tabIdImp[ind] = idImp;
00117 tabScore.addValue(t);
00118 }
00119
00120
00121 bool DistribNorm::computeMeanStd(double &mean,double &std,char mode, double percentH,double percentL){
00122 if(tabScore.size() == 0) return false;
00123 else{
00124 unsigned long size=tabScore.size();
00125 unsigned long begin=0;
00126 unsigned long end=size;
00127 if ((percentH!=0) || (percentL!=0)){
00128 tabScore.descendingSort();
00129 unsigned long discardH=(unsigned long) (((double) size) * percentH);
00130 unsigned long discardL=(unsigned long) (((double) size) * percentL);
00131 size-=(discardH+discardL);
00132 begin=discardH;
00133 end=tabScore.size()-discardL;
00134 if (debug) cout<<"discardH["<<discardH<<"] discardL["<<discardL<<"] begin["<<begin<<"] end["<<end<<"]"<<endl;
00135 }
00136 double sum=0;
00137 double sum2=0;
00138 switch (mode){
00139 case 0:
00140 for(unsigned int i=begin; i<end; i++){
00141 sum += tabScore[i].lk;
00142 sum2 += tabScore[i].lk * tabScore[i].lk;
00143 }
00144 mean=sum/(double)(size);
00145 std=sqrt((sum2/(double)(size)-(mean*mean)));
00146 break;
00147 case 1:
00148 mean=tabScore[begin+(size/2)].lk;
00149 for(unsigned int i=begin; i<end; i++)
00150 sum += abs(tabScore[i].lk-mean);
00151 std=sum/(double)(size);
00152 break;
00153 default: cout <<"mean compute mode["<<mode<<"] unknown"<<endl;
00154 exit(0);
00155 }
00156
00157 return true;
00158 }
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 void DistribNorm::print(){
00175 cout << "Distrib Score Print (nbScore=" << tabScore.size() << ")" << endl;
00176 for(unsigned int i=0; i<tabScore.size(); i++){
00177 cout << tabIdImp[tabScore[i].idx] << " ";
00178 printf("%.8lE ", tabScore[i].lk);
00179 }
00180 cout << endl;
00181 }
00182
00183 DistribNorm::DistribNorm(Config &config){
00184 conf = config;
00185 unsigned long nbScoreMax = (unsigned long)(conf.getParam("maxScoreDistribNb").toLong());
00186 tabIdImp = new String[nbScoreMax];
00187
00188
00189 }
00190
00191 DistribNorm::~DistribNorm() {
00192 delete []tabIdImp;
00193 }
00194
00195 class NormSeg{
00196 String name;
00197 double mean;
00198 double std;
00199 bool computed;
00200
00201
00202 unsigned long nb;
00203 DistribNorm *distribNorm;
00204 public:
00205 double getMean(char,double,double);
00206 double getStd(char,double,double);
00207 unsigned long getNb();
00208 String getName();
00209 void setNb(unsigned long);
00210 void set(String,double,double);
00211 void setName(String);
00212 void addScore(double,const String &imp);
00213 void newDistribNorm(Config &);
00214 void deleteDistribNorm();
00215 NormSeg();
00216 ~NormSeg();
00217 };
00218 void NormSeg::addScore(double score,const String & imp){
00219 distribNorm->addScore(score,imp);
00220 }
00221 double NormSeg::getMean(char computeMode,double discardH,double discardL){
00222 if (!computed){
00223 if (!distribNorm->computeMeanStd(mean,std,computeMode,discardH,discardL)){
00224 cout << "Problem: empty impostor cohort"<<endl;
00225 exit(0);
00226 }
00227 computed=true;
00228 }
00229 return mean;
00230 }
00231
00232 double NormSeg::getStd(char computeMode,double discardH,double discardL){
00233 if (!computed){
00234 if (!distribNorm->computeMeanStd(mean,std,computeMode,discardH,discardL)){
00235 cout << "Problem: empty impostor cohort"<<endl;
00236 exit(0);
00237 }
00238 computed=true;
00239 }
00240 return std;
00241 }
00242
00243 unsigned long NormSeg::getNb(){
00244 return nb;
00245 }
00246
00247 String NormSeg::getName(){
00248 return name;
00249 }
00250
00251
00252 void NormSeg::setNb(unsigned long m){
00253 nb = m;
00254 }
00255
00256 void NormSeg::set(String n,double m,double s){
00257 name = n;
00258 mean = m;
00259 std = s;
00260 computed=true;
00261 }
00262 void NormSeg::setName(String n){
00263 name = n;
00264 }
00265 void NormSeg::newDistribNorm(Config &config){
00266 distribNorm=new DistribNorm(config);
00267 }
00268 void NormSeg::deleteDistribNorm(){
00269 delete distribNorm;
00270 distribNorm=NULL;
00271 }
00272 NormSeg::NormSeg(){
00273 distribNorm=NULL;
00274 }
00275 NormSeg::~NormSeg(){
00276 if (distribNorm) deleteDistribNorm();
00277 }
00278
00279 class Norm {
00280 NormSeg *normTab;
00281 unsigned long nbNorm;
00282 unsigned long nbNormMax;
00283 unsigned long findEntityIdxInNorm(String);
00284 void moveEntity(unsigned long,unsigned long);
00285 unsigned long idxLastFind;
00286 char _computeMode;
00287
00288
00289 double _percentH;
00290 double _percentL;
00291 public:
00292 bool findEntityInNorm(String,unsigned long &);
00293 double getMean(unsigned long);
00294 double getStd(unsigned long);
00295
00296
00297 unsigned long getNb(unsigned long);
00298 void print();
00299 unsigned long addSeg(String, double, double);
00300
00301 unsigned long findAddSeg(String,Config&);
00302 void addScore(unsigned long,double,const String &);
00303 void deleteAllDistribNorm();
00304 void setNormAndFreeDistrib();
00305
00306 Norm(unsigned long);
00307 Norm(unsigned long, char,double,double);
00308 ~Norm();
00309 };
00310 void Norm::setNormAndFreeDistrib(){
00311 for(unsigned long idx=0; idx<nbNorm; idx++){
00312 normTab[idx].getMean(_computeMode,_percentH,_percentL);
00313 normTab[idx].deleteDistribNorm();
00314 }
00315 }
00316
00317 void Norm::addScore(unsigned long idx,double score,const String & imp)
00318 {
00319 normTab[idx].addScore(score,imp);
00320 }
00321 void Norm::deleteAllDistribNorm(){
00322 for(unsigned long i=0; i<nbNorm; i++)
00323 normTab[i].deleteDistribNorm();
00324 }
00325
00326
00327 void Norm::moveEntity(unsigned long beg,unsigned long end){
00328
00329 if (debug || (verboseLevel>2))
00330 cout << "moveEntity beg["<<beg<<"] end["<<end<<"]"<<endl;
00331 for (unsigned idx=end;idx>beg;idx--)
00332 normTab[idx]=normTab[idx-1];
00333
00334 }
00335 unsigned long Norm::findEntityIdxInNorm(String name){
00336 unsigned long beg=0;
00337 unsigned long end=nbNorm-1;
00338 unsigned long idx=0;
00339 if (nbNorm==0) return 0;
00340 while ((end-beg)>1){
00341 idx=(beg+end)/2;
00342 if (name > normTab[idx].getName())
00343 beg=idx;
00344 else end=idx;
00345 }
00346 if (name <=normTab[beg].getName()) return beg;
00347 else if (name>normTab[end].getName()) return end+1;
00348 else return end;
00349 }
00350 bool Norm::findEntityInNorm(String name,unsigned long & idx){
00351 if(nbNorm == 0) {idx=0;return false;}
00352
00353 if (normTab[idxLastFind].getName() == name){
00354 idx=idxLastFind;
00355 return true;
00356 }
00357 idx=findEntityIdxInNorm(name);
00358 if(normTab[idx].getName() == name){
00359 idxLastFind=idx;
00360 return true;
00361 }
00362 else return false;
00363 }
00364
00365 void Norm::print(){
00366 cout << "nbnorm: " << nbNorm << endl;
00367 for(unsigned long i=0; i<nbNorm; i++){
00368 cout << normTab[i].getName() << " " << getMean(i) << " " << getStd(i) << endl;
00369 }
00370 }
00371
00372 double Norm::getMean(unsigned long ind){
00373 return normTab[ind].getMean(_computeMode,_percentH,_percentL);
00374 }
00375
00376 double Norm::getStd(unsigned long ind){
00377 return normTab[ind].getStd(_computeMode,_percentH,_percentL);
00378 }
00379
00380 unsigned long Norm::getNb(unsigned long ind){
00381 return normTab[ind].getNb();
00382 }
00383
00384 unsigned long Norm::findAddSeg(String name,Config & config){
00385 if(nbNorm == (nbNormMax)){
00386 cout << "Table norm Capacity out of bound: " << nbNorm << endl;
00387 exit(-1);
00388 }
00389 unsigned long idx;
00390 if (!findEntityInNorm(name,idx)){
00391 if (debug) cout <<"addSeg:seg["<<name<<"] idx["<<idx<<"]"<<endl;
00392 moveEntity(idx,nbNorm);
00393 normTab[idx].setName(name);
00394 nbNorm++;
00395 normTab[idx].newDistribNorm(config);
00396 }
00397 return idx;
00398 }
00399
00400 unsigned long Norm::addSeg(String name, double mean, double std){
00401 if(nbNorm == (nbNormMax)){
00402 cout << "Table norm Capacity out of bound: " << nbNorm << endl;
00403 exit(-1);
00404 }
00405 unsigned long idx=findEntityIdxInNorm(name);
00406 if (debug) cout <<"addSeg:seg["<<name<<"] idx["<<idx<<"]"<<endl;
00407 moveEntity(idx,nbNorm);
00408 normTab[idx].set(name,mean,std);
00409 nbNorm++;
00410 return (idx);
00411 }
00412
00413 Norm::Norm(unsigned long nbMax){
00414 _computeMode=0;
00415 _percentH=0;_percentL=0;
00416 nbNorm = 0;
00417 nbNormMax = nbMax;
00418 normTab = new NormSeg[nbNormMax];
00419 idxLastFind=0;
00420 }
00421 Norm::Norm(unsigned long nbMax, char compute,double percentH,double percentL){
00422 _computeMode=compute;
00423 _percentH=percentH;
00424 _percentL=percentL;
00425 nbNorm = 0;
00426 nbNormMax = nbMax;
00427 normTab = new NormSeg[nbNormMax];
00428 idxLastFind=0;
00429 }
00430 Norm::~Norm(){
00431 delete [] normTab;
00432 }
00433
00434
00435
00436 bool selectImp(String &fieldOne,String& fieldTwo,XList &impList,char selectMode)
00437 {
00438 bool select;
00439 switch (selectMode){
00440 case 0:select=true;break;
00441 case 1:select=(impList.findLine(fieldTwo) !=NULL);break;
00442 default:select=true;cout <<"selectMode unknown. No impostor scores selection is applied"<<endl;
00443 }
00444 return select;
00445 }
00446 void getAllScores(XList &list, unsigned long indFieldOne, unsigned long indFieldTwo, unsigned long indScore, Norm &norm,XList &impList,char selectMode,Config &config){
00447 XLine *linep;
00448
00449 list.getLine(0);
00450 while ((linep=list.getLine()) != NULL){
00451 String fieldOne=linep->getElement(indFieldOne);
00452 String fieldTwo=linep->getElement(indFieldTwo);
00453 double score=linep->getElement(indScore).toDouble();
00454 if (selectImp(fieldOne,fieldTwo,impList,selectMode)){
00455
00456
00457
00458 unsigned long idx=norm.findAddSeg(fieldOne,config);
00459 norm.addScore(idx,score, fieldTwo);
00460 }
00461 }
00462 }
00463
00464
00465
00466 void getAllScoresFirstNormed(XList &list, unsigned long indFieldOne, unsigned long indFieldTwo,unsigned long indScore, Norm &firstNorm,
00467 Norm &outNorm,XList &impList,char selectMode,Config &config){
00468 XLine *linep;
00469
00470 list.getLine(0);
00471 while ((linep=list.getLine()) != NULL){
00472 String fieldOne=linep->getElement(indFieldOne);
00473 String fieldTwo=linep->getElement(indFieldTwo);
00474 double score=linep->getElement(indScore).toDouble();
00475 unsigned long ind;
00476 if (selectImp(fieldOne,fieldTwo,impList,selectMode)){
00477
00478 if(firstNorm.findEntityInNorm(fieldTwo,ind)){
00479 unsigned long idx=outNorm.findAddSeg(fieldOne,config);
00480 outNorm.addScore(idx,(score - firstNorm.getMean(ind)) / firstNorm.getStd(ind), fieldTwo);
00481 }
00482 else{
00483 cout << "distribution for["<<fieldTwo<<"] not found!" << endl;
00484 cout <<"line:"<<linep<<endl;
00485 exit(-1);
00486 }
00487 }
00488 }
00489 }
00490
00491 int ComputeNorm(Config& config)
00492 {
00493
00494 using namespace alize;
00495 using namespace std;
00496
00497 int decision=0;
00498 String outputNISTFileName = config.getParam("outputFileBaseName");
00499 String znormFilesExtension = config.getParam("znormFilesExtension");
00500 String tnormFilesExtension = config.getParam("tnormFilesExtension");
00501 String tznormFilesExtension = config.getParam("tznormFilesExtension");
00502 String ztnormFilesExtension = config.getParam("ztnormFilesExtension");
00503
00504
00505 unsigned long maxIdNb = (unsigned long)(config.getParam("maxIdNb").toLong());
00506 unsigned long maxSegNb = (unsigned long)(config.getParam("maxSegNb").toLong());
00507 String normType = config.getParam("normType");
00508 String testNistFile = config.getParam("testNistFile");
00509 char selectMode=0;
00510 XList impList;
00511 if (config.existsParam("impostorIDList")){
00512 selectMode=1;
00513 impList.load(config.getParam("impostorIDList"),config);
00514 }
00515 char computeMode = (char)(config.getParam("meanMode").toLong());
00516 double percentH=(double)(config.getParam("percentH").toDouble());
00517 double percentL=(double)(config.getParam("percentL").toDouble());
00518
00519
00520 char fieldGender=(char) config.getParam("fieldGender").toLong();
00521 char fieldName=(char)config.getParam("fieldName").toLong();
00522
00523 char fieldSeg=(char)config.getParam("fieldSeg").toLong();
00524 char fieldLLR=(char)config.getParam("fieldLLR").toLong();
00525
00526 XList testList(testNistFile, config);
00527 testList.getLine(0);
00528
00529 try{
00530 if(normType == "tnorm"){
00531 String outputFilename=outputNISTFileName+tnormFilesExtension;
00532 ofstream outFile(outputFilename.c_str(),ios::out | ios::trunc);
00533 Norm tnorm(maxSegNb,computeMode,percentH,percentL);
00534 String tnormNistFile = config.getParam("tnormNistFile");
00535 if (verbose) cout << "Tnorm, reading tnormList"<<endl;
00536 XList tnormList(tnormNistFile, config);
00537 getAllScores(tnormList, fieldSeg, fieldName, fieldLLR, tnorm,impList,selectMode,config);
00538 tnorm.setNormAndFreeDistrib();
00539
00540 if (verbose) cout << "Tnorm, begin the test list"<<endl;
00541 XLine * linep;
00542 while ((linep=testList.getLine()) != NULL){
00543
00544 String seg=linep->getElement(fieldSeg);
00545 unsigned long ind;
00546 if(debug) cout << endl << "findEntityInNorm SEG[" << seg << "]";
00547 if (!tnorm.findEntityInNorm(seg,ind)){
00548 cout << "tnorm impostor score not found for seg["<<seg<<endl;
00549 exit(-1);
00550 }
00551 if(debug) cout << " idx["<< ind<< "]"<<endl;
00552 double score = ((linep->getElement(fieldLLR)).toDouble() - tnorm.getMean(ind)) / tnorm.getStd(ind);
00553 outputResultLine(score, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, outFile);
00554 }
00555 outFile.close();
00556 if(debug||verbose){
00557 cout << "tnorm distrib" << endl;
00558 tnorm.print();
00559 }
00560
00561 }
00562 else if(normType == "znorm"){
00563 String outputFilename=outputNISTFileName+znormFilesExtension;
00564 ofstream outFile(outputFilename.c_str(),ios::out | ios::trunc);
00565 if(verbose) cout << endl << "Compute Znorm" << endl;
00566
00567 Norm znorm(maxIdNb,computeMode,percentH,percentL);
00568 String znormNistFile = config.getParam("znormNistFile");
00569 XList znormList(znormNistFile, config);
00570 XLine * linep;
00571 if (verbose) cout << "Computing once the Znorm distributions"<<endl<<
00572 "Take Care, really faster if the score files are sorted!"<<endl;
00573 getAllScores(znormList, fieldName, fieldSeg, fieldLLR, znorm,impList,selectMode,config);
00574 znorm.setNormAndFreeDistrib();
00575
00576 while ((linep=testList.getLine()) != NULL){
00577
00578 String id=linep->getElement(fieldName);
00579 unsigned long ind;
00580 if(verboseLevel>2) cout << endl << "Compute Znorm [" << id << "]"<< endl;
00581 if(debug) cout << endl << "findEntityInNorm Id[" << id << "]";
00582 if (!znorm.findEntityInNorm(id,ind)){
00583 cout << "znorm impostor score not found for id["<<id<<endl;
00584 exit(-1);
00585 }
00586 if(debug) cout << " idx["<< ind<< "]"<<endl;
00587 double score = ((linep->getElement(fieldLLR)).toDouble() - znorm.getMean(ind)) / znorm.getStd(ind);
00588 outputResultLine(score, id, linep->getElement(fieldSeg), linep->getElement(fieldGender), decision, outFile);
00589 }
00590 outFile.close();
00591 if(debug||verbose){
00592 cout << "znorm distrib" << endl;
00593 znorm.print();
00594 }
00595 }
00596 else if(normType == "ztnorm"){
00597 String outputTnormFilename=outputNISTFileName+tnormFilesExtension;
00598 String outputZtnormFilename=outputNISTFileName+ztnormFilesExtension;
00599
00600 ofstream outFileTnorm(outputTnormFilename.c_str(),ios::out | ios::trunc);
00601 ofstream outFileZtnorm(outputZtnormFilename.c_str(),ios::out | ios::trunc);
00602 if(verbose) cout << endl << "Compute ZTnorm (and tnorm)" << endl;
00603
00604 Norm tnorm(maxSegNb,computeMode,percentH,percentL);
00605 Norm znorm(maxIdNb,computeMode,percentH,percentL);
00606 Norm ztnorm(maxSegNb,computeMode,percentH,percentL);
00607
00608 String tnormNistFile = config.getParam("tnormNistFile");
00609 String znormNistFile = config.getParam("znormNistFile");
00610 String ztnormNistFile = config.getParam("ztnormNistFile");
00611 XList tnormList(tnormNistFile, config);
00612 XList znormList(znormNistFile, config);
00613 XList ztnormList(ztnormNistFile, config);
00614
00615
00616 if (verbose) cout << "Computing once the Tnorm distribution for impostor segments"<<endl<<
00617 "Take Care, really faster if the score files are sorted!"<<endl;
00618 getAllScores(ztnormList, fieldSeg, fieldName, fieldLLR, ztnorm,impList,selectMode,config);
00619 ztnorm.setNormAndFreeDistrib();
00620
00621 if (verbose) cout << "Computing once all the tnorm distributions for the test segments "<<endl
00622 << "Take Care, really faster if the score files are sorted!"<<endl;
00623 getAllScores(tnormList, fieldSeg, fieldName, fieldLLR, tnorm,impList,selectMode,config);
00624 tnorm.setNormAndFreeDistrib();
00625
00626
00627 if (verbose) cout << "Computing once all the znorm (tnormed) distributions "<<endl
00628 << "Take Care, really faster if the score files are sorted!"<<endl;
00629 getAllScoresFirstNormed(znormList, fieldName, fieldSeg, fieldLLR, ztnorm, znorm,impList,selectMode,config);
00630 znorm.setNormAndFreeDistrib();
00631
00632
00633 XLine * linep;
00634 while ((linep=testList.getLine()) != NULL){
00635
00636 String seg=linep->getElement(fieldSeg);
00637 String id= linep->getElement(fieldName);
00638 if (verboseLevel>2) cout << "ztnorm seg["<<seg<<"] Id["<<id<<"]"<<endl;
00639 unsigned long ind;
00640
00641 if(debug) cout << endl << "findEntityInNorm SEG[" << seg << "]";
00642 if (!tnorm.findEntityInNorm(seg,ind)){
00643 cout << "tnorm impostor distribution not found for seg["<<seg<<"]"<<endl;
00644 exit(-1);
00645 }
00646 if(debug) cout << " idx["<< ind<< "]"<<endl;
00647 double scoreTNorm = ((linep->getElement(fieldLLR)).toDouble() - tnorm.getMean(ind)) / tnorm.getStd(ind);
00648
00649
00650 if(!znorm.findEntityInNorm(id,ind)){
00651 cout << "znorm(tnormed) distribution not found for id["<<id<<"]"<<endl;
00652 exit(-1);
00653 }
00654 double score = (scoreTNorm - znorm.getMean(ind)) / znorm.getStd(ind);
00655
00656 outputResultLine(score, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, outFileZtnorm);
00657 outputResultLine(scoreTNorm, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, outFileTnorm);
00658 }
00659 outFileZtnorm.close();
00660 outFileTnorm.close();
00661 if(debug||verbose){
00662 cout << "tnorm distrib" << endl;
00663 tnorm.print();
00664 cout << "znorm distrib" << endl;
00665 znorm.print();
00666 }
00667 }
00668 else if(normType == "tznorm"){
00669 String outputTznormFilename=outputNISTFileName+tznormFilesExtension;
00670 String outputZnormFilename=outputNISTFileName+znormFilesExtension;
00671 ofstream outFileTznorm(outputTznormFilename.c_str(),ios::out | ios::trunc);
00672 ofstream outFileZnorm(outputZnormFilename.c_str(),ios::out | ios::trunc);
00673 if(verbose) cout << endl << "Compute TZnorm" << endl;
00674
00675 Norm tnorm(maxSegNb,computeMode,percentH,percentL);
00676 Norm znorm(maxIdNb,computeMode,percentH,percentL);
00677 Norm tznorm(maxSegNb,computeMode,percentH,percentL);
00678
00679 String tnormNistFile = config.getParam("tnormNistFile");
00680 String znormNistFile = config.getParam("znormNistFile");
00681 String tznormNistFile = config.getParam("ztnormNistFile");
00682 XList tnormList(tnormNistFile, config);
00683 XList znormList(znormNistFile, config);
00684 XList tznormList(tznormNistFile, config);
00685
00686
00687 if (verbose) cout << "Compute Znorm distribs for the target speakers (using znorm scores)"<<endl
00688 <<"Computing once all the impostor distribution "<<endl
00689 << "Take Care, really faster if the score files are sorted!"<<endl;
00690 getAllScores(znormList, fieldName, fieldSeg, fieldLLR, znorm,impList,selectMode,config);
00691 znorm.setNormAndFreeDistrib();
00692
00693
00694 if (verbose) cout << "Compute znorm distribs for the impostor speakers (using ztnorm scores)"
00695 << "Computing once all the impostor distribution "<<endl
00696 << "Take Care, really faster if the score files are sorted!"<<endl;
00697 getAllScores(tznormList, fieldName, fieldSeg, fieldLLR, tznorm,impList,selectMode,config);
00698 tznorm.setNormAndFreeDistrib();
00699
00700
00701 if (verbose) cout << "Compute tnorm distribs of the znormed scores "<<endl
00702 << "Computing once all the impostor distribution "<<endl
00703 << "Take Care, really faster if the score files are sorted!"<<endl;
00704 getAllScoresFirstNormed(tnormList, fieldSeg, fieldName, fieldLLR, tznorm, tnorm,impList,selectMode,config);
00705 tnorm.setNormAndFreeDistrib();
00706 if(debug|| verbose){
00707 cout << "tnorm distrib" << endl;
00708 tnorm.print();
00709 cout << "znorm distrib" << endl;
00710 znorm.print();
00711 cout << "tznorm distrib" << endl;
00712 tznorm.print();
00713 }
00714
00715 if (verbose) cout << "begin the test list"<<endl;
00716 XLine * linep;
00717 while ((linep=testList.getLine()) != NULL){
00718
00719 String seg=linep->getElement(fieldSeg);
00720 String id= linep->getElement(fieldName);
00721 if (verboseLevel>2) cout << "tznorm seg["<<seg<<"] Id["<<id<<"]"<<endl;
00722 unsigned long ind;
00723
00724 if(debug) cout << endl << "findEntityInNorm SEG[" << seg << "]";
00725 if (!znorm.findEntityInNorm(id,ind)){
00726 cout << "znorm distribution not found for id["<<id<<"]"<<endl;
00727 exit(-1);
00728 }
00729 if(debug) cout << " idx["<< ind<< "]"<<endl;
00730 double scoreZNorm = ((linep->getElement(fieldLLR)).toDouble() - znorm.getMean(ind)) / znorm.getStd(ind);
00731
00732 if(!tnorm.findEntityInNorm(seg,ind)){
00733 cout << "tnorm(znormed) distribution not found for seg["<<seg<<"]"<<endl;
00734 exit(-1);
00735 }
00736 double score = (scoreZNorm - tnorm.getMean(ind)) / tnorm.getStd(ind);
00737
00738 outputResultLine(score, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, outFileTznorm);
00739 outputResultLine(scoreZNorm, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, outFileZnorm);
00740 if (verboseLevel>2) outputResultLine(score, linep->getElement(fieldName), seg, linep->getElement(fieldGender), decision, cout);
00741
00742 }
00743 outFileTznorm.close();
00744 outFileZnorm.close();
00745 if(debug || verbose){
00746 cout << "tnorm distrib" << endl;
00747 tnorm.print();
00748 cout << "znorm distrib" << endl;
00749 znorm.print();
00750 }
00751 }
00752 else {
00753 cout << "unknown normalization mode:"<<normType<<endl;
00754 exit(-1);
00755 }
00756 }
00757 catch (Exception& e){
00758 cout << e.toString().c_str() << endl;
00759 }
00760
00761
00762 return 0;
00763 }
00764
00765 #endif //!defined(ALIZE_ComputeNorm_cpp)