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_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);
00190 #endif
00191
00193 void estimateAndInverseL(Config &);
00194 void estimateAndInverseLUnThreaded();
00195 #if defined(THREAD)
00196 void estimateAndInverseLThreaded(unsigned long);
00197 #endif
00198
00200
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
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