Пример #1
0
void FactorAnalysisStat::getXEstimate(){
	if (verbose) cout << "(FactorAnalysisStat) Compute X Estimate "<<endl;
	RealVector <double> AUX;
	AUX.setSize(_rang);
	XLine *pline;
	String *pFile;

	_matX.setAllValues(0.0);

	double *X=_matX.getArray();	
	double *U=_matU.getArray();
	double *S_X_h=_matS_X_h.getArray();
	double *aux=AUX.getArray();
	double *super_invvar=_super_invvar.getArray();
	
	fileList.rewind();
	while((pline=fileList.getLine())!=NULL) {
		while((pFile=pline->getElement())!=NULL) {
		    unsigned long sent=_ndxTable.sessionNb(*pFile);
			AUX.setAllValues(0.0);
			for(unsigned long i=0;i<_rang;i++)
				for(unsigned long k=0;k<_supervsize;k++) 
					aux[i]+= U[k*_rang+i]*super_invvar[k]*S_X_h[sent*_supervsize+k];	
			double *l_h_inv=_l_h_inv[sent].getArray();	
			for(unsigned long i=0;i<_rang;i++)
				for(unsigned long k=0;k<_rang;k++) 
					X[sent*_rang+i]+=l_h_inv[i*_rang+k]*aux[k];
			sent++;
		}
	}
};
Пример #2
0
void FactorAnalysisStat::substractChannelStats(){
	if (verbose) cout <<"(FactorAnalysisStat) Compute and Substract Channel FA Stats... "<<endl;	
	RealVector <double> UX;UX.setSize(_supervsize); UX.setAllValues(0.0);double* ux=UX.getArray();		
		
	// Compute Occupations and Statistics
	unsigned long loc=0;
	unsigned long sent=0; 
	XLine *pline; String *pFile; 
	fileList.rewind();
	
	double *super_mean=_super_mean.getArray();
	double *N_h=_matN_h.getArray(); 
	double *S_X=_matS_X.getArray();

	while((pline=fileList.getLine())!=NULL) { 		
		while((pFile=pline->getElement())!=NULL) {
			this->getUX(UX,*pFile);
			for(unsigned long k=0;k<_supervsize;k++) 
				ux[k]+=super_mean[k];
			
			for(unsigned long k=0;k<_mixsize;k++)
				for (unsigned long i=0;i<_vsize;i++)
					S_X[loc*_supervsize+(k*_vsize+i)]-= N_h[sent*_mixsize+k]*ux[i+k*_vsize];
			sent++;
		}
		loc++;
	}
};
Пример #3
0
void *Uthread(void *threadarg) {
	struct Uthread_data *my_data;
	my_data = (struct Uthread_data *) threadarg;
	// Get data
	double *U = my_data->U;
	double *N_h=my_data->N_h;	
	double *S_X_h=my_data->S_X_h;	
	double *X=my_data->X;
	unsigned long _rang=my_data->rang;
	unsigned long _supervsize=my_data->sv;	
	unsigned long _nb_sent=my_data->nbsent;
	unsigned long _vsize=my_data->vsize;
	unsigned long _mixsize=my_data->mixsize;
	unsigned long idxBottom=my_data->idxBottom;
	unsigned long idxUp=my_data->idxUp;
	RefVector <DoubleSquareMatrix>& _l_h_inv=*(my_data->L);

	// Routine
	DoubleSquareMatrix L(_rang);
	DoubleSquareMatrix L_Inv(_rang);
	RealVector <double> R;
	R.setSize(_rang);
	double *RV=R.getArray();
	double *LV=L.getArray();	
	for (unsigned long g=idxBottom;g<idxUp;g++) {
		L.setAllValues(0.0);
		// Estimate LU for the gaussian g
		for(unsigned long j=0;j<_nb_sent;j++){
			double *l_h_inv=_l_h_inv[j].getArray();
			for(unsigned long k=0;k<_rang;k++)
				for(unsigned long l=0;l<_rang;l++) 
					LV[k*_rang+l]+=(l_h_inv[k*_rang+l]+X[j*_rang+k]*X[j*_rang+l])*N_h[j*_mixsize+g];
		}
		L.invert(L_Inv); 
		double *L_InvV=L_Inv.getArray();	
		
		// Estimate LU for the line lineNum
		for (unsigned long i=0;i<_vsize;i++) {
			unsigned long lineNum=_vsize*g+i;			
			// estime RU i
			R.setAllValues(0.0);
			for(unsigned long j=0;j<_nb_sent;j++)
				for(unsigned long k=0;k<_rang;k++)
					RV[k]+=S_X_h[j*_supervsize+lineNum]*X[j*_rang+k];
			// estime U i
			for(unsigned long j=0;j<_rang;j++)
				for(unsigned long k=0;k<_rang;k++) 
					U[lineNum*_rang+j]+=L_InvV[j*_rang+k]*RV[k];
		}
	}
	//
	pthread_exit((void*) 0);
	return(void*)0;
}
Пример #4
0
/// Normalize features with a smooth mixture transformation o't=ot-sum(P(c|ot)Uc.x)
void FactorAnalysisStat::normalizeFeatures(SegCluster &selectedSegments,FeatureServer &fs,Config & config){
	if (verbose) cout << "(FactorAnalysisStat) Normalize Features" << endl;	
	MixtureGD & clientMixture=_ms.getMixtureGD(1); // copy the UBM mixture		
	unsigned long nt=0;	
	RealVector <double> m_xh_1; m_xh_1.setSize(_supervsize); 	
	double *_m_xh_1=m_xh_1.getArray();
	Seg *seg;          // current selectd segment
	selectedSegments.rewind();
	String currentSource="";
	while((seg=selectedSegments.getSeg())!=NULL){                	
		unsigned long begin=seg->begin()+fs.getFirstFeatureIndexOfASource(seg->sourceName()); 
		if (currentSource!=seg->sourceName()) {
			currentSource=seg->sourceName();
			this->getUX(m_xh_1,currentSource);
			this->getSpeakerModel(clientMixture,currentSource);			
			if (verbose)cout << "Processing speaker["<<currentSource<<"]"<< endl;	
		}		
		fs.seekFeature(begin);
		Feature f;
		if (!_topGauss) {
			for (unsigned long idxFrame=0;idxFrame<seg->length();idxFrame++){
				fs.readFeature(f,0);
				double *ff=f.getDataVector();				
				double sum=0.0;
				RealVector <double> P;
				P.setSize(_mixsize);
				double *Prob=P.getArray();
				for(unsigned long k=0;k<_mixsize;k++) {
					Prob[k]=clientMixture.weight(k)*clientMixture.getDistrib(k).computeLK(f);
					sum+=Prob[k];
					}
				for(unsigned long k=0;k<_mixsize;k++) 
					Prob[k]/=sum; 
				for(unsigned long k=0;k<_mixsize;k++) {
					for (unsigned long i=0;i<_vsize;i++) 
						ff[i]-= Prob[k]*_m_xh_1[k*_vsize+i];
					}
				fs.writeFeature(f);
				nt++;		
			}	
		}
		else {
			throw Exception("no topgauss yet",__FILE__,__LINE__);
		}
	}
};	
Пример #5
0
void FactorAnalysisStat::getUEstimateUnThreaded(){
	if (verbose) cout << "(FactorAnalysisStat) Compute U Estimate "<<endl;	
	DoubleSquareMatrix L(_rang);
	DoubleSquareMatrix L_Inv(_rang);
	RealVector <double> R;
	R.setSize(_rang);

	double *N_h=_matN_h.getArray(); 
	double *X=_matX.getArray();
	double *S_X_h=_matS_X_h.getArray();
	double *U=_matU.getArray();
	double *RV=R.getArray();
	double *LV=L.getArray();

	/*for(i=0;i<_supervsize;i++){
		unsigned long im=i/_vsize;
		L.setAllValues(0.0);
		R.setAllValues(0.0);
		for(j=0;j<_nb_sent;j++){
			double *l_h_inv=_l_h_inv[j].getArray();
			for(k=0;k<_rang;k++){
				for(l=0;l<_rang;l++) 
					LV[k*_rang+l]+=(l_h_inv[k*_rang+l]+X[j*_rang+k]*X[j*_rang+l])*N_h[j*_mixsize+im];
				RV[k]+=S_X_h[j*_supervsize+i]*X[j*_rang+k];
				}
			}		
		L.invert(L_Inv);
		double *L_InvV=L_Inv.getArray();
		for(j=0;j<_rang;j++)
			U[i*_rang+j]=0.0;
		for(j=0;j<_rang;j++)
			for(k=0;k<_rang;k++) 
				U[i*_rang+j]+=L_InvV[j*_rang+k]*RV[k];
	}*/
	_matU.setAllValues(0.0);
	for(unsigned long g=0;g<_mixsize;g++){		
		L.setAllValues(0.0);
		// Estimate LU for the gaussian g
		for(unsigned long j=0;j<_nb_sent;j++){
			double *l_h_inv=_l_h_inv[j].getArray();
			for(unsigned long k=0;k<_rang;k++)
				for(unsigned long l=0;l<_rang;l++) 
					LV[k*_rang+l]+=(l_h_inv[k*_rang+l]+X[j*_rang+k]*X[j*_rang+l])*N_h[j*_mixsize+g];
		}
		L.invert(L_Inv); 
		double *L_InvV=L_Inv.getArray();	
		
		// Estimate LU for the line lineNum
		for (unsigned long i=0;i<_vsize;i++) {
			unsigned long lineNum=_vsize*g+i;			
			// estime RU i
			R.setAllValues(0.0);
			for(unsigned long j=0;j<_nb_sent;j++)
				for(unsigned long k=0;k<_rang;k++)
					RV[k]+=S_X_h[j*_supervsize+lineNum]*X[j*_rang+k];
			// estime U i
			for(unsigned long j=0;j<_rang;j++)
				for(unsigned long k=0;k<_rang;k++) 
					U[lineNum*_rang+j]+=L_InvV[j*_rang+k]*RV[k];
		}
	}	
};