FactorAnalysis.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_FactorAnalysis_h)
00056 #define ALIZE_FactorAnalysis_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 <liatools.h>
00069 
00070 class TopGauss;
00071 
00073 class LIA_SPKTOOLS_API Translate {
00074         XLine _id;
00075         ULongVector _locidx;
00076         ULongVector _sessionidx;
00077         
00079         long _idxOfID(const String &file) {
00080         _id.rewind();
00081         for(unsigned long i=0;i<_id.getElementCount();i++)
00082                 if(file==_id.getElement(i)) return i;
00083         return -1;
00084         }
00085         
00086         public:
00087         Translate() {};
00088                 
00090         Translate(XList &fileList) {
00091                 fileList.rewind(); XLine *pline;String *pFile;
00092                 unsigned long sent=0;
00093                 unsigned long loc=0;
00094                 while((pline=fileList.getLine())!=NULL) { 
00095                         while((pFile=pline->getElement())!=NULL) {
00096                                 _id.addElement(*pFile);
00097                                 _locidx.addValue(loc);
00098                                 _sessionidx.addValue(sent);
00099                                 sent++;
00100                         }
00101                         loc++;
00102                 }
00103         };
00104         ~Translate() {};
00105                 
00107         unsigned long locNb(const String &file) {
00108                 long idx=_idxOfID(file);
00109                 if (idx==-1) throw Exception("File not known",__FILE__,__LINE__);
00110         return _locidx[idx];
00111         }
00112         
00114         unsigned long sessionNb(const String &file) {
00115                 long idx=_idxOfID(file);
00116                 if (idx==-1) throw Exception("File not known",__FILE__,__LINE__);
00117         return _sessionidx[idx];    
00118         }
00119 };
00120 
00121 class LIA_SPKTOOLS_API FactorAnalysisStat {
00122   private :
00123         XList fileList; 
00124         unsigned long _vsize;
00125         unsigned long _mixsize;
00126         unsigned long _supervsize;
00127         unsigned long _rang;
00128         unsigned long  _nb_speakers;
00129         unsigned long  _nb_sent;
00131         double _tau; 
00132 
00133         bool _topGauss;
00134   
00135     MixtureServer _ms;
00136         StatServer _ss;
00137   
00138         Matrix <double> _matX;
00139         Matrix <double> _matY;
00140         RealVector <double> _D;
00141         Matrix <double> _matU;
00142   
00144         Matrix<double> _matS_X;
00145         Matrix<double> _matS_X_h;
00146         Matrix<double> _matN;
00147         Matrix<double> _matN_h;
00148         
00150         Matrix<double> matcS_X;
00151         Matrix<double> matcS_X_h;
00152         Matrix<double> matcN;
00153         Matrix<double> matcN_h; 
00154         
00156         RefVector <DoubleSquareMatrix> _l_h_inv;
00157         
00159         RealVector<double> _super_mean;
00160         RealVector<double> _super_invvar;
00161         
00163         void _init(XList &,FeatureServer &,Config &);
00164         
00165   public :
00167         Translate _ndxTable;
00168   
00170         FactorAnalysisStat(XList &,FeatureServer&,Config & config); 
00171         FactorAnalysisStat(String &,FeatureServer&,Config & config);
00172         ~FactorAnalysisStat() {
00173                 _l_h_inv.deleteAllObjects();
00174         }
00176         void computeAndAccumulateGeneralFAStats(FeatureServer&,Config & config);
00177         void computeAndAccumulateGeneralFAStats(SegCluster&,FeatureServer&,Config & config);    
00178         
00180         void getXEstimate(); 
00181         
00183         void getYEstimate();
00184         
00186         void getUEstimate(Config &); 
00187         void getUEstimateUnThreaded(); 
00188         #if defined(THREAD)
00189         void getUEstimateThreaded(unsigned long);// threaded version of estimate U      
00190         #endif  
00191         
00193         void estimateAndInverseL(Config &);
00194         void estimateAndInverseLUnThreaded();
00195         #if defined(THREAD)     
00196         void estimateAndInverseLThreaded(unsigned long);// threaded version of inverse L        
00197         #endif
00198         
00200         //void getLLK(Config & config);
00201         double getLLK(SegCluster &,MixtureGD &,FeatureServer &,Config &); 
00202         
00204         void substractSpeakerStats(); 
00205         void substractChannelStats();
00206         
00208         void normalizeFeatures(FeatureServer&,Config &);        
00209         void normalizeFeatures(SegCluster &selectedSegments,FeatureServer &fs,Config & config); 
00210         //void normalizeFeatures(TopGauss &tg,SegCluster &selectedSegments,FeatureServer &fs,MixtureGD &model,RealVector<double> m_xh_1,Config & config);       
00211 
00213         void estimateXYAndNorm(FeatureServer &,Config &);       
00214         void estimateXYAndNorm(SegCluster&,FeatureServer &,Config &);
00215 
00217         void getUX(RealVector <double> &,String&);      
00218         void getMplusDY(RealVector <double> &,String&);                 
00219 
00221         void setYFromModel(MixtureGD&,String&); 
00222         void estimateXForKnownSpeaker(MixtureGD &,String&,Config &);
00223         void getTrueSpeakerModel(MixtureGD &,String&); 
00224         void getSpeakerModel(MixtureGD &,String&);
00225         void getSessionModel(MixtureGD &,String&);      
00226         void getFactorAnalysisModel(MixtureGD&,String&);
00227         
00229         void resetAcc() {
00230                 _matS_X.setAllValues(0.0);      
00231                 _matS_X_h.setAllValues(0.0);    
00232                 _matN_h.setAllValues(0.0);
00233                 _matN.setAllValues(0.0);        
00234                 if (verbose) cout << "# FA Accumulators reset" << endl;
00235         }
00236         void resetXY() {
00237                 _matY.setAllValues(0.0);
00238                 _matX.setAllValues(0.0);                        
00239         }
00240         
00242         void storeAccs() {
00243                 matcS_X=_matS_X;
00244                 matcS_X_h=_matS_X_h;
00245                 matcN_h=_matN_h; 
00246                 matcN=_matN;
00247                 if (verbose) cout << "(FactorAnalysisStat) FA Accs states stored" << endl;              
00248         }       
00249         
00251         void restoreAccs() {    
00252                 _matS_X=matcS_X;
00253                 _matS_X_h=matcS_X_h;
00254                 _matN_h=matcN_h;
00255                 _matN=matcN;    
00256                 if (verbose) cout << "(FactorAnalysisStat) FA Accs states restored" << endl;                    
00257         }       
00258         
00260         void saveAccs(Config &config) {
00261                 _matS_X.save("S_X.mat",config);
00262                 _matS_X_h.save("S_X_h.mat",config);
00263                 _matN_h.save("N_h.mat",config); 
00264                 _matN.save("N.mat",config);
00265                 if (verbose) cout << "(FactorAnalysisStat) FA Accs states saved" << endl;               
00266         }               
00267         
00269         void loadAccs(Config &config) { 
00270                 _matS_X.load("S_X.mat",config);
00271                 _matS_X_h.load("S_X_h.mat",config);
00272                 _matN_h.load("N_h.mat",config); 
00273                 _matN.load("N.mat",config);
00274                 if (verbose) cout << "(FactorAnalysisStat) FA Accs states loaded" << endl;              
00275         }
00276         
00278         MixtureServer & getMixtureServer() {
00279                 return this->_ms;}
00280         StatServer & getStatServer() {
00281                 return this->_ss;}
00282                 XList & getFileList() {
00283                 return this->fileList;} 
00284         unsigned long &getNbEx() {
00285                 return _nb_sent;}       
00286         Matrix <double>& getU() {
00287                 return _matU;}          
00288         Matrix <double>& getY() {
00289                 return _matY;}  
00290         Matrix <double>& getX() {
00291                 return _matX;}  
00292         RealVector <double>& getD() {
00293                 return _D;}                     
00294         unsigned long getRank() {
00295                 return _rang;}                  
00296         void setU(Matrix <double>& U) {
00297                 _matU=U;}       
00298         void setX(Matrix <double>& X) {
00299                 _matX=X;}       
00300         void setY(Matrix <double>& Y) {
00301                 _matY=Y;}       
00302 };
00303 
00304 #endif