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_GeneralTools_h)
00056 #define ALIZE_GeneralTools_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 const unsigned long CST_MAX_CLIENT_LINE=500;
00077
00078 class LIA_SPKTOOLS_API TabClientLine{
00079 unsigned long nbMaxModelLine;
00080 MixtureServer *ms;
00081 Config *conf;
00082 MixtureGD ** tabModel;
00083 XLine *pline;
00084 unsigned long nbModelsLine;
00085
00086 public:
00087 unsigned long nbClientLine();
00088 String& getClientName(unsigned long);
00089 MixtureGD& getClientModel(unsigned long);
00090 unsigned long loadLine(XLine*,String="",bool=true,bool=false);
00091 TabClientLine(MixtureServer &, Config &, unsigned long=CST_MAX_CLIENT_LINE);
00092 ~TabClientLine();
00093 };
00094
00095
00096
00097 class LIA_SPKTOOLS_API TabHisto{
00098 unsigned long _nb;
00099 ObjectRefVector _tabHisto;
00100 XLine _id;
00101 public:
00102 TabHisto(unsigned long nbBins, unsigned long maxTargetLine){_nb=0;for (unsigned int i=0;i<maxTargetLine;i++) _tabHisto.addObject(*(new Histo(nbBins)));}
00103 ~TabHisto(){_tabHisto.deleteAllObjects();}
00104 unsigned long getSize(){return _nb;}
00105 void accumulateValueInTab(const String &id,double score);
00106 Histo & getHisto(const String &id);
00107 void computeHistoInTab(const String &id);
00108 String & getId(unsigned long n);
00109 unsigned long getIndex(const String &id);
00110 Histo & getHistoFromVect(unsigned long n);
00111 };
00112
00113
00114
00115
00116 LIA_SPKTOOLS_API double computeEntropy(Histo & hist);
00117
00118
00119
00120 LIA_SPKTOOLS_API double computeMean(Histo & hist);
00121
00122
00123 LIA_SPKTOOLS_API long setDecision(double LLRClient, double decisionThreshold);
00124
00125
00126
00127
00128 class LIA_SPKTOOLS_API ScoreAccum{
00129 unsigned long _nb;
00130 DoubleVector _score;
00131 ULongVector _nbFrame;
00132 XLine _id;
00133 public:
00134 ScoreAccum(){_nb=0;}
00135 ~ScoreAccum(){}
00136 unsigned long getSize(){return _nb;}
00137 void addAndAccumulate(const String &id,double score, unsigned long nbFrames);
00138 double getScore(const String &id);
00139 double getScore(unsigned long n);
00140 String & getId(unsigned long n);
00141 unsigned long getIndex(const String &id);
00142 };
00143
00144
00145 struct TabWeightElem{
00146 double weight;
00147 unsigned long distrib;
00148 DistribGD *distribP;
00149 };
00150
00151 LIA_SPKTOOLS_API int _compF(const void * op1, const void *op2);
00152
00153 class LIA_SPKTOOLS_API TabWeight{
00154 unsigned long _size;
00155 TabWeightElem *_tab;
00156 unsigned long _nbTop;
00157 void _sortByWeight(const MixtureGD &data){
00158 for(unsigned i=0;i<_size;i++){
00159 _tab[i].weight=data.weight(i);
00160 _tab[i].distrib=i;
00161 _tab[i].distribP=&(data.getDistrib(i));
00162 }
00163 qsort ( (void *) _tab,_size, sizeof(TabWeightElem),_compF);
00164 }
00165 void _nbTopDyn(double threshold){
00166 _nbTop=0;
00167 for (double tot=0;(_nbTop<_size)&&(tot<threshold);_nbTop++) tot+=_tab[_nbTop].weight;
00168 if (verbose) cout <<"Dyn nb top["<<_nbTop<<"]"<<endl;
00169 }
00170 public:
00171 TabWeight(){};
00172 TabWeight(const MixtureGD &);
00173 TabWeight(const MixtureGD &,unsigned long);
00174 TabWeight(const MixtureGD &,double);
00175 void init(const MixtureGD &,unsigned long);
00176 void init(const MixtureGD &,double);
00177 unsigned long getNbTop(){return _nbTop;}
00178 unsigned long getDistrib(unsigned long id){return _tab[id].distrib;}
00179 double getWeight(unsigned long id){return _tab[id].weight;}
00180 void setDistrib(unsigned long id,unsigned long distrib,double weight){_tab[id].distrib=distrib;_tab[id].weight=weight;}
00181 TabWeightElem *getArray(){return _tab;}
00182 ~TabWeight(){delete []_tab;}
00183 };
00184
00185
00186
00187
00188
00189
00190
00191 LIA_SPKTOOLS_API bool baggedFrame(double baggedFrameProbability);
00192 LIA_SPKTOOLS_API void baggedSegments(SegCluster &,SegCluster &,double,unsigned long=3,unsigned long=7);
00193 LIA_SPKTOOLS_API void baggedSegmentsConstraint(SegCluster &,SegCluster &,double,unsigned long=3,unsigned long=7);
00194
00195
00196 LIA_SPKTOOLS_API void baggedSegments(SegCluster &selectedSegments,SegCluster &baggedSeg,unsigned long nbBagged,double & baggedProbability,
00197 unsigned long minimumLength,unsigned long maximumLength);
00198
00199
00200 LIA_SPKTOOLS_API void baggedSegments(SegCluster &selectedSegments,SegCluster &baggedSelected,SegCluster &baggedUnselected,double baggedProbability,unsigned long minimumLength,unsigned long maximumLength);
00201
00202
00203 LIA_SPKTOOLS_API double meanLikelihood(StatServer &ss,FeatureServer &fs,MixtureGD &model,unsigned long idxBeginFrame,unsigned long nbFrames,Config &config);
00204
00205 LIA_SPKTOOLS_API double meanLikelihood(StatServer &ss,FeatureServer &fs,MixtureGD &model,SegCluster &selectedSegments,Config &config);
00206
00207 LIA_SPKTOOLS_API double meanLikelihood(StatServer &ss,FeatureServer **fsTab,SegCluster **segTab,unsigned long nbStream,MixtureGD &model,Config &config);
00208 LIA_SPKTOOLS_API double meanLikelihood(StatServer &ss,ObjectRefVector &FeatServ,ObjectRefVector &ClusterSeg,MixtureGD &model,DoubleVector &decision,Config &config);
00209
00210
00211
00212 LIA_SPKTOOLS_API void globalMeanCov (FeatureServer &fs,SegCluster &selectedSegments,FrameAcc & globalFrameAcc,Config &config);
00213
00214 LIA_SPKTOOLS_API void globalMeanCov (FeatureServer &fs,FrameAcc & globalFrameAcc,Config &config);
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 LIA_SPKTOOLS_API double areaHisto(const Histo & histo,unsigned long bin);
00228 LIA_SPKTOOLS_API double areaHisto(const Histo & histo,unsigned long bin, double nonObserved);
00229 LIA_SPKTOOLS_API double linearInterpolation(double val,double lower,double higher);
00230 LIA_SPKTOOLS_API void freezeHistoTab(Histo* &histoT);
00231 LIA_SPKTOOLS_API void initHistoTab(Histo* &histoT,unsigned long size, unsigned long nbBins);
00232 LIA_SPKTOOLS_API void computeHistoTab(Histo* histoT,unsigned long size);
00233 LIA_SPKTOOLS_API void accumulateHistoFrame(Histo *histoT,FeatureServer &fs,
00234 unsigned long idxBeginFrame,unsigned long nbFrames,Config &config);
00235
00236 LIA_SPKTOOLS_API void accumulateHistoFrame(Histo *histoT,FeatureServer &fs,Seg* seg,Config &config);
00237
00238 LIA_SPKTOOLS_API void accumulateHistoFrame(Histo *histoT,FeatureServer &fs,SegCluster &selectedSegments,Config &config);
00239
00240
00241
00242
00243
00244
00245 LIA_SPKTOOLS_API void computeWarp(Histo *histoT,Histo &destH,FeatureServer & fs,unsigned long begin, unsigned long length,Config &config);
00246
00247 LIA_SPKTOOLS_API void computeWarp(Histo *histoT,Histo &destH, FeatureServer & fs, Seg* seg, Config & config);
00248
00249 LIA_SPKTOOLS_API void computeWarp(Histo *histoT,Histo &destH, FeatureServer & fs, SegCluster & selectedSegments, Config & config);
00250
00251
00252
00253
00254 LIA_SPKTOOLS_API void cms(String &,FeatureServer &,Config &);
00255
00256 LIA_SPKTOOLS_API void computeZeroOne(FrameAccGD &frameAccu,FeatureServer & fs,unsigned long begin, unsigned long length,Config &config) ;
00257
00258 LIA_SPKTOOLS_API void computeZeroOne(FrameAccGD & frameAccu, FeatureServer & fs, Seg* seg, Config & config);
00259
00260 LIA_SPKTOOLS_API void computeZeroOne(FrameAccGD & frameAccu, FeatureServer & fs, SegCluster & selectedSegments, Config & config);
00261
00262 LIA_SPKTOOLS_API void computeZeroOne(const DoubleVector &mean,const DoubleVector& cov,FeatureServer & fs,unsigned long begin, unsigned long length,Config &config) ;
00263
00264 LIA_SPKTOOLS_API void computeZeroOne(const DoubleVector &mean,const DoubleVector& cov, FeatureServer & fs, Seg* seg, Config & config);
00265
00266 LIA_SPKTOOLS_API void computeZeroOne(const DoubleVector &mean,const DoubleVector& cov, FeatureServer & fs, SegCluster & selectedSegments, Config & config);
00267
00268
00269 LIA_SPKTOOLS_API void outputFeatureFile(Config &config, FeatureServer &fs, Feature & f, FeatureFileWriter &w);
00270
00271 LIA_SPKTOOLS_API void outputFeatureFile(Config &config, FeatureServer &fs, Seg * seg, FeatureFileWriter &w);
00272
00273 LIA_SPKTOOLS_API void outputFeatureFile(Config &config, FeatureServer &fs, SegCluster & selectedSegments, FeatureFileWriter &w);
00274
00275 LIA_SPKTOOLS_API void outputFeatureFile(Config &config, FeatureServer &fs, unsigned long begin,unsigned long length, FeatureFileWriter &w);
00276
00277
00278 LIA_SPKTOOLS_API unsigned long getBestGaussian(Mixture & M, Feature & f);
00279 LIA_SPKTOOLS_API void mapDataToDistrib(double & data, const double meanData, const double covData, const double meanMap, const double covMap);
00280
00281 LIA_SPKTOOLS_API void featureMapping(MixtureServer & ms, FeatureServer & fs,unsigned long begin, unsigned long length,Config &config);
00282
00283 LIA_SPKTOOLS_API void featureMapping(MixtureServer & ms, FeatureServer & fs,Seg * seg,Config &config);
00284
00285
00286 LIA_SPKTOOLS_API void featureMapping(MixtureServer & ms, FeatureServer & fs,SegCluster & selectedSegments,Config &config);
00287
00288
00289
00290 LIA_SPKTOOLS_API double likelihoodGD(const DistribGD&,const DistribGD &);
00291 LIA_SPKTOOLS_API double likelihoodGD(const MixtureGD&,const MixtureGD &);
00292 LIA_SPKTOOLS_API double likelihoodGD(const MixtureGD&,const MixtureGD &,TabWeight&);
00293 LIA_SPKTOOLS_API double likelihoodGD(const MixtureGD& ,const MixtureGD &,TabWeight &,TabWeight &);
00294
00295 #endif //!defined(ALIZE_GeneralTools_h)