Go to the documentation of this file.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_EigenChannel_cpp)
00056 #define ALIZE_EigenChannel_cpp
00057
00058 #include <fstream>
00059 #include <cstdio>
00060 #include <cassert>
00061 #include <cmath>
00062 #include "liatools.h"
00063 #include "EigenChannel.h"
00064 #include "AccumulateJFAStat.h"
00065
00066 using namespace alize;
00067 using namespace std;
00068
00069 void verifyEMLK(FactorAnalysisStat & FA,XList &ndx,FeatureServer &fs,Config &config) {
00070 XLine *pline; String *pFile; ndx.rewind();
00071 double total=0.0;
00072 unsigned long maxLLKcomputed=1;
00073 maxLLKcomputed=config.getParam("computeLLK").toLong();
00074 bool FALLK=false;
00075 if (config.existsParam("FALLK")) {FALLK=true;if(verbose) cout<<"(EigenChannel) Computing Factor Analysis Likelihoods"<<endl;}
00076 unsigned long cnt=0;
00077 while((pline=ndx.getLine())!=NULL && cnt < maxLLKcomputed) {
00078 while((pFile=pline->getElement())!=NULL && cnt < maxLLKcomputed) {
00080 MixtureServer ms(config);
00081 MixtureGD &model=ms.loadMixtureGD(config.getParam("inputWorldFilename"));
00082 if (FALLK) FA.getFactorAnalysisModel(model,*pFile);
00083 else FA.getSpeakerModel(model,*pFile);
00084
00086 FeatureServer fs(config,*pFile);
00087 SegServer segmentsServer;
00088 LabelServer labelServer;
00089 initializeClusters(*pFile,segmentsServer,labelServer,config);
00090 verifyClusterFile(segmentsServer,fs,config);
00091 unsigned long codeSelectedFrame=labelServer.getLabelIndexByString(config.getParam("labelSelectedFrames"));
00092 SegCluster& selectedSegments=segmentsServer.getCluster(codeSelectedFrame);
00093 double llk=FA.getLLK(selectedSegments,model,fs,config);
00094 if (verbose) cout << "(EigenChannel) LLK["<<*pFile<<"]="<<llk<<endl;
00095 cnt++;
00096 total+=llk;
00097 }
00098 }
00099 if (verbose) cout << "(EigenChannel) Total LLK="<<total<<endl;
00100 }
00101
00102 int EigenChannel(Config & config){
00103 unsigned long nbIt=config.getParam("nbIt").toLong();
00104 bool _computeLLK=false;
00105 if (config.existsParam("computeLLK")) _computeLLK=true;
00106 bool init=false;
00107 if (config.existsParam("loadAccs")) init=config.getParam("loadAccs").toBool();;
00108
00109 XList ndx(config.getParam("ndxFilename"));
00110 XLine allFiles=ndx.getAllElements();
00111 FeatureServer fs;
00112
00113 if (verbose) cout << "** Create Factor Analysis Statistics Accumulator" << endl;
00114 FactorAnalysisStat FA((XList&)ndx,fs,config);
00115
00116
00117 if (!init) {
00118 fs.init(config,allFiles);
00119 FA.computeAndAccumulateGeneralFAStats(fs,config);
00120 FA.saveAccs(config);
00121 }
00122 else FA.loadAccs(config);
00123
00124
00125 FA.storeAccs();
00126 for(unsigned long i=0;i<nbIt;i++){
00127 if (_computeLLK) verifyEMLK(FA,ndx,fs,config);
00128 if (verbose) cout << "(EigenChannel) --------- Iteration "<<i<<"--------- "<<endl;
00129 FA.estimateAndInverseL(config);
00130 FA.substractSpeakerStats();
00131 FA.getXEstimate();
00132
00133 FA.substractChannelStats();
00134 FA.getYEstimate();
00135
00136 FA.getUEstimate(config);
00137 if (1) {
00138 String mat=config.getParam("channelMatrix")+".lastIt";
00139 FA.getU().save(mat,config);
00140 }
00141 FA.restoreAccs();
00142 }
00143 FA.getU().save(config.getParam("channelMatrix"),config);
00144 return 0;
00145 }
00146
00147
00148 int EigenChannelJFA(Config & config){
00149
00150
00151 String ndxFilename = config.getParam("ndxFilename");
00152
00153
00154 JFAAcc jfaAcc(ndxFilename, config);
00155
00156
00157 bool _checkLLK = false;
00158 if (config.existsParam("checkLLK")) _checkLLK= config.getParam("checkLLK").toBool();
00159
00160
00161 if((config.existsParam("loadAccs")) && config.getParam("loadAccs").toBool()){
00162 jfaAcc.loadN(config);
00163 jfaAcc.loadN_h(config);
00164 jfaAcc.loadF_X(config);
00165 jfaAcc.loadF_X_h(config);
00166 }
00167 else{
00168 jfaAcc.computeAndAccumulateJFAStat(config);
00169 jfaAcc.saveAccs(config);
00170 }
00171
00172
00173 if(config.existsParam("loadInitChannelMatrix") && config.getParam("loadInitChannelMatrix").toBool()){
00174 jfaAcc.loadEC(config.getParam("initEigenChannelMatrix"), config);
00175 }
00176 else{
00177 jfaAcc.initEC(config);
00178 }
00179
00180
00181 bool saveInitMatrix = false;
00182 if(config.existsParam("saveInitChannelMatrix")) saveInitMatrix = config.getParam("saveInitChannelMatrix").toBool();
00183 if(saveInitMatrix){
00184 jfaAcc.saveU(config.getParam("initEigenChannelMatrix"), config);
00185 cout<<" (EigenChannel) Save the initial EigenChannel Matrix in "<<config.getParam("initEigenChannelMatrix")<<endl;
00186 }
00187
00188
00189 if(config.existsParam("eigenVoiceMatrix")){
00190 jfaAcc.loadEV(config.getParam("eigenVoiceMatrix"), config);
00191 }
00192 else{
00193 jfaAcc.getV().setAllValues(0.0);
00194 cout<<" (EigenChannel) Initialise NULL EigenVoice Matrix"<<endl;
00195 }
00196
00197
00198 unsigned long nbIt = config.getParam("nbIt").toULong();
00199
00200
00201 jfaAcc.storeAccs();
00202 jfaAcc.estimateVEVT(config);
00203 jfaAcc.estimateAndInverseL_EV(config);
00204 jfaAcc.substractMplusDZ(config);
00205 jfaAcc.substractUX(config);
00206 jfaAcc.estimateY(config);
00207
00208
00209 jfaAcc.restoreAccs();
00210
00211 jfaAcc.storeAccs();
00212 for(unsigned long it=0; it<nbIt; it++){
00213
00214 cout<<" (EigenChannel) --------- start iteration "<<it<<" --------"<<endl;
00215 if (_checkLLK) jfaAcc.verifyEMLK(config);
00216
00217
00218 jfaAcc.estimateUEUT(config);
00219
00220
00221 jfaAcc.estimateAndInverseL_EC(config);
00222
00223
00224 jfaAcc.substractMplusVYplusDZ(config);
00225
00226
00227 jfaAcc.estimateXandU(config);
00228
00229
00230 jfaAcc.updateUestimate();
00231
00232
00233 jfaAcc.resetTmpAcc();
00234 jfaAcc.restoreAccs();
00235
00236
00237 jfaAcc.resetTmpAcc();
00238 jfaAcc.restoreAccs();
00239
00240
00241 bool saveAllMatrices = false;
00242 if(config.existsParam("saveAllECMatrices")) saveAllMatrices=config.getParam("saveAllECMatrices").toBool();
00243 if(saveAllMatrices)
00244 {
00245 String s;
00246 String output = config.getParam("eigenChannelMatrix") + s.valueOf(it);
00247 jfaAcc.saveU(output, config);
00248 }
00249 }
00250
00251 cout<<" (EigenChannel) --------- save EigenChannel Matrix --------"<<endl;
00252 jfaAcc.saveU(config.getParam("eigenChannelMatrix") ,config);
00253 cout<<" (EigenChannel) --------- end of process --------"<<endl;
00254
00255 return 0;
00256 }
00257
00258
00259
00260 int EigenChannelLFA(Config & config){
00261
00262
00263 String ndxFilename = config.getParam("ndxFilename");
00264
00265
00266 JFAAcc jfaAcc(ndxFilename, config);
00267
00268
00269 bool _checkLLK = false;
00270 if (config.existsParam("checkLLK")) _checkLLK= config.getParam("checkLLK").toBool();
00271
00272
00273 if((config.existsParam("loadAccs")) && config.getParam("loadAccs").toBool()){
00274 jfaAcc.loadN(config);
00275 jfaAcc.loadN_h(config);
00276 jfaAcc.loadF_X(config);
00277 jfaAcc.loadF_X_h(config);
00278 }
00279 else{
00280 jfaAcc.computeAndAccumulateJFAStat(config);
00281 jfaAcc.saveAccs(config);
00282 }
00283
00284
00285 if(config.existsParam("loadInitChannelMatrix") && config.getParam("loadInitChannelMatrix").toBool()){
00286 jfaAcc.loadEC(config.getParam("initEigenChannelMatrix"), config);
00287 }
00288 else{
00289 jfaAcc.initEC(config);
00290 }
00291
00292
00293 if(config.existsParam("saveInitChannelMatrix") && config.getParam("saveInitChannelMatrix").toBool()){
00294 jfaAcc.saveU(config.getParam("initEigenChannelMatrix"), config);
00295 cout<<" (EigenChannel) Save the initial EigenChannel Matrix in "<<config.getParam("initEigenChannelMatrix")<<endl;
00296 }
00297
00298
00299 if(config.existsParam("eigenVoiceMatrix")){
00300 jfaAcc.loadEV(config.getParam("eigenVoiceMatrix"), config);
00301 }
00302 else{
00303 jfaAcc.getV().setAllValues(0.0);
00304 cout<<" (EigenChannel) Initialise NULL EigenVoice Matrix"<<endl;
00305 }
00306
00307
00308
00309 if(config.getParam("channelCompensation")=="LFA"){
00310 jfaAcc.initD(config);
00311 }
00312
00313
00314 unsigned long nbIt = config.getParam("nbIt").toULong();
00315
00316
00317 jfaAcc.storeAccs();
00318 jfaAcc.estimateVEVT(config);
00319 jfaAcc.estimateAndInverseL_EV(config);
00320 jfaAcc.substractMplusDZ(config);
00321 jfaAcc.substractUX(config);
00322 jfaAcc.estimateY(config);
00323
00324
00325 jfaAcc.restoreAccs();
00326
00327 jfaAcc.storeAccs();
00328 for(unsigned long it=0; it<nbIt; it++){
00329
00330 cout<<" (EigenChannel) --------- start iteration "<<it<<" --------"<<endl;
00331 if (_checkLLK) jfaAcc.verifyEMLK(config);
00332
00333
00334 jfaAcc.estimateUEUT(config);
00335
00336
00337 jfaAcc.estimateAndInverseL_EC(config);
00338
00339
00340 jfaAcc.substractMplusVYplusDZ(config);
00341
00342
00343 jfaAcc.estimateX(config);
00344
00345
00346 jfaAcc.substractMplusUX();
00347
00348
00349 jfaAcc.estimateZMAP(config.getParam("regulationFactor").toLong());
00350
00351
00352 jfaAcc.estimateU();
00353
00354
00355 jfaAcc.updateUestimate();
00356
00357
00358 jfaAcc.resetTmpAcc();
00359 jfaAcc.restoreAccs();
00360
00361
00362 if(config.getParam("saveAllECMatrices").toBool()){
00363 String s;
00364 String output = config.getParam("eigenChannelMatrix") + s.valueOf(it);
00365 jfaAcc.saveU(output, config);
00366 }
00367 }
00368
00369 cout<<" (EigenChannel) --------- save EigenChannel Matrix --------"<<endl;
00370 jfaAcc.saveU(config.getParam("eigenChannelMatrix") ,config);
00371 cout<<" (EigenChannel) --------- end of process --------"<<endl;
00372
00373 return 0;
00374 }
00375
00376 #endif