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_TrainTools_h)
00056 #define ALIZE_TrainTools_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 class LIA_SPKTOOLS_API MAPCfg {
00075 String _method;
00076 double _r[3];
00077 bool _mean,_var,_weight;
00078 unsigned long _nbTrainIt;
00079 unsigned long _nbEmIt;
00080 bool _normalizeModel;
00081 bool _normalizeModelMeanOnly;
00082 unsigned long _normalizeModelNbIt;
00083 double _baggedFrameProbability;
00084 public:
00085 MAPCfg(Config &);
00086 String &getMethod(){return _method;}
00087 void showConfig(ostream & st);
00088 bool getMeanAdapt() { return _mean;}
00089 bool getVarAdapt() { return _var;}
00090 bool getWeightAdapt(){ return _weight;}
00091 double getMeanReg() { return _r[0];}
00092 double getVarReg() { return _r[1];}
00093 double getWeightReg() { return _r[2];}
00094 double getMeanAlpha() { return _r[0];}
00095 double getVarAlpha() { return _r[1];}
00096 double getWeightAlpha() { return _r[2];}
00097 unsigned long getNbTrainIt(){return _nbTrainIt;}
00098 unsigned long getNbEmIt(){return _nbEmIt;}
00099 bool getNormalizeModel(){return _normalizeModel;}
00100 bool getNormalizeModelMeanOnly(){return _normalizeModelMeanOnly;}
00101 unsigned long getNormalizeModelNbIt(){return _normalizeModelNbIt;}
00102 double getBaggedFrameProbability(){return _baggedFrameProbability;}
00103 void setMethod(String v) {_method=v;}
00104 void setMeanAdapt(bool v) {_mean=v;}
00105 void setVarAdapt(bool v) { _var=v;}
00106 void setWeightAdapt(bool v){ _weight=v;}
00107 void setMeanReg(double v) { _r[0]=v;}
00108 void setVarReg(double v) { _r[1]=v;}
00109 void setWeightReg(double v) { _r[2]=v;}
00110 void setMeanAlpha(double v) { _r[0]=v;}
00111 void setVarAlpha(double v) { _r[1]=v;}
00112 void setWeightAlpha(double v) { _r[2]=v;}
00113 void setNbTrainIt(unsigned long v){_nbTrainIt=v;}
00114 void setNbEmIt(unsigned long v){_nbEmIt=v;}
00115 void setNormalizeModel(bool v){_normalizeModel=v;}
00116 void setNormalizeModelMeanOnly(bool v){_normalizeModelMeanOnly=v;}
00117 void setNormalizeModelNbIt(unsigned long v){_normalizeModelNbIt=v;}
00118 void setBaggedFrameProbability(double v){_baggedFrameProbability=v;}
00119 };
00120
00121
00122 class LIA_SPKTOOLS_API TrainCfg{
00123 double _initVarianceFlooring;
00124 double _initVarianceCeiling;
00125 double _finalVarianceFlooring;
00126 double _finalVarianceCeiling;
00127 unsigned long _nbTrainIt;
00128 bool _normalizeModel;
00129 bool _normalizeModelMeanOnly;
00130 unsigned long _normalizeModelNbIt;
00131 double _baggedFrameProbability;
00132 double _baggedFrameProbabilityInit;
00133 bool _componentReduction;
00134 unsigned long _targetDistribCount;
00135 public:
00136 TrainCfg(Config &);
00137 double getInitVarFloor(){return _initVarianceFlooring;}
00138 double getInitVarCeil(){return _initVarianceCeiling;}
00139 double getFinalVarFloor(){return _finalVarianceFlooring;}
00140 double getFinalVarCeil(){return _finalVarianceCeiling;}
00141 unsigned long getNbTrainIt(){return _nbTrainIt;}
00142 bool getNormalizeModel(){return _normalizeModel;}
00143 bool getNormalizeModelMeanOnly(){return _normalizeModelMeanOnly;}
00144 unsigned long getNormalizeModelNbIt(){return _normalizeModelNbIt;}
00145 double getBaggedFrameProbability(){return _baggedFrameProbability;}
00146 double getBaggedFrameProbabilityInit(){return _baggedFrameProbabilityInit;}
00147 bool getComponentReduction(){return _componentReduction;}
00148 unsigned long getTargetDistribCount(){return _targetDistribCount;}
00149 void setInitVarFlooring (double v){_initVarianceFlooring=v;}
00150 void setInitVarCeiling (double v){_initVarianceCeiling=v;}
00151 void setFinalVarFlooring (double v){_finalVarianceFlooring=v;}
00152 void setFinalVarCeiling (double v){_finalVarianceCeiling=v;}
00153 void setNbTrainIt(unsigned long v){_nbTrainIt=v;}
00154 void setNormalizeModel(bool v){_normalizeModel=v;}
00155 void setNormalizeModelMeanOnly(bool v){_normalizeModelMeanOnly=v;}
00156 void setNormalizeModelNbIt(unsigned long v){_normalizeModelNbIt=v;}
00157 void setBaggedFrameProbability(double v){_baggedFrameProbability=v;}
00158 void setBaggedFrameProbabilityInit(double v){_baggedFrameProbabilityInit=v;}
00159 void showConfig(ostream &);
00160 };
00161
00162 LIA_SPKTOOLS_API void fuseModels(const MixtureGD &,unsigned long,const MixtureGD &,unsigned long,MixtureGD &);
00163 LIA_SPKTOOLS_API void copyMixture(DistribGD &,DistribGD &);
00164 LIA_SPKTOOLS_API unsigned long selectComponent(bool selectCompA[],XList & distribL, MixtureGD &inputM);
00165 LIA_SPKTOOLS_API unsigned long selectComponent(bool selectCompA[],double wFactor,MixtureGD &inputM);
00166 LIA_SPKTOOLS_API unsigned long selectComponent(bool selectCompA[],unsigned long nbTop,MixtureGD &inputM);
00167 LIA_SPKTOOLS_API double reduceModel(bool selectCompA[],MixtureGD &inputM,MixtureGD &outputM);
00168 LIA_SPKTOOLS_API void normalizeWeights(MixtureGD &outputM);
00169
00170
00171 LIA_SPKTOOLS_API void gaussianFusion(const DistribGD &g1,double w1,const DistribGD & g2,double w2, DistribGD &res,double &w);
00172 LIA_SPKTOOLS_API void mixtureFusion(const MixtureGD &mixt,DistribGD &res,double &wres);
00173
00174
00175
00176
00177 LIA_SPKTOOLS_API void normalizeMixture(MixtureGD &mixt,const DoubleVector &meanSignal,const DoubleVector &covSignal,bool zeroOne,
00178 unsigned long nbIt, bool meanOnly,Config &config);
00179 LIA_SPKTOOLS_API void normalizeMixture(MixtureGD &mixt,const DoubleVector &meanSignal,const DoubleVector &covSignal,Config &config);
00180
00181 LIA_SPKTOOLS_API void normalizeMixture(MixtureGD &mixt,Config &config);
00182 LIA_SPKTOOLS_API void normalizeMixture(MixtureGD & mixt, MAPCfg & mapCfg, Config & config);
00183
00184 LIA_SPKTOOLS_API double likelihoodLoss(const DistribGD &g1,double w1,const DistribGD &g2,double w2);
00185 LIA_SPKTOOLS_API double *outputMAPTransformation(MixtureGD & world, MixtureGD & clientMixture,
00186 Config & config);
00187
00188
00189
00190 LIA_SPKTOOLS_API void computeMAP(MixtureServer &ms,const MixtureGD& world,MixtureGD &client,unsigned long frameCount,Config &config);
00191 LIA_SPKTOOLS_API void computeMAP(MixtureServer &ms,const MixtureGD& world,MixtureGD &client,unsigned long frameCount,MAPCfg &cfg);
00192
00193
00194 LIA_SPKTOOLS_API void copyMean(MixtureGD & mixtS, MixtureGD & mixtD);
00195 LIA_SPKTOOLS_API void copyVar(MixtureGD & mixtS, MixtureGD & mixtD);
00196 LIA_SPKTOOLS_API void copyWeight(MixtureGD & mixtS, MixtureGD & mixtD);
00197
00198
00199 LIA_SPKTOOLS_API double setItParameter(double begin, double end, int nbIt, int it);
00200
00201
00202 LIA_SPKTOOLS_API void varianceControl(MixtureGD& model,double flooring,double ceiling,const DoubleVector &covSignal);
00203
00204
00205
00206
00207
00208 LIA_SPKTOOLS_API unsigned long computeMeanCov(Config &config,FeatureServer **fsTab,SegCluster ** segTab,unsigned long nbStream,DoubleVector &mean,DoubleVector &cov);
00209 LIA_SPKTOOLS_API unsigned long computeMeanCov(Config &config,FeatureServer &fs,SegCluster &seg,DoubleVector &mean,DoubleVector &cov);
00210 LIA_SPKTOOLS_API void initialize01(unsigned long vectSize,DoubleVector &mean,DoubleVector &cov);
00211
00212 LIA_SPKTOOLS_API MixtureGD &mixtureInit(MixtureServer &ms,FeatureServer &fs,MixtureGD &world,
00213 SegCluster &selectedSegments,const DoubleVector &globalCov, Config& config);
00214 LIA_SPKTOOLS_API MixtureGD &mixtureInit(MixtureServer &ms,FeatureServer &fs,MixtureGD &world,
00215 SegCluster &selectedSegments,const DoubleVector &globalCov, Config& config,TrainCfg & trainCfg);
00216 LIA_SPKTOOLS_API MixtureGD &mixtureInit(MixtureServer &ms,FeatureServer **fsTab, SegCluster **segTab,double *weightTab,unsigned long nbStream,MixtureGD &world,
00217 const DoubleVector &globalCov, Config& config,TrainCfg &trainCfg);
00218 LIA_SPKTOOLS_API MixtureGD &mixtureInit(MixtureServer &ms,FeatureServer **fsTab, SegCluster **segTab,double*weightTab,unsigned long nbStream,MixtureGD &world,
00219 const DoubleVector &globalCov, Config& config);
00220
00221
00222 LIA_SPKTOOLS_API void adaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,MixtureGD &world,MixtureGD &clientMixture);
00223 LIA_SPKTOOLS_API void adaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,MixtureGD &world,MixtureGD &clientMixture, MAPCfg &cfg);
00224
00225 LIA_SPKTOOLS_API void modelBasedadaptModel(Config& config,StatServer &ss,MixtureServer &ms,FeatureServer &fs,SegCluster& selectedSegments,
00226 MixtureGD &aprioriModel,MixtureGD &clientMixture, MixtureGD &initModel);
00227
00228
00229
00230
00231
00232
00233
00234
00235 LIA_SPKTOOLS_API void trainModel(Config& config,StatServer &ss,FeatureServer &fs,SegCluster& selectedSegments,
00236 DoubleVector & globalMean,DoubleVector &globalCov,MixtureGD &world);
00237 LIA_SPKTOOLS_API void trainModel(Config& config,StatServer &ss,FeatureServer &fs,SegCluster& selectedSegments,
00238 DoubleVector & globalMean,DoubleVector &globalCov,MixtureGD &world,TrainCfg &trainCfg);
00239 LIA_SPKTOOLS_API void trainModelStream(Config& config,MixtureServer &ms,StatServer &ss,FeatureServer **fsTab,SegCluster** segTab,double *weightTab,unsigned long nbStream,
00240 DoubleVector & globalMean,DoubleVector &globalCov,MixtureGD* &world,TrainCfg &trainCfg);
00241 LIA_SPKTOOLS_API void trainModel(Config& config,MixtureServer &ms,StatServer &ss,FeatureServer **fsTab,SegCluster** segTab,double *weightTab,unsigned long nbStream,
00242 DoubleVector & globalMean,DoubleVector &globalCov,MixtureGD* &world);
00243
00244
00245
00246 LIA_SPKTOOLS_API Matrix<double> computeMLLR (MixtureGD &inM,MixtureGD& outM,unsigned long frameCount, Config &config);
00247
00248
00249 #endif //!defined(ALIZE_TrainTools_h)