AccumulateJFAStat.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_AccumulateJFAStat_h)
00056 #define ALIZE_AccumulateJFAStat_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 
00077 
00078 class LIA_SPKTOOLS_API JFATranslate{
00079         XLine _id;
00080         ULongVector _locidx;
00081         ULongVector _sessionidx;
00082 //      RealVector<unsigned long > _locidx;
00083 //  RealVector<unsigned long> _sessionidx;
00084         
00086         long _idxOfID(const String &file) {
00087         _id.rewind();
00088         for(unsigned long i=0;i<_id.getElementCount();i++)
00089                 if(file==_id.getElement(i)) return i;
00090         return -1;
00091         }
00092         
00093         
00094         public:
00095         JFATranslate() {};
00096 
00099         JFATranslate(XList &fileList) {
00100                 fileList.rewind(); XLine *pline;String *pFile;
00101                 unsigned long sent=0;
00102                 unsigned long loc=0;
00103                 while((pline=fileList.getLine())!=NULL) { 
00104                         while((pFile=pline->getElement())!=NULL) {
00105                                 _id.addElement(*pFile);
00106                                 _locidx.addValue(loc);
00107                                 _sessionidx.addValue(sent);
00108                                 sent++;
00109                         }
00110                         loc++;
00111                 }
00112         };
00113         ~JFATranslate() {};
00114                 
00119         unsigned long locNb(const String &file) {
00120                 unsigned long idx=_idxOfID(file);
00121                 if (idx==-1) throw Exception("File not known",__FILE__,__LINE__);
00122                 return _locidx[idx];
00123                 }
00124 
00129         unsigned long firstSession(unsigned long spk) {
00130                 unsigned long i;
00131                 for(i=0;;i++) if (_locidx[i]==spk) break;
00132                 return (_sessionidx[i]);
00133                 }
00134                 
00140         unsigned long numSession(unsigned long spk, unsigned long session) {
00141                 unsigned long i, cnt;
00142                 if(spk==0) return(session);
00143                 for(i=session-1,cnt=0;;i--,cnt++) if (_locidx[i]!=spk) break;
00144                 return (cnt);
00145                 }
00146 
00151         unsigned long locNb(unsigned long idx) {
00152                 return _locidx[idx];
00153         }
00154         
00159         unsigned long sessionNb(const String &file) {
00160                 long idx=_idxOfID(file);
00161                 if (idx==-1) throw Exception("File not known",__FILE__,__LINE__);
00162         return _sessionidx[idx];
00163         }
00164 };
00165 
00173 
00174 class LIA_SPKTOOLS_API JFAAcc{
00175 
00176         private :
00177 
00178                 MixtureServer _ms;
00179                 StatServer _ss;
00180         
00181                 XList _fileList; 
00182                 unsigned long _vectSize;
00183                 unsigned long _n_distrib;
00184                 unsigned long _svSize;
00185                 unsigned long _rankEC;
00186                 unsigned long _rankEV;
00187                 unsigned long _n_speakers;
00188                 unsigned long _n_sessions;
00189         
00191                 RealVector<double> _ubm_means;
00192                 RealVector<double> _ubm_invvar;
00193 
00195                 Matrix<double> _matN;
00196                 Matrix<double> _N_h;
00197                 Matrix<double> _F_X;
00198                 Matrix<double> _F_X_h;
00199                 
00201                 Matrix<double> _cN;
00202                 Matrix<double> _cN_h;
00203                 Matrix<double> _cF_X;
00204                 Matrix<double> _cF_X_h;
00205 
00207                 RealVector<double> _D;
00208                 Matrix<double> _V;
00209                 Matrix<double> _matU;
00210                 Matrix<double> _VU;
00211 
00212                 Matrix<double> _Z;
00213                 Matrix<double> _Y;
00214                 Matrix<double> _matX;
00215                 Matrix<double> _YX;
00216                 
00218                 RefVector<DoubleSquareMatrix> _vEvT;
00220                 RefVector<DoubleSquareMatrix> _uEuT;
00222                 RefVector<DoubleSquareMatrix> _vuEvuT;
00223                 
00225                 RefVector<DoubleSquareMatrix> _l_spk_inv;
00226                 RefVector<DoubleSquareMatrix> _l_sess_inv;
00227                 RefVector<DoubleSquareMatrix> _l_yx_inv;
00228                 
00230                 RefVector<DoubleSquareMatrix> _Aev;
00231                 Matrix<double> _Cev;
00232                 RefVector<DoubleSquareMatrix> _Aec;
00233                 Matrix<double> _Cec;
00234                 
00239                 void _init(XList & list,Config & config);
00240 
00241 
00242         public :
00243 
00245                 JFATranslate _ndxTable;
00246         
00247                 JFAAcc(String &,Config &);
00248                 JFAAcc(XList &,Config & );
00249                 virtual ~JFAAcc();
00250                 virtual String getClassName() const;
00251         
00255                 void computeAndAccumulateJFAStat(Config& config);
00256         
00260                 void computeAndAccumulateJFAStatUnThreaded(Config& config);
00261         
00265                 #ifdef THREAD
00266 
00267 
00268 
00269                         void computeAndAccumulateJFAStatThreaded(Config&);
00270                 #endif
00271         
00276                 void computeAndAccumulateJFAStat(FeatureServer & fs,Config & config);
00277                 
00283                 void computeAndAccumulateJFAStat(SegCluster & sc,FeatureServer & fs,Config & config);
00284 
00287                 void resetAcc();
00288 
00291                 void resetTmpAcc();
00292 
00297                 void loadEV(const String& file, Config& config);
00298 
00302                 void loadEV(Matrix<double> & mat, Config& config);
00303 
00308                 void loadEC(const String&, Config&);
00309 
00313                 void loadEC(Matrix<double> & mat, Config& config);
00314 
00319                 void loadD(const String& file, Config& config);
00320 
00324                 void loadD(DoubleVector & vec);
00325 
00329                 void loadN(Config&);
00330 
00334                 void loadN_h(Config&);
00335 
00339                 void loadF_X(Config&);
00340 
00344                 void loadF_X_h(Config&);
00345 
00348                 void initEV(Config&);
00349 
00352                 void initEC(Config&);
00353 
00354                 // Initialise the D matrix using the MAP paradigm
00356                 void initD(Config&);
00357 
00360                 void initVU();
00361 
00365                 void saveV(const String& file, Config& config);
00366 
00370                 void saveU(const String& file, Config& config);
00371 
00375                 void saveD(const String& file, Config& config);
00376         
00380                 void estimateVEVT(Config & config);
00381 
00384                 void estimateVEVTUnThreaded();
00385 
00389                 void estimateUEUT(Config & config);
00390 
00393                 void estimateUEUTUnThreaded();
00394 
00398                 void estimateVUEVUT(Config &);
00399 
00402                 void estimateVUEVUTUnThreaded();
00403 
00404                 #ifdef THREAD
00405 
00406 
00407 
00408                         void estimateVEVTThreaded(unsigned long threads);
00409 
00413                         void estimateUEUTThreaded(unsigned long threads);
00414 
00418                         void estimateVUEVUTThreaded(unsigned long threads);
00419                 #endif
00420                 
00425                 void getVY(DoubleVector & vy, String & file);
00426 
00431                 void getVY(DoubleVector &file, unsigned long spk);
00432 
00437                 void getVUYX(DoubleVector &vuyx, String & file);
00438 
00443                 void getVUYX(DoubleVector &vuyx, unsigned long spk);
00444 
00449                 void getDZ(DoubleVector & dz, unsigned long spk);
00450 
00455                 void getUX(DoubleVector & ux, unsigned long session);
00456 
00461                 void getUX(DoubleVector &ux, String& file);
00462 
00467                 void getVYplusDZ(DoubleVector &vyplusdz, String &file);
00468 
00473                 void getVYplusDZ(DoubleVector &, unsigned long spk);
00474                 
00479                 void getMplusDZ(DoubleVector &MplusDZ, String& file);
00480 
00485                 void getMplusDZ(DoubleVector &MplusDZ, unsigned long spk);
00486 
00491                 void getMplusVY(DoubleVector &MplusVY, String& file);
00492 
00497                 void getMplusVY(DoubleVector &MplusVY, unsigned long spk);
00498 
00503                 void getMplusUX(DoubleVector &MplusUX, String& file);
00504 
00509                 void getMplusUX(DoubleVector &MplusUX, unsigned long session);
00510 
00515                 void getMplusVYplusDZ(DoubleVector &, String& file);
00516 
00521                 void getMplusVYplusDZ(DoubleVector &, unsigned long spk);
00522 
00527                 void getMplusVUYX(DoubleVector &MplusVUYX, String& file);
00528 
00533                 void getMplusVUYX(DoubleVector &MplusVUYX, unsigned long spk);  
00534                 
00538                 void estimateAndInverseL_EV(Config&);
00539 
00542                 void estimateAndInverseLUnThreaded_EV();
00543 
00547                 void estimateAndInverseL_EC(Config&);
00548 
00551                 void estimateAndInverseLUnThreaded_EC();
00552                 
00556                 void estimateAndInverseL_VU(Config&);
00557 
00560                 void estimateAndInverseLUnThreaded_VU();
00561                 
00565                 void estimateYandV(Config &);
00566 
00569                 void estimateYandVUnThreaded();
00570                 
00571                 #ifdef THREAD
00572 
00573 
00574 
00575                         void estimateAndInverseLThreaded_EV(unsigned long threads);
00576 
00580                         void estimateAndInverseLThreaded_EC(unsigned long threads);
00581 
00585                         void estimateAndInverseLThreaded_VU(unsigned long threads);
00586 
00590                         void estimateYandVThreaded(unsigned long threads);
00591                 #endif
00592                 
00596                 void estimateY(Config &);
00597 
00600                 void estimateYUnThreaded();
00601 
00605                 void estimateXandU(Config &);
00606 
00609                 void estimateXandUUnThreaded();
00610 
00614                 void estimateX(Config &);
00615 
00618                 void estimateXUnThreaded();
00619 
00620                 #ifdef THREAD
00621 
00622 
00623 
00624                         void estimateXandUThreaded(unsigned long threads);
00625 
00629                         void estimateXThreaded(unsigned long threads);
00630 
00634                         void estimateYThreaded(unsigned long threads);
00635                 #endif
00636 
00639                 void estimateU();
00640 
00643                 void estimateZandD();
00644 
00647                 void estimateYX();
00648 
00651                 void estimateZ();
00652 
00656                 void estimateZMAP(unsigned long tau);
00657                 
00660                 void updateVestimate();
00661 
00664                 void updateUestimate();
00665                 
00668                 XList& getXList();
00669 
00672                 unsigned long getNSpeakers();
00673 
00676                 unsigned long getNSessions();
00677 
00680                 unsigned long getNDistrib();
00681 
00684                 unsigned long getVectSize();
00685 
00688                 unsigned long getSvSize();
00689 
00692                 unsigned long getRankEV();
00693 
00696                 unsigned long getRankEC();
00697                 
00700                 DoubleVector& getUbmMeans();
00701 
00704                 DoubleVector& getUbmInvVar();
00705                 
00708                 Matrix<double> getV();
00709 
00712                 Matrix<double> getU();
00713 
00716                 DoubleVector getD();
00717 
00718                 // Return the EigenVoice and EigenChannel matrices concatenated
00720                 Matrix<double> getVU();
00721                 
00724                 Matrix<double> getY();
00725 
00728                 Matrix<double> getX();
00729 
00732                 Matrix<double> getZ();
00733 
00736                 Matrix<double> getYX();
00737                 
00740                 void splitYX();
00741 
00744                 void storeAccs();
00745 
00748                 void restoreAccs();
00749                 
00753                 void substractMplusDZ(Config & config);
00754 
00757                 void substractMplusDZUnThreaded();
00758 
00762                 void substractMplusVY(Config &);
00763 
00766                 void substractMplusVYUnThreaded();
00767 
00768 
00772                 void substractUX(Config & config);
00773 
00776                 void substractUXUnThreaded();
00777                 
00781                 void substractMplusUX();                                //creer la fonction multithread
00782 
00785                 void substractMplusVUYX();                              //creer la fonction multithread
00786                 
00790                 void substractMplusVYplusDZ(Config &);
00791 
00794                 void substractMplusVYplusDZUnThreaded();
00795 
00798                 void substractMplusDZByChannel();               //creer la version multithread
00799                 
00800                 #ifdef THREAD
00801 
00802 
00803 
00804                 void substractMplusDZThreaded(unsigned long threads);
00805 
00809                 void substractUXThreaded(unsigned long threads);
00810 
00814                 void substractMplusVYplusDZThreaded(unsigned long threads);
00815 
00819                 void substractMplusVYThreaded(unsigned long threads);
00820                 #endif
00821 
00826                 void getSpeakerModel(MixtureGD &mixture, String& file);
00827 
00833                 void normalizeFeatures(alize::SegCluster& segCluster, alize::FeatureServer& featureServer, alize::Config& config);
00834 
00839                 void substractUXfromFeatures(FeatureServer &fs,Config &config);
00840 
00844                 void saveAccs(Config &config);
00845                 
00851                 double getLLK(SegCluster &selectedSegments,MixtureGD &model,FeatureServer&fs,Config & config);
00852 
00858                 void verifyEMLK(Config& config);
00859 
00862                 Matrix <double>& getN();
00863 
00866                 Matrix <double>& getN_h();
00867 
00870                 Matrix <double>& getF_X();
00871 
00874                 Matrix <double>& getF_X_h();
00875 
00876 };
00877 #endif