Beispiel #1
0
// store the HMM into a file
void HMMState::store(FileOutput &file) {
	
	// phonetic symbol
	char strPhone[MAX_PHONETIC_SYMBOL_LENGTH+1];
	memset(strPhone,0,MAX_PHONETIC_SYMBOL_LENGTH+1);
	strcpy(strPhone,m_phoneSet->getStrPhone(m_iPhone));	
	IOBase::writeBytes(file.getStream(),reinterpret_cast<char*>(strPhone),MAX_PHONETIC_SYMBOL_LENGTH+1);
	
	// state
	IOBase::write(file.getStream(),m_iState);
	
	// within word position (DEPRECATED)
	IOBase::write(file.getStream(),m_iPosition);

	// Gaussian components
	int iGaussianComponents = m_gaussianMixture->getNumberComponents();
	IOBase::write(file.getStream(),iGaussianComponents);
	for(int iGaussian = 0 ; iGaussian < iGaussianComponents ; ++iGaussian) {
		Gaussian *gaussian = (*m_gaussianMixture)(iGaussian); 
		IOBase::write(file.getStream(),gaussian->weight());
		gaussian->mean().writeData(file.getStream());
		if (m_iCovarianceModeling == COVARIANCE_MODELLING_TYPE_DIAGONAL) {
			gaussian->covarianceDiag().writeData(file.getStream());
		} else {
			gaussian->covarianceFull().writeData(file.getStream());
		}
	}
}
Beispiel #2
0
// load the HMM from a file
void HMMState::load(FileInput &file, unsigned char iEstimationMethod) {

	// phonetic symbol
	char strPhone[MAX_PHONETIC_SYMBOL_LENGTH+1];	
	IOBase::readBytes(file.getStream(),reinterpret_cast<char*>(strPhone),MAX_PHONETIC_SYMBOL_LENGTH+1);
	m_iPhone = m_phoneSet->getPhoneIndex(strPhone);
	assert(m_iPhone != UCHAR_MAX);
	
	// state
	IOBase::read(file.getStream(),&m_iState);
	assert(m_iState < NUMBER_HMM_STATES);
	
	// within word position (DEPRECATED)
	IOBase::read(file.getStream(),&m_iPosition);
	
	// Gaussian components
	int iGaussianComponents = -1;
	IOBase::read(file.getStream(),&iGaussianComponents);
	for(int iGaussian = 0 ; iGaussian < iGaussianComponents ; ++iGaussian) {
	
		Gaussian *gaussian = new Gaussian(m_iDim,m_iCovarianceModeling);	
		
		IOBase::read(file.getStream(),&gaussian->weight());
		gaussian->mean().readData(file.getStream());		
		if (m_iCovarianceModeling == COVARIANCE_MODELLING_TYPE_DIAGONAL) {
			gaussian->covarianceDiag().readData(file.getStream());
		} else {
			gaussian->covarianceFull().readData(file.getStream());
		}	
		m_gaussianMixture->addGaussianComponent(gaussian);
	}
}
Beispiel #3
0
    bool is_approx(const Gaussian<OtherVariate>& other)
    {


        return fl::are_similar(mean(), other.mean()) &&
               fl::are_similar(covariance(), other.covariance());
    }
Beispiel #4
0
// estimate the parameters of the given HMM-state
void MAPEstimator::estimateParameters(HMMState *hmmState, Accumulator **accumulators, float fPriorKnowledgeWeight) {

	// (1) update the mean of each Gaussian component
	for(unsigned int g = 0 ; g < hmmState->getMixture().getNumberComponents() ; ++g) {
	
		Gaussian *gaussian = hmmState->getMixture()(g);
		Accumulator *accumulator = accumulators[g];
		// if there occupation for this component?
		if (accumulator == NULL) {
			continue;
		}
		
		// mean (needs to be computed first in the case of full covariance)
		gaussian->mean().mul(fPriorKnowledgeWeight);
		gaussian->mean().add(accumulator->getObservation());
		gaussian->mean().mul((float)(1.0f/(fPriorKnowledgeWeight+accumulator->getOccupation())));
	}	

	assert(hmmState->getMixture().getNumberComponents() > 0);
}
Beispiel #5
0
    bool is_approx(const Gaussian<OtherVariate>& other,
                   Real eps = 1.e-9,
                   bool scale_with_size = false)
    {
        Real eps_mean = eps;
        Real eps_cov = eps;

        if (scale_with_size)
        {
            eps_mean *= mean().size();
            eps_cov *= covariance().size();
        }

        return fl::are_similar(mean(), other.mean(), eps_mean) &&
               fl::are_similar(covariance(), other.covariance(), eps_cov);
    }