コード例 #1
0
ファイル: Evrot.cpp プロジェクト: BigkoalaZhu/STAR_PoCorr
Evrot::Evrot(Eigen::MatrixXd& X, int method):
	mMethod(method),
	mNumDims(X.cols()),
	mNumData(X.rows()),
	mNumAngles((int)(mNumDims*(mNumDims-1)/2)), // get the number of angles
	ik(Eigen::VectorXi(mNumAngles)),
	jk(Eigen::VectorXi(mNumAngles)),
	mX(X),
	mClusters(std::vector<std::vector<int> >(mNumDims)) //allocate clusters vector
{
	// build index mapping (to index upper triangle)
	int k = 0;
	for( int i=0; i<mNumDims-1; i++ ){
		for( int j=i+1; j<=mNumDims-1; j++ ){
			ik[k] = i;
			jk[k] = j;
			k++;
		}
	}

	evrot();
}
コード例 #2
0
double cluster_rotate(const double* mat,int row,int column,int* groups,int group_size,int* out_clusts,unsigned int* out_num,double* out_vr,int method)
{
	if(mat==NULL)
		return 0;
	else
	{
		double* cur_vr=new double[row*row];
		double* matV=new double[row*row];
		int* mycur_clusts=new int[group_size*row];
		double* out_Qs=new double[group_size];
		int tmpi=0;
		int tmpj=0;
		int tmpk=0;
		int vari=0;
		int vcur_column=0;
		double* doup_mat=NULL;
		double* doup_tmp=NULL;
		double* p_curvr=NULL;
		int* p_curclu=NULL;
		int* intp_tmp=NULL;
		double out_Q=0;
		MatrixInitZeros(cur_vr,row,row);
		MatrixInitZeros(matV,row,row);	
		vcur_column=groups[0];
		for(tmpj=0;tmpj<row;tmpj++)
		{
			mycur_clusts[tmpj]=0;
			doup_mat=(double*)(mat+tmpj*row);
			doup_tmp=(double*)(matV+tmpj*vcur_column);
			for(tmpi=0;tmpi<vcur_column;tmpi++)
			{
				doup_tmp[tmpi]=doup_mat[tmpi];
			}
		}

		p_curvr=out_vr;
		p_curclu=mycur_clusts;
		//cout<<"disp vcurr "<<endl;
		//DisplayMatrix(matV,10,vcur_column);
		out_Qs[0]=evrot(matV,vcur_column,row,p_curclu,p_curvr,method);
		out_Q=out_Qs[0];
		//cout<<"the "<<0<<"\tQuality is \t"<<out_Qs[tmpk]<<endl;
		for(tmpk=1;tmpk<group_size;tmpk++)
		{
				vari=groups[tmpk]-1;
				//cout<<"vari"<<vari<<endl;
				for(tmpj=0;tmpj<row;tmpj++)
				{
					doup_mat=(double*)(p_curvr+tmpj*vcur_column);
					doup_tmp=(double*)(matV+tmpj*(vcur_column+1));
					for(tmpi=0;tmpi<vcur_column;tmpi++)
						doup_tmp[tmpi]=doup_mat[tmpi];
					doup_tmp[tmpi]=mat[tmpj*row+vari];
				}
				vcur_column++;
				CopyFileToMatrix(doup_tmp,row,vcur_column,"vcur_vr");
				//cout<<"disp vcurr "<<endl;
				//DisplayMatrix(matV,10,vcur_column);
				p_curclu=(int*)(mycur_clusts+tmpk*row);
			 	out_Qs[tmpk]=evrot(matV,vcur_column,row,p_curclu,p_curvr,method);
				//cout<<"the "<<tmpk<<"\tQuality is \t"<<out_Qs[tmpk]<<endl;
		}
		p_curclu=mycur_clusts;
		CopyMatrixToFile(p_curclu,group_size,row,"all_out_clusts");
		tmpi=0;
		CopyMatrixToFile(out_Qs,group_size,1,"all_out_Quality");
		//cout<<"Out_Qs"<<endl;
		//cout<<out_Q<<"\t";
		for(tmpk=1;tmpk<group_size;tmpk++)
		{
			if(out_Q<out_Qs[tmpk])
			{
				out_Q=out_Qs[tmpk];
			}
			//cout<<out_Qs[tmpk]<<"\t";
		}
		//cout<<endl;
		for(tmpk=0;tmpk<group_size;tmpk++)
		{
			if((out_Q-out_Qs[tmpk])<=0.001)
			{
				tmpi=tmpk;
			}
		}
		/**/
		p_curclu=(int* )(mycur_clusts+tmpi*row);
		for(tmpk=0;tmpk<row;tmpk++)
			out_clusts[tmpk]=p_curclu[tmpk];
		*out_num=tmpi;
		/**/
		//clear memory
		delete []matV;
		delete []cur_vr;
		delete []mycur_clusts;
		delete []out_Qs;
		//
		return out_Q;
	}
};