Gaussian Class Reference

Using Gaussian objects, single gaussians can be trained and used. More...

Inheritance diagram for Gaussian:

List of all members.


Public Member Functions

 Gaussian (int dim=ASR_DEFAULT_VECTORSIZE)
 Gaussian (Gaussian *copyFrom, bool shiftGaussian=true)
 Gaussian (Gaussian *model1, Gaussian *model2, double rate)
 Gaussian (FILE *inFile, int dim)
 ~Gaussian ()
int getNrTrainingSamples () const
int dim () const
VectorgetMean () const
double getCP () const
VectorgetVariance () const
virtual double getP (Vector *observation)
virtual double getLogP (Vector *observation)
void setVariance (const Vector *v)
void setMean (Vector *v)
void storeData (FILE *outFile)
void storeSAT (FILE *outFile)
void appendSAT (FILE *outFile)
void train (Gaussian *trainG)
void train (double factor, Vector *observation, Gaussian *doSat=NULL)
double trainFinish (bool cleanUp=true, double minVar=GAUSSIAN_VARIANCE_MINIMUM)
void shiftMean (int shiftFactor=1)
double getTrainingDenominator (void)
double getCoSim (Gaussian *g1, Gaussian *g2)
double getKLDistance (Gaussian *g2)
double getNormDistance ()
void moveModel (Gaussian *model, double factor)
void mapAdaptMean ()
void adapt_setInitialNode (Adapt_AM_TreeNode *node)
void adapt_setNode ()
void adapt_setHelperMatrices ()
void adapt_setVarTrans ()
void adapt_adaptVar ()
void adapt_adapt ()
void adapt_unAdapt ()
void adapt_clear ()
void writeAccumulators (FILE *file, FILE *fileF=NULL, FILE *fileST=NULL, bool doBinary=false)
void trainMMI (FILE *fileEnum, FILE *fileDenom)
void addAccumulators (FILE *file)
void printModel (FILE *fileMean, FILE *fileVariance)
void printInfo (Vector *v)
void printGaussian (void)

Protected Member Functions

void calculateCP ()
void enterTrainingMode (bool mmiTraining=false)

Protected Attributes

double CP
 CP is the part of the normal distribution calculation that can be done before-hand.
VectorvarianceVector
VectormeanVector
TrainGaussiantrainPars
TrainGaussianmmi_trainPars
double helper_meanJKProd

Detailed Description

Using Gaussian objects, single gaussians can be trained and used.

In order to form a gaussian, the user must provide Gaussian objects with training samples. The object will set its mean Vector and variance Vector according to these samples. With getP() the user can request the likelihood that the gaussian would produce a particular observation.


Constructor & Destructor Documentation

Gaussian::Gaussian ( int  dimensions = ASR_DEFAULT_VECTORSIZE  ) 

The constructor initialises the gaussian. The variance is set to 100 (very big), and the mean is set to all zero.

References calculateCP(), meanVector, mmi_trainPars, Vector::setAllValues(), trainPars, and varianceVector.

Referenced by FeatureExtraction::setNormalization().

Here is the call graph for this function:

Gaussian::Gaussian ( Gaussian copyFrom,
bool  shiftGaussian = true 
)

This constructor creates an identical copy from another Gaussian.

References Vector::addElements(), calculateCP(), Vector::copyVector(), Vector::getMaxElement(), meanVector, mmi_trainPars, Vector::multiplyElements(), Vector::sqrtElements(), trainPars, and varianceVector.

Here is the call graph for this function:

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

This constructor creates a Gaussian with mean inbetween the mean of model1 and model2.

References Vector::addElements(), calculateCP(), Vector::copyVector(), meanVector, mmi_trainPars, Vector::multiplyElements(), trainPars, and varianceVector.

Here is the call graph for this function:

Gaussian::Gaussian ( FILE *  inFile,
int  dim 
)

Reads the Gaussian parameters (mean and variance Vectors) from file.

References calculateCP(), meanVector, mmi_trainPars, trainPars, and varianceVector.

Here is the call graph for this function:

Gaussian::~Gaussian (  ) 


Member Function Documentation

void Gaussian::adapt_adapt (  ) 

The Gaussian object will adapt its mean Vector with use of the adaptation matrix that is calculated by the Adapt_AM_TreeNode adaptation node that the Gaussian is registered to. The old mean Vector is kept in memory and can be restored by calling adapt_unAdapt().

References TrainGaussian::adaptNode, Vector::copyVector(), enterTrainingMode(), Vector::getValue(), Vector::len(), meanVector, Vector::setValue(), trainPars, TrainGaussian::unAdaptedMeanVector, varianceVector, and Adapt_AM_TreeNode::W.

Referenced by MixGaussian::adapt_adapt().

Here is the call graph for this function:

void Gaussian::adapt_adaptVar (  ) 

void Gaussian::adapt_clear (  ) 

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

References enterTrainingMode(), TrainGaussian::numeratorMean, TrainGaussian::numeratorVariance, Vector::setAllValues(), TrainGaussian::trainingDenominator, and trainPars.

Referenced by MixGaussian::adapt_clear().

Here is the call graph for this function:

void Gaussian::adapt_setHelperMatrices (  ) 

void Gaussian::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 set the Gaussian in training mode (enterTrainingMode()) and add its mean vector to the training pool of the adaptation cluster (Adapt_AM_TreeNode).

References TrainGaussian::adaptNode, Adapt_AM_TreeNode::denominator, enterTrainingMode(), Adapt_AM_TreeNode::meanGaussian, meanVector, train(), TrainGaussian::trainingDenominator, and trainPars.

Referenced by MixGaussian::adapt_setInitialNode().

Here is the call graph for this function:

void Gaussian::adapt_setNode (  ) 

The Gaussian 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 calculate which one of the two Adapt_AM_TreeNode children has a mean vector closest to the mean vector of the Gaussian itself. It will register to the closest child adaptation node and add its mean vector to the adaptation training pool.

References TrainGaussian::adaptNode, Adapt_AM_TreeNode::childLeft, Adapt_AM_TreeNode::childRight, Adapt_AM_TreeNode::denominator, enterTrainingMode(), getP(), Adapt_AM_TreeNode::meanGaussian, meanVector, train(), TrainGaussian::trainingDenominator, and trainPars.

Referenced by MixGaussian::adapt_setNode().

Here is the call graph for this function:

void Gaussian::adapt_unAdapt (  ) 

The Gaussian object will adapt its mean Vector with use of the adaptation matrix that is calculated by the Adapt_AM_TreeNode adaptation node that the Gaussian is registered to when the method adapt_adapt() is called. The method adapt_unAdapt() will restore the old mean Vector that is kept in memory.

References enterTrainingMode(), meanVector, trainPars, and TrainGaussian::unAdaptedMeanVector.

Referenced by MixGaussian::adapt_unAdapt().

Here is the call graph for this function:

void Gaussian::addAccumulators ( FILE *  inFile  ) 

void Gaussian::appendSAT ( FILE *  inFile  ) 

void Gaussian::calculateCP ( void   )  [protected]

Calculates the CP and logCP. The CP is 1 devided by the square root from the determinant of the variance vector:

References CP, Vector::getValue(), Vector::len(), FastMath::log(), and varianceVector.

Referenced by Gaussian(), mapAdaptMean(), setMean(), setVariance(), shiftMean(), trainFinish(), and trainMMI().

Here is the call graph for this function:

int Gaussian::dim (  )  const [inline]

References Vector::len(), and varianceVector.

Referenced by enterTrainingMode(), MixGaussian::MixGaussian(), and FeatureExtraction::setNormalization().

Here is the call graph for this function:

void Gaussian::enterTrainingMode ( bool  mmiTraining = false  )  [protected]

In order to safe memory, Gaussian training parameters are grouped in a TrainGaussian structure. Each Gaussian object contains a NULL pointer (trainPars) of type TrainGaussian. When a training method is called and the trainPars variable is NULL, the method enterTrainingMode() is automatically called. This method will create the TrainGaussian structure and initialise its variables.

References TrainGaussian::adaptNode, dim(), TrainGaussian::lastTrainingWeight, Vector::len(), meanVector, mmi_trainPars, TrainGaussian::numeratorMean, TrainGaussian::numeratorVariance, Vector::setAllValues(), TrainGaussian::trainingDenominator, TrainGaussian::trainingSamples, trainPars, and TrainGaussian::unAdaptedMeanVector.

Referenced by adapt_adapt(), adapt_clear(), adapt_setHelperMatrices(), adapt_setInitialNode(), adapt_setNode(), adapt_unAdapt(), addAccumulators(), appendSAT(), getTrainingDenominator(), storeSAT(), train(), trainFinish(), trainMMI(), and writeAccumulators().

Here is the call graph for this function:

double Gaussian::getCoSim ( Gaussian g1,
Gaussian g2 
)

double Gaussian::getCP (  )  const [inline]

References CP.

Referenced by MixGaussian::initializeFastCalc().

double Gaussian::getKLDistance ( Gaussian g2  ) 

References Vector::getValue(), Vector::len(), meanVector, and varianceVector.

Referenced by MixGaussian::getKLDistance().

Here is the call graph for this function:

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

Returns the chance that an observation is produced by this Gaussian (in log)

References Vector::calculateEPart(), CP, meanVector, and varianceVector.

Referenced by TrainPhoneModel::train().

Here is the call graph for this function:

double Gaussian::getNormDistance (  ) 

References Vector::getValue(), Vector::len(), meanVector, and varianceVector.

Referenced by MixGaussian::getNormDistance().

Here is the call graph for this function:

int Gaussian::getNrTrainingSamples (  )  const [inline]

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

Returns the chance that an observation is produced by this Gaussian.

References Vector::calculateEPart(), CP, meanVector, and varianceVector.

Referenced by adapt_setNode(), MixGaussian::count(), and MixGaussian::getSumHist().

Here is the call graph for this function:

double Gaussian::getTrainingDenominator ( void   ) 

Returns the training denominator. This is basically the number of training observations used during the training phase.

References enterTrainingMode(), TrainGaussian::lastTrainingWeight, and trainPars.

Referenced by MixGaussian::trainFinish().

Here is the call graph for this function:

void Gaussian::moveModel ( Gaussian model,
double  factor 
)

Todo:
docs

References Vector::addElements(), meanVector, and Vector::multiplyElements().

Referenced by MixGaussian::moveModelGaussians().

Here is the call graph for this function:

void Gaussian::printGaussian ( void   ) 

Prints the gaussian to the standard output for debugging purposes.

References meanVector, Vector::printVector(), and varianceVector.

Referenced by MixGaussian::printMixGaussian().

Here is the call graph for this function:

void Gaussian::printInfo ( Vector v  ) 

References Vector::addElements(), and meanVector.

Referenced by MixGaussian::printInfo().

Here is the call graph for this function:

void Gaussian::printModel ( FILE *  fileMean,
FILE *  fileVariance 
)

References Vector::getValue(), Vector::len(), meanVector, and varianceVector.

Referenced by MixGaussian::printModel().

Here is the call graph for this function:

void Gaussian::setMean ( Vector v  ) 

Sets the mean of the Gaussian

References calculateCP(), meanVector, and Vector::setAllValues().

Referenced by MixGaussian::addGaussian(), and MixGaussian::getSumHist().

Here is the call graph for this function:

void Gaussian::setVariance ( const Vector v  ) 

Sets the variance of the Gaussian

References calculateCP(), Vector::setAllValues(), and varianceVector.

Referenced by MixGaussian::getSumHist().

Here is the call graph for this function:

void Gaussian::shiftMean ( int  shiftFactor = 1  ) 

Shifts the mean Vector by -0.2*shiftFactor of the variance Vector. shiftFactor may be negative

References Vector::addElements(), calculateCP(), Vector::getMaxElement(), meanVector, Vector::multiplyElements(), Vector::sqrtElements(), and varianceVector.

Referenced by MixGaussian::shiftBestGaussian(), Adapt_AM_TreeNode::split(), MixGaussian::splitAllGaussians(), and MixGaussian::splitBestGaussian().

Here is the call graph for this function:

void Gaussian::storeData ( FILE *  outFile  ) 

Writes the Gaussian parameters (mean and variance Vectors) to file.

References meanVector, Vector::storeData(), and varianceVector.

Referenced by MixGaussian::storeData().

Here is the call graph for this function:

void Gaussian::storeSAT ( FILE *  outFile  ) 

Writes training data to file.

References enterTrainingMode(), TrainGaussian::numeratorMean, TrainGaussian::numeratorVariance, Vector::storeData(), TrainGaussian::trainingDenominator, and trainPars.

Referenced by MixGaussian::storeSAT().

Here is the call graph for this function:

void Gaussian::train ( double  factor,
Vector observation,
Gaussian doSat = NULL 
)

Train the Gaussian as follows:

The training factor (input parameter) is added to the denominator. When factor is one, this means that an entire observation is added to the training pool. If 0.0 < factor < 1.0, the observation is seen as being partly mapped on this gaussian.

Literature: Frederick Jelinek, "Statistical Methods for Speech Recognition": page 30 for parameter (mean and variance) estimation.

References Vector::addElements(), Vector::copyVector(), enterTrainingMode(), TrainGaussian::lastTrainingWeight, meanVector, Vector::multiplyElements(), TrainGaussian::numeratorMean, TrainGaussian::numeratorVariance, Vector::substractElements(), TrainGaussian::trainingDenominator, TrainGaussian::trainingSamples, and trainPars.

Here is the call graph for this function:

void Gaussian::writeAccumulators ( FILE *  outFile,
FILE *  outFileF = NULL,
FILE *  outFileST = NULL,
bool  doBinary = false 
)


Member Data Documentation

double Gaussian::CP [protected]

CP is the part of the normal distribution calculation that can be done before-hand.

Referenced by calculateCP(), getCP(), getLogP(), and getP().

double Gaussian::helper_meanJKProd [protected]