Пример #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::getUX(RealVector <double> &ux,String& file) {
	ux.setAllValues(0.0);	
	unsigned long idx=_ndxTable.sessionNb(file);
	for (unsigned long i=0;i<_supervsize;i++)
		for (unsigned long j=0;j<_rang;j++) 
			ux[i]+=_matU(i,j)*_matX(idx,j);
};
Пример #3
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++;
	}
};
Пример #4
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;
}
Пример #5
0
void *Lthread(void *threadarg) {
	struct Lthread_data *my_data;
	my_data = (struct Lthread_data *) threadarg;
	double *U = my_data->U;
	unsigned long sentBottom = my_data->sentBottom;	
	unsigned long sentUp = my_data->sentUp;
	double *N_h=my_data->N_h;
	double *super_invvar=my_data->super_invvar;
	unsigned long _rang=my_data->rang;
	unsigned long _supervsize=my_data->sv;
	unsigned long _vsize=my_data->vsize;
	unsigned long _mixsize=my_data->mixsize;
	for (unsigned long sent=sentBottom;sent <sentUp;sent++) {
		DoubleSquareMatrix L(_rang);	
		L.setAllValues(0.0);	
		double *LV=L.getArray();
		unsigned long mk;
		RealVector <double> AUX;
		AUX.setSize(_rang);
		AUX.setAllValues(0.0);
		for(unsigned long i=0;i<_rang;i++){
			for(unsigned long j=0;j<=i;j++){
				for(unsigned long k=0;k<_supervsize;k++){
					mk=k/_vsize;
					LV[i*_rang+j]+=N_h[sent*_mixsize+mk]*super_invvar[k]*U[k*_rang+i]*U[k*_rang+j];
				}
			}
		}
		for(unsigned long i=0;i<_rang;i++)
			for(unsigned long j=i+1;j<_rang;j++) 
				LV[i*_rang+j]=LV[j*_rang+i];
					
		for(unsigned long i=0;i<_rang;i++) 
			LV[i*_rang+i]+=1.0;	
		DoubleSquareMatrix &linv=(*(my_data->linv))[sent];		
		L.invert(linv);
	}
	pthread_exit((void*) 0);
	return (void*)0;
}
Пример #6
0
void FactorAnalysisStat::estimateAndInverseLUnThreaded(){
	if (verbose) cout << "(FactorAnalysisStat) Inverse L Matrix ... "<<endl;	
	unsigned long mk;
	DoubleSquareMatrix L(_rang);	
	L.setAllValues(0.0);
	RealVector <double> AUX;
	AUX.setSize(_rang);
	unsigned long sent=0;
	XLine *pline;
	String *pFile;
	fileList.rewind();

	double *N_h=_matN_h.getArray(); 
	double *U=_matU.getArray();
	double *LV=L.getArray();
	double *super_invvar=_super_invvar.getArray();
	
	while((pline=fileList.getLine())!=NULL) {
		while((pFile=pline->getElement())!=NULL) {
			L.setAllValues(0.0);
			AUX.setAllValues(0.0);
			for(unsigned long i=0;i<_rang;i++){
				for(unsigned long j=0;j<=i;j++){
					for(unsigned long k=0;k<_supervsize;k++){
						mk=k/_vsize;
						LV[i*_rang+j]+=N_h[sent*_mixsize+mk]*super_invvar[k]*U[k*_rang+i]*U[k*_rang+j];
						}
					}
				}
			for(unsigned long i=0;i<_rang;i++)
				for(unsigned long j=i+1;j<_rang;j++) 
					LV[i*_rang+j]=LV[j*_rang+i];
				
			for(unsigned long i=0;i<_rang;i++) 
				LV[i*_rang+i]+=1.0;
			L.invert(_l_h_inv[sent]);	
			sent++;
		}
	}
};
Пример #7
0
// Compute supervector of client M_s_h=M+Dy_s
void FactorAnalysisStat::getMplusDY(RealVector <double> &Sp, String& file) {
	Sp.setAllValues(0.0);
	unsigned long loc=_ndxTable.locNb(file);		
	for (unsigned long i=0;i<_supervsize;i++)
		Sp[i]=_super_mean[i]+_D[i]*_matY(loc,i);
};
Пример #8
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];
		}
	}	
};