MixGaussian Class Reference

The MixGaussian class handles mixture sets of gaussians. More...

Inheritance diagram for MixGaussian:

List of all members.


Public Member Functions

 MixGaussian (int dim=ASR_DEFAULT_VECTORSIZE)
 MixGaussian (FILE *inFile, int dim, bool noReTrainig=false)
 MixGaussian (MixGaussian *org)
 MixGaussian (MixGaussian *model1, MixGaussian *model2)
 MixGaussian (MixGaussian *model1, MixGaussian *model2, double rate)
virtual ~MixGaussian ()
int dim () const
virtual void mergeMixGaussians (MixGaussian *model1, MixGaussian *model2)
virtual int getNumberOfGaussians (void)
void setVariance (const Vector *v)
virtual double getP (Vector *observation)
virtual double getLogP (Vector *observation)
virtual double getLookaheadLogP (double *vectorList, int time, bool doSecondHalf)
void getSumHist (Vector **histogram)
virtual void train (MixGaussian *trainMG)
virtual void train (bool useKMeans, double weight, Vector *observation, MixGaussian *doSat=NULL)
void mapAdaptMeans ()
void adapt_setInitialNode (Adapt_AM_TreeNode *node)
void adapt_setHelperMatrices ()
void adapt_adapt ()
void adapt_unAdapt ()
void initializeFastCalc (bool onlyOnce)
virtual int trainFinish (bool neverSplit=false, double minVar=GAUSSIAN_VARIANCE_MINIMUM)
virtual double finishSAT (double minVar=GAUSSIAN_VARIANCE_MINIMUM)
virtual bool splitAllGaussians (bool alwaysSplit=false)
virtual bool splitBestGaussian (bool alwaysSplit=false)
virtual void shiftBestGaussian (int shiftFactor)
virtual void copyGaussians (MixGaussian *destMixGaussian, int maxNmbr)
virtual void addGaussian (Gaussian *gaussian, double weight)
virtual void addGaussian (Vector *vector)
virtual void normalizeWeights (int maxGaussians=-1)
virtual void storeData (FILE *outFile)
void storeSAT (FILE *outFile)
void appendSAT (FILE *outFile)
void adapt_setNode ()
void adapt_clear ()
void writeAccumulators (FILE *file, FILE *fileF=NULL, FILE *fileST=NULL, bool doBinary=false)
void addAccumulators (FILE *file)
void trainMMI (FILE *fileEnum, FILE *fileDenom)
void adapt_setVarTrans ()
void adapt_adaptVar ()
double getCoSim (MixGaussian *mg1, MixGaussian *mg2)
double getKLDistance (MixGaussian *mg2)
double getNormDistance ()
void moveModelGaussians (MixGaussian *model, double factor)
void startCount ()
void count (Vector *observation)
void stopCount ()
int getBestCount ()
void addCountedGaussians (MixGaussian *source, int nmbr)
void fillDistanceArray (int *distA)
void printModel (FILE *fileMean, FILE *fileVariance, FILE *fileWeight)
int printInfo (Vector *v)
void printMixGaussian (void)

Public Attributes

double * fastP_CPandWeight_meanAndVar

Protected Attributes

Gaussian ** myGaussians
double * myGaussianWeights
double trainP
int numberOfGaussians
bool noSplitting
double * myGaussiansCounts
int * myGaussiansSorted
double * fastP_res
void * lastObservation
int vectorDimension
double lookaheadRes [GMMLOOKAHEAD]
int lookaheadPointer

Detailed Description

The MixGaussian class handles mixture sets of gaussians.

Gaussian objects offer functionality for training single gaussian parameter values and determining chances given specific observations. The MixGaussian class makes it possible to train and use mixtures of gaussians. The user may increase the number of gaussians in the mixture using splitBestGaussian(). This method splits the Gaussian that has been trained with the most observation samples.


Constructor & Destructor Documentation

MixGaussian::MixGaussian ( int  dim = ASR_DEFAULT_VECTORSIZE  ) 

The constructor initialises the object. It creates a single gaussian (mixture of one) and makes a weight table of size one with weight one.

References fastP_CPandWeight_meanAndVar, fastP_res, initializeFastCalc(), myGaussians, myGaussiansCounts, myGaussiansSorted, myGaussianWeights, noSplitting, numberOfGaussians, and vectorDimension.

Referenced by MultiMixGaussian::MultiMixGaussian().

Here is the call graph for this function:

MixGaussian::MixGaussian ( FILE *  inFile,
int  dim,
bool  noReTraining = false 
)

This constructor reads all its data from file. (number of gaussians, the weight table and the gaussian parameters)

References fastP_CPandWeight_meanAndVar, fastP_res, WriteFileLittleBigEndian::freadEndianSafe(), initializeFastCalc(), myGaussians, myGaussiansCounts, myGaussiansSorted, myGaussianWeights, noSplitting, numberOfGaussians, and vectorDimension.

Here is the call graph for this function:

MixGaussian::MixGaussian ( MixGaussian org  ) 

MixGaussian::MixGaussian ( MixGaussian model1,
MixGaussian model2 
)

This constructor will merge the two input gaussians.

References Gaussian::dim(), fastP_CPandWeight_meanAndVar, fastP_res, initializeFastCalc(), mergeMixGaussians(), myGaussians, myGaussiansCounts, myGaussiansSorted, myGaussianWeights, noSplitting, and vectorDimension.

Here is the call graph for this function:

MixGaussian::MixGaussian ( MixGaussian model1,
MixGaussian model2,
double  rate 
)

This constructor will merge the two input gaussians.

References Gaussian::dim(), dim(), fastP_CPandWeight_meanAndVar, fastP_res, initializeFastCalc(), myGaussians, myGaussiansCounts, myGaussiansSorted, myGaussianWeights, noSplitting, numberOfGaussians, and vectorDimension.

Here is the call graph for this function:

MixGaussian::~MixGaussian (  )  [virtual]

The destructor deletes all gaussians from the mix and also deletes the weights table.

References fastP_CPandWeight_meanAndVar, fastP_res, myGaussians, myGaussiansCounts, myGaussiansSorted, myGaussianWeights, and numberOfGaussians.


Member Function Documentation

void MixGaussian::adapt_adapt (  ) 

Once all adaptation matrices are calculated, this method will adapt all Gaussians in the mix according to those matrices.

References Gaussian::adapt_adapt(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_adapt().

Here is the call graph for this function:

void MixGaussian::adapt_adaptVar (  ) 

Todo:
Docs

References Gaussian::adapt_adaptVar(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_adaptVar().

Here is the call graph for this function:

void MixGaussian::adapt_clear (  ) 

This method will clear all adaptation settings, so that a new adaptation iteration can be started.

References Gaussian::adapt_clear(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_clear().

Here is the call graph for this function:

void MixGaussian::adapt_setHelperMatrices (  ) 

This method will call the Gaussian::adapt_setHelperMatrices() method of all Gaussian objects in the mix (of this MixGaussian object).

References Gaussian::adapt_setHelperMatrices(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_setHelperMatrices().

Here is the call graph for this function:

void MixGaussian::adapt_setInitialNode ( Adapt_AM_TreeNode node  ) 

The SMAPLR adaptation starts with creating one single cluster (node) at which all gaussians in the system will need to register. The method adapt_setInitialNode() will call the Gaussian::adapt_setInitialNode() of all Gaussian objects that are in the mix (of this MixGaussian object)

References Gaussian::adapt_setInitialNode(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_setInitialNode().

Here is the call graph for this function:

void MixGaussian::adapt_setNode (  ) 

The MixGaussian has registered at least once to an adaptation node when this method is called. The first time adapt_setInitialNode() shall be used. This method will call the Gaussian::adapt_setNode() method of all Gaussian objects in the mix (of this MixGaussian object).

References Gaussian::adapt_setNode(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_setNode().

Here is the call graph for this function:

void MixGaussian::adapt_setVarTrans (  ) 

Todo:
Docs

References Gaussian::adapt_setVarTrans(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_setVarTrans().

Here is the call graph for this function:

void MixGaussian::adapt_unAdapt (  ) 

The mean Vectors of the Gaussian objects in the mix can be restored to the values before adaptation by calling adapt_unAdapt().

References Gaussian::adapt_unAdapt(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::adapt_unAdapt().

Here is the call graph for this function:

void MixGaussian::addAccumulators ( FILE *  file  ) 

This method will read accumulator data from file

References Gaussian::addAccumulators(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::addAccumulators().

Here is the call graph for this function:

void MixGaussian::addCountedGaussians ( MixGaussian source,
int  nmbr 
)

This method is added for the Train_Speaker_Clustering class. The amount of data assigned to each Gaussian of the mix is counted by count(). Using this method, the nmbr best gaussians from source are added to the mix.

References addGaussian(), getNumberOfGaussians(), myGaussians, myGaussiansSorted, and myGaussianWeights.

Referenced by TrainPhoneModel::addCountedGaussians().

Here is the call graph for this function:

void MixGaussian::addGaussian ( Vector v  )  [virtual]

Todo:
docs

Reimplemented in MultiMixGaussian.

References myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::setMean().

Here is the call graph for this function:

void MixGaussian::addGaussian ( Gaussian gaussian,
double  weight 
) [virtual]

This is a helper method for copyGaussians(). It adds a gaussian directly to the mix. The gaussian itself and the weight are provided as input parameters.

References myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by addCountedGaussians(), TrainPhoneModel::addGaussian(), MultiMixGaussian::addGaussian(), and copyGaussians().

void MixGaussian::appendSAT ( FILE *  outFile  ) 

This method loads training data from file.

References Gaussian::appendSAT(), myGaussians, and numberOfGaussians.

Referenced by TrainPhoneModel::appendSAT().

Here is the call graph for this function:

void MixGaussian::copyGaussians ( MixGaussian destMixGaussian,
int  maxNmbr 
) [virtual]

This method copies the maxNmbr gaussians with the biggest weights into the destination gaussian mix. This method is used by the SpeechDetection class to make speech/non-speech models.

Reimplemented in MultiMixGaussian.

References addGaussian(), myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by PhoneModel::copyGaussians(), and MultiMixGaussian::copyGaussians().

Here is the call graph for this function:

void MixGaussian::count ( Vector observation  ) 

Given the input parameter observation, this method counts the weights of the single Gaussian objects. These counts are later used by the Train_Speaker_Cluster class.

References Gaussian::getP(), myGaussians, myGaussiansCounts, myGaussianWeights, and numberOfGaussians.

Referenced by TrainPhoneModel::count().

Here is the call graph for this function:

void MixGaussian::fillDistanceArray ( int *  distA  ) 

Fills the distance array: an array of size numberOfGaussians. The two most distant gaussians are in the first and last spot. The others are sorted in between.

References Vector::distance(), Gaussian::meanVector, myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by TrainPhoneModel::fillDistanceArray().

Here is the call graph for this function:

double MixGaussian::finishSAT ( double  minVar = GAUSSIAN_VARIANCE_MINIMUM  )  [virtual]

Todo:
Docs

References myGaussians, numberOfGaussians, and Gaussian::trainFinish().

Here is the call graph for this function:

int MixGaussian::getBestCount (  ) 

This method is added for the Train_Speaker_Clustering class. The amount of data assigned to each Gaussian of the mix is counted by count(). When done, this method will return the best Gaussian...

References myGaussiansCounts, and numberOfGaussians.

Referenced by TrainPhoneModel::getDominantGaussian().

double MixGaussian::getCoSim ( MixGaussian mg1,
MixGaussian mg2 
)

References Gaussian::getCoSim(), myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by TrainPhoneModel::getCoSim().

Here is the call graph for this function:

double MixGaussian::getKLDistance ( MixGaussian mg2  ) 

References Gaussian::getKLDistance(), myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by TrainPhoneModel::getKLDistance().

Here is the call graph for this function:

double MixGaussian::getLogP ( Vector observation  )  [virtual]

GetLogP() returns the chance of an observation beeing produced by this mixture of gaussians (in log)

Reimplemented in MultiMixGaussian.

References dim(), fastP_CPandWeight_meanAndVar, fastP_res, Vector::getVectorArray(), lastObservation, FastMath::log(), and numberOfGaussians.

Referenced by MultiMixGaussian::getLogP(), PhoneModel::getLogPDFProbability(), TrainPhoneModel::getSilP(), PhoneModel::processVector(), and TrainPhoneModel::viterbi().

Here is the call graph for this function:

double MixGaussian::getLookaheadLogP ( double *  vectorList,
int  timeStamp,
bool  doSecondHalf 
) [virtual]

GetLogP() returns the chance of an observation beeing produced by this mixture of gaussians (in log)

Reimplemented in MultiMixGaussian.

References dim(), fastP_CPandWeight_meanAndVar, fastP_res, FastMath::log(), lookaheadPointer, lookaheadRes, and numberOfGaussians.

Referenced by PhoneModel::getLookaheadLogP(), MultiMixGaussian::getLookaheadLogP(), and thread_pdfCalculation().

Here is the call graph for this function:

double MixGaussian::getNormDistance (  ) 

References Gaussian::getNormDistance(), myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by TrainPhoneModel::getNormDistance().

Here is the call graph for this function:

int MixGaussian::getNumberOfGaussians ( void   )  [virtual]

double MixGaussian::getP ( Vector observation  )  [virtual]

GetP() returns the chance of an observation beeing produced by this mixture of gaussians.

Reimplemented in MultiMixGaussian.

References dim(), fastP_CPandWeight_meanAndVar, fastP_res, Vector::getKey(), Vector::getVectorArray(), lastObservation, and numberOfGaussians.

Referenced by TrainPhoneModel::baumWelch(), TrainPhoneModel::getClusterP(), PhoneModel::getPDFProbability(), and train().

Here is the call graph for this function:

void MixGaussian::mapAdaptMeans (  ) 

Todo:
docs

References Gaussian::mapAdaptMean(), myGaussians, and numberOfGaussians.

Referenced by PhoneModel::mapAdaptMeans().

Here is the call graph for this function:

void MixGaussian::mergeMixGaussians ( MixGaussian model1,
MixGaussian model2 
) [virtual]

Merge the two input gaussians.

Reimplemented in MultiMixGaussian.

References dim(), myGaussians, myGaussianWeights, noSplitting, and numberOfGaussians.

Referenced by MultiMixGaussian::mergeMixGaussians(), and MixGaussian().

Here is the call graph for this function:

void MixGaussian::moveModelGaussians ( MixGaussian model,
double  factor 
)

References Gaussian::moveModel(), myGaussians, and numberOfGaussians.

Referenced by TrainPhoneModel::moveModelGaussians().

Here is the call graph for this function:

void MixGaussian::normalizeWeights ( int  maxGaussians = -1  )  [virtual]

With this method, the sum of the weights from the gaussian mix is forced to be one and if the mix contains more than maxGaussians, the gaussians with the smallest weight are pruned.

Reimplemented in MultiMixGaussian.

References myGaussians, myGaussianWeights, and numberOfGaussians.

Referenced by MultiMixGaussian::normalizeWeights(), TrainPhoneModel::setMaxGaussians(), and TrainPhoneModel::TrainPhoneModel().

int MixGaussian::printInfo ( Vector v  ) 

References myGaussians, numberOfGaussians, and Gaussian::printInfo().

Referenced by PhoneModel::printInfo().

Here is the call graph for this function:

void MixGaussian::printMixGaussian ( void   ) 

Prints the mixture of gaussians to the standard output for debugging purposes.

References myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::printGaussian().

Here is the call graph for this function:

void MixGaussian::printModel ( FILE *  fileMean,
FILE *  fileVariance,
FILE *  fileWeight 
)

References myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::printModel().

Referenced by PhoneModel::printModel().

Here is the call graph for this function:

void MixGaussian::setVariance ( const Vector v  ) 

Set the variance for all of the gaussians in this mixture

References dim(), Vector::len(), myGaussians, and numberOfGaussians.

Here is the call graph for this function:

void MixGaussian::shiftBestGaussian ( int  shiftFactor  )  [virtual]

This method searches the "best" gaussian, and shifts its mean vector.

The best gaussian is the gaussian with the largest weight. The weight is chosen, because indirectly, the weight represents the amount of training samples defining the gaussian. The mean of the new gaussian is 0.2*shiftFactor times shifted (shiftFactor may be negative).

Reimplemented in MultiMixGaussian.

References myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::shiftMean().

Referenced by MultiMixGaussian::shiftBestGaussian(), and TrainPhoneModel::TrainPhoneModel().

Here is the call graph for this function:

bool MixGaussian::splitAllGaussians ( bool  alwaysSplit = false  )  [virtual]

Todo:
docs

References initializeFastCalc(), myGaussians, myGaussianWeights, noSplitting, numberOfGaussians, and Gaussian::shiftMean().

Referenced by TrainPhoneModel::train().

Here is the call graph for this function:

bool MixGaussian::splitBestGaussian ( bool  alwaysSplit = false  )  [virtual]

This method searches the "best" gaussian, and splits it into two new gaussians as follows:

The best gaussian is the gaussian with the largest weight. The weight is chosen, because indirectly, the weight represents the amount of training samples defining the gaussian. The mean of the new gaussian is 0.2 times the variance bigger than the old mean. The mean of the existing gaussian is made 0.2 times the variance smaller. The variance is not changed. Note that the mean is shifted in all dimensions. One could argue if this is a good initialisation step. The weights of the two new gaussians is set half the weight of the original gaussian. Also, it could be argued if this is good practice.

Reimplemented in MultiMixGaussian.

References initializeFastCalc(), myGaussians, myGaussianWeights, noSplitting, numberOfGaussians, and Gaussian::shiftMean().

Referenced by MultiMixGaussian::splitBestGaussian(), and TrainPhoneModel::train().

Here is the call graph for this function:

void MixGaussian::startCount (  ) 

This method is added for the Train_Speaker_Clustering class. The amount of data assigned to each Gaussian of the mix is counted by count(). Before counting is started, startCount should be called. This method will delete earlier allocated count-data and initialises the counting parameters.

References myGaussiansCounts, myGaussiansSorted, and numberOfGaussians.

Referenced by TrainPhoneModel::startCount().

void MixGaussian::stopCount (  ) 

This method is added for the Train_Speaker_Clustering class. The amount of data assigned to each Gaussian of the mix is counted by count(). When done, stopCount() will sort the counted gaussians so that the best X can be chosen.

References myGaussiansCounts, and numberOfGaussians.

Referenced by TrainPhoneModel::stopCount().

void MixGaussian::storeData ( FILE *  outFile  )  [virtual]

This method writes all its data to file. (number of gaussians, the weight table and the gaussian parameters)

Reimplemented in MultiMixGaussian.

References myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::storeData().

Referenced by MultiMixGaussian::storeData(), and PhoneModel::writeModel().

Here is the call graph for this function:

void MixGaussian::storeSAT ( FILE *  outFile  ) 

This method writes training data to file.

References myGaussians, numberOfGaussians, and Gaussian::storeSAT().

Referenced by TrainPhoneModel::writeSAT().

Here is the call graph for this function:

void MixGaussian::train ( bool  useKMeans,
double  weight,
Vector observation,
MixGaussian doSat = NULL 
) [virtual]

Given a single sample-observation (only one Vector), the mixed gaussian is trained. If K-means is used, the observation is used to train only the best fitting Gaussian. K-means is (currently) only used during initialisation of a TrainPhoneModel. If K-means is not used, all gaussians in the mix are updated with the observation, using the probability that the observation would map on the perticular gaussian. See Gaussian::train() for more information on training single gaussians. The weight is passed to each of the gaussians (used by Baum-Welch).

After feeding all observations to this method, trainFinish() shall be called to finalize the training procedure.

Reimplemented in MultiMixGaussian.

References fastP_res, Vector::getKey(), getP(), lastObservation, myGaussians, numberOfGaussians, and Gaussian::train().

Here is the call graph for this function:

void MixGaussian::train ( MixGaussian trainMG  )  [virtual]

Add all acumulator data to the data of this MixGaussian. The number of gaussians of both models should be the same!

Reimplemented in MultiMixGaussian.

References myGaussians, numberOfGaussians, and Gaussian::train().

Referenced by PhoneModel::adapt_addAcumulatorData(), PhoneModel::adapt_setAcumulators(), TrainPhoneModel::baumWelch(), TrainPhoneModel::train(), MultiMixGaussian::train(), and TrainPhoneModel::viterbi().

Here is the call graph for this function:

int MixGaussian::trainFinish ( bool  neverSplit = false,
double  minVar = GAUSSIAN_VARIANCE_MINIMUM 
) [virtual]

This method checks if all gaussians from the mix are updated by enough (MIN_TRAIN_SAMPLES_PER_GAUSSIAN) training observations. If not, the gaussian is pruned. After this, the mixture weights are updated according to the number of observations used for each gaussian, and the single gaussian training procedures are finalized by calling Gaussian::trainFinish(). This method will return the amount of used training data.

Reimplemented in MultiMixGaussian.

References Gaussian::getTrainingDenominator(), initializeFastCalc(), myGaussians, myGaussianWeights, numberOfGaussians, and Gaussian::trainFinish().

Referenced by TrainPhoneModel::baumWelch(), TrainPhoneModel::finishSAT(), TrainPhoneModel::train(), MultiMixGaussian::trainFinish(), and TrainPhoneModel::viterbi().

Here is the call graph for this function:

void MixGaussian::trainMMI ( FILE *  fileEnum,
FILE *  fileDenom 
)

This method will read accumulator data from file and perform MMI training

References initializeFastCalc(), myGaussians, numberOfGaussians, and Gaussian::trainMMI().

Referenced by TrainPhoneModel::trainMMI().

Here is the call graph for this function:

void MixGaussian::writeAccumulators ( FILE *  file,
FILE *  fileF = NULL,
FILE *  fileST = NULL,
bool  doBinary = false 
)

This method will write accumulator data to file

References myGaussians, numberOfGaussians, and Gaussian::writeAccumulators().

Referenced by PhoneModel::writeAccumulators().

Here is the call graph for this function:


Member Data Documentation

double MixGaussian::lookaheadRes[GMMLOOKAHEAD] [protected]

Referenced by getLookaheadLogP().

double MixGaussian::trainP [protected]

Referenced by dim(), and MixGaussian().