Пример #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());
		}
	}
}
Пример #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);
	}
}