UnsupervisedTools.h

Go to the documentation of this file.
00001 /*
00002 This file is part of LIA_RAL which is a set of software based on ALIZE
00003 toolkit for speaker recognition. ALIZE toolkit is required to use LIA_RAL.
00004 
00005 LIA_RAL project is a development project was initiated by the computer
00006 science laboratory of Avignon / France (Laboratoire Informatique d'Avignon -
00007 LIA) [http://lia.univ-avignon.fr <http://lia.univ-avignon.fr/>]. Then it
00008 was supported by two national projects of the French Research Ministry:
00009         - TECHNOLANGUE program [http://www.technolangue.net]
00010         - MISTRAL program [http://mistral.univ-avignon.fr]
00011 
00012 LIA_RAL is free software: you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation, either version 3 of
00015 the License, or any later version.
00016 
00017 LIA_RAL is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 GNU Lesser General Public License for more details.
00021 
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with LIA_RAL.
00024 If not, see [http://www.gnu.org/licenses/].
00025 
00026 The LIA team as well as the LIA_RAL project team wants to highlight the
00027 limits of voice authentication in a forensic context.
00028 The "Person Authentification by Voice: A Need of Caution" paper
00029 proposes a good overview of this point (cf. "Person
00030 Authentification by Voice: A Need of Caution", Bonastre J.F.,
00031 Bimbot F., Boe L.J., Campbell J.P., Douglas D.A., Magrin-
00032 chagnolleau I., Eurospeech 2003, Genova].
00033 The conclusion of the paper of the paper is proposed bellow:
00034 [Currently, it is not possible to completely determine whether the
00035 similarity between two recordings is due to the speaker or to other
00036 factors, especially when: (a) the speaker does not cooperate, (b) there
00037 is no control over recording equipment, (c) recording conditions are not
00038 known, (d) one does not know whether the voice was disguised and, to a
00039 lesser extent, (e) the linguistic content of the message is not
00040 controlled. Caution and judgment must be exercised when applying speaker
00041 recognition techniques, whether human or automatic, to account for these
00042 uncontrolled factors. Under more constrained or calibrated situations,
00043 or as an aid for investigative purposes, judicious application of these
00044 techniques may be suitable, provided they are not considered as infallible.
00045 At the present time, there is no scientific process that enables one to
00046 uniquely characterize a persones voice or to identify with absolute
00047 certainty an individual from his or her voice.]
00048 
00049 Copyright (C) 2004-2010
00050 Laboratoire d'informatique d'Avignon [http://lia.univ-avignon.fr]
00051 LIA_RAL admin [alize@univ-avignon.fr]
00052 Jean-Francois Bonastre [jean-francois.bonastre@univ-avignon.fr]
00053 */
00054 
00055 #if !defined(ALIZE_UnsupervisedTools_h)
00056 #define ALIZE_UnsupervisedTools_h
00057 
00058 #if defined(_WIN32)
00059 #if defined(LIA_SPKTOOLS_EXPORTS)
00060 #define LIA_SPKTOOLS_API __declspec(dllexport)
00061 #else
00062 #define LIA_SPKTOOLS_API __declspec(dllimport)
00063 #endif
00064 #else
00065 #define LIA_SPKTOOLS_API
00066 #endif
00067 
00068 #include <alize.h>
00069 #include "liatools.h"
00070 
00071 using namespace alize;
00072 using namespace std;
00073 
00074 
00075 
00076 //Accumulate statistics on a frame, a segment,a cluster.
00077 LIA_SPKTOOLS_API void accumulateStatLK(StatServer & ss, FeatureServer & fs, MixtureStat & acc, unsigned long idxBeginFrame, unsigned long nbFrames, Config & config);
00078 LIA_SPKTOOLS_API void accumulateStatLK(StatServer & ss, FeatureServer & fs, MixtureStat & acc, Seg * seg, Config & config);
00079 LIA_SPKTOOLS_API void accumulateStatLK(StatServer & ss, FeatureServer & fs, MixtureStat & acc, SegCluster & selectedSegments, Config & config);
00080 
00081 
00082 
00083 
00084 // The main function for estimate a client model by bayesian adaptattion of a world model
00085 // Using EM and MAP 
00086 //void adaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,MixtureGD &world,MixtureGD &clientMixture);//A.P.
00087 LIA_SPKTOOLS_API void adaptModelEM(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,MixtureGD &world,MixtureGD &clientMixture);//A.P.
00088 LIA_SPKTOOLS_API void adaptModelEM(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,FeatureServer &fs2,SegCluster& selectedSegments2,MixtureGD &aprioriModel,MixtureGD &clientMixture,MAPCfg &mapCfg);
00089 LIA_SPKTOOLS_API void adaptModelEM(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,FeatureServer &fs2,SegCluster& selectedSegments2,
00090                 MixtureGD &aprioriModel,MixtureGD &clientMixture);
00091 LIA_SPKTOOLS_API void adaptModelMAP(Config& config,StatServer &ss,MixtureServer &ms,MixtureGD &world,MixtureGD &clientMixture, unsigned long &frameCount);
00092 LIA_SPKTOOLS_API void adaptModelMAP(Config & config, StatServer & ss, MixtureServer & ms, MixtureGD & aprioriModel, MixtureGD & clientMixture, MAPCfg & mapCfg,  unsigned long &frameCount);
00093 //void adaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,MixtureGD &world,MixtureGD &clientMixture, MAPCfg &cfg);
00094 // ** New training algo based on a true EM/ML estimate of the training data before to apply MAP
00095 LIA_SPKTOOLS_API void modelBasedadaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,
00096                           MixtureGD &aprioriModel,MixtureGD &clientMixture, MixtureGD &initModel);
00097 LIA_SPKTOOLS_API void modelBasedadaptModelEM(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,
00098                           MixtureGD &aprioriModel,MixtureGD &clientMixture, MixtureGD &initModel);
00099 LIA_SPKTOOLS_API void modelBasedadaptModelEM(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,FeatureServer &fsTests,SegCluster& selectedSegmentsTests,MixtureGD &aprioriModel,MixtureGD &clientMixture, MixtureGD &initModel);
00100 LIA_SPKTOOLS_API void adaptModel(Config& config,StatServer &ss,MixtureServer &ms,ObjectRefVector &FeatServ,ObjectRefVector & ClusterSeg,
00101                 MixtureGD &aprioriModel,MixtureGD &clientMixture,DoubleVector &decision);
00102 
00103 
00104 
00105 
00106 //Compute LLR 
00107 //basic
00108 LIA_SPKTOOLS_API double computeLLR(StatServer & ss, FeatureServer & fsTests, MixtureGD & world,
00109                 MixtureGD & clientMixture, SegCluster & selectedSegmentsTests);
00110 //basic and write top information 
00111 LIA_SPKTOOLS_API double computeLLR(Config & config, StatServer & ss, FeatureServer & fsTests,  MixtureGD & world, MixtureGD & clientMixture,
00112                 SegCluster & selectedSegmentsTests, String & idTest);
00113 //Fast by using top information
00114 LIA_SPKTOOLS_API double computeFastLLR(StatServer & ss, FeatureServer & fsTests, MixtureGD & world, MixtureGD & clientMixture, SegCluster & selectedSegmentsTests,
00115                 String & idTest, Config & config);
00116 //modelbased
00117 LIA_SPKTOOLS_API double computeLLRGD(Config & config, MixtureGD & clientMixture, MixtureGD & world,  MixtureGD & dataTest);
00118 
00119 
00120 //compute weights used for adaptation for each tests
00121 //logistic regression, take parameter from the config
00122 LIA_SPKTOOLS_API void expandLLR(DoubleVector & decision, Config & configTest);
00123 //WMAP using gaussian formulae
00124 LIA_SPKTOOLS_API void WMAP(DoubleVector & decision, Config & configTest);
00125 //WMAP on GMM on scores
00126 LIA_SPKTOOLS_API void WMAPGMM(DoubleVector & decision, Config & configTest, MixtureGD & tar,  MixtureGD & non, StatServer & ss);
00127 LIA_SPKTOOLS_API void WMAPGMMFixedPriors(DoubleVector & decision, Config & configTest, MixtureGD & tar,
00128                 MixtureGD & non, StatServer & ss);
00129 LIA_SPKTOOLS_API String getFullFileName(String & id, Config & c);
00130 LIA_SPKTOOLS_API String getFullMixtureName(String & id, Config & c);
00131 LIA_SPKTOOLS_API bool FileExists(String & fullFileName);
00132 
00133 
00134 //compute a MAP model from EM models (fast)
00135 //takes a list of EM models, the number of frames each model was learnt with, and a weight for each model  
00136 LIA_SPKTOOLS_API void computeMAPmodelFromEMones(Config & config, StatServer & ss,  MixtureServer & ms, DoubleVector & nbFramesSelected,
00137                 MixtureGD & aprioriModel, MixtureGD & clientMixture, MixtureGD & aux,  MixtureGD & tmp, DoubleVector & decision, XLine & testsToCompute);
00138 
00139 LIA_SPKTOOLS_API double SegClusterFrame(SegCluster & SegC); //return the number of frames in a cluster
00140 
00141 LIA_SPKTOOLS_API void addLineInXList(XLine &line,XList &list);  
00142 
00143 LIA_SPKTOOLS_API void computePriors(DoubleVector & decision, DoubleVector &priorImp, DoubleVector &priorTar,Config & configTest); //update Imp and Tar priors during the adaptation process
00144 
00145 
00146 //load TNORM or ZNORM parameters, need trials scores on impostor models, a list of the trials name.
00147 
00148 //load impostors scores for TNORM computation from imp_seg.res file
00149 //Must concatenate imp_seg.res and imp_imp.res if you want to do ZTNORM.
00150 LIA_SPKTOOLS_API void loadTnormParam(String &inputClientListFileName,String &testFile,ObjectRefVector &stockTnorm,Config &config);
00151 
00152 
00153 
00154 //Compute Znorm "online", !!!!!could do the same for TNORM but not implemented yet!!!!!
00155 LIA_SPKTOOLS_API void computeAndStoreZnormParam(StatServer &ss, String & inputImpListFileName, String &idclient, MixtureGD &clientMixture,
00156                 ObjectRefVector & stockZnorm, MixtureGD &world, Config & config, bool &ztnorm, ObjectRefVector & stockTnorm);
00157 
00158 //To create Impostor models once
00159 LIA_SPKTOOLS_API void learnMAPimpostorModels(Config & config, DoubleVector &NbFramesSelectedImp,MixtureServer &ms,StatServer &ss,MixtureGD &world);  
00160 
00161 
00162 //Normalize a score, TNORM or ZNORM : the same function is used
00163 LIA_SPKTOOLS_API void normalizeScore(String &test, double &decision, ObjectRefVector &stockNorm);
00164 LIA_SPKTOOLS_API void normalizeScore(String &test, double &decision, ObjectRefVector &stockNorm, double &shift);
00165 
00166 //Oracle TEST 
00167 LIA_SPKTOOLS_API void resetWeights(DoubleVector & decision);
00168 LIA_SPKTOOLS_API void Oracle(String &idTar, String & idTest, double &score, Config & config,MixtureGD & tar,
00169                 MixtureGD & non, StatServer & ss);
00170 
00171 //Compute a train model with a selected percentage of train data, and compute the LLR with the rest of the data (this is done several times ) return the EM estimate and the SegCluster associated
00172 //for the smaller LLR.
00173 LIA_SPKTOOLS_API void crossValid(Config & configTest, StatServer & ss,  MixtureServer & ms, FeatureServer & fs, SegCluster & totalSegments,
00174                 MixtureGD & aprioriModel,MixtureGD & bestModel,SegCluster & selectedSegments,String & idTest);
00175 
00176 //2 purposes : do not recalculate LLR of test data on a client model, and possibility to use RES file from a different recognition system to compute adaptation weights
00177 LIA_SPKTOOLS_API double searchLLRFromResFile(String &idTar, String &test ,String &inputResFilename, Config & config);
00178 
00179 //Create an EM/ML model (1 iter) by weighting each seg thanks to WMAP
00180 LIA_SPKTOOLS_API unsigned long adaptModelEMweightedFrames(String &labelSelectedFrames,XLine & featureFileName,StatServer &ss,MixtureGD &world, MixtureGD &tar, MixtureGD &non,MixtureGD &MixtureforLLR,MixtureGD &MixtureEMOutput, Config &config, FeatureServer &fs, String &fullFileName,String &idTest);
00181 
00182 //Return the String id of the model in a list TARLIstFilename for which the LLR of selectedSegments is MAX. 
00183 LIA_SPKTOOLS_API String selectNearestTarModel(String &TARListFilename, String & fullFileName,Config &config, StatServer & ss, FeatureServer & fs,
00184                 MixtureGD & world,  SegCluster & selectedSegments,MixtureServer &ms);
00185 
00186 //Input : ndx to create target model
00187 //Output : matrix of crossing LLR 
00188 LIA_SPKTOOLS_API void computeLLRmatrix(DoubleMatrix &LLR, XLine &models, XList &features, Config &config, StatServer &ss, MixtureGD & world, MixtureServer &ms,String &labelSelectedFrames);
00189 
00190 
00191 //Method for weighted fusion of MAP models 
00192 LIA_SPKTOOLS_API void fuseMAP(Config & config, StatServer & ss,  MixtureServer & ms, MixtureGD & aprioriModel, MixtureGD & clientMixture, MixtureGD & aux,
00193                 MixtureGD & tmp, DoubleVector & decision, XLine & testsToCompute);
00194 //weighted sum of MAP means of two GMM
00195 LIA_SPKTOOLS_API void fuseMAPMeans(const MixtureGD & model1,double &w1,const MixtureGD & model2,double &w2,MixtureGD &result);
00196 
00197 
00198 LIA_SPKTOOLS_API double computeWeightedLLR(Config & config, StatServer & ss, FeatureServer &fsTests, MixtureServer & ms, MixtureGD & aprioriModel, SegCluster & selectedSegmentsTests,MixtureGD & aux, DoubleVector & decision, XLine & testsToCompute, String &idTest, String &fullfilename);
00199 
00200 //to copy cluster
00201 LIA_SPKTOOLS_API void copyCluster(SegCluster &source, SegCluster &dest);
00202 LIA_SPKTOOLS_API int findClusterInRefvector(ObjectRefVector &SegServ,String & id);
00203 
00204 
00205 //ADAPTATIVE TNORM functions
00206 
00207 //compute all EM ML models for the cohort and store it (one session training)
00208 LIA_SPKTOOLS_API void learnEMimpostorModels(Config & config, DoubleVector &NbFramesSelectedImp,MixtureServer &ms,StatServer &ss,MixtureGD &world);
00209 //load Tnorms models, update it and compute Tnorm on a score
00210 LIA_SPKTOOLS_API double computeAdaptedTnorm(Config & configTest, MixtureServer & ms,StatServer &ss, MixtureGD &world, MixtureGD &auxMixture, MixtureGD &tmpMixture, double &nonorm_score, int &countTests, DoubleVector &decision, DoubleVector &NbFramesSelected, XLine &testsToCompute,
00211                 DoubleVector &NbFramesSelectedImp, FeatureServer &fsTests, SegCluster &selectedSegmentsTests, String &idTest);
00212         
00213 //need a matrix columns : nb session for training , rows : clients LLR
00214 //look for the nearest LLR in the matrix (for a given nb of training session) and returns the delta LLR between one session and the given nb of session
00215 LIA_SPKTOOLS_API double findNearestLLRInMatrix(Matrix <double> &Mat, unsigned long &index, double &LLR);        
00216 
00217 //USE TRAIN DATA TO ASSESS THE ADAPATION WEIGHT
00218 LIA_SPKTOOLS_API void assessAdaptation(StatServer &ss,MixtureGD & adaptedMixture ,SegCluster &selectedSegments, 
00219                 Config &configTest, FeatureServer &fs, MixtureGD &world, DoubleVector &tmp, String &fullFileNameTrain, 
00220                 int countTests, double &tarScore);
00221         
00222 
00223 #endif //!defined(ALIZE_UnsupervisedTools_h)