Пример #1
0
void hgemitter::SetDirectionFromAngle( int flag, VECTOR *res, VECTOR *ang )
{
	float spd;
	VECTOR v;

	spd = speed;
	if ( spd != 0.0f ) spd += ((float)(rand()&4095) * FRND_4096 ) * speedopt;

	if ( flag == HGMODEL_FLAG_2DSPRITE ) {
		SetVector( res, sin(ang->z) * spd, cos(ang->z) * spd, 0.0f, 0.0f );
		return;
	}

	SetVector( &v, 0.0f, 0.0f, spd, 0.0f );
	InitMatrix();
	switch( rotorder ) {
	case HGMODEL_ROTORDER_ZYX:
		RotZ( ang->z );
		RotY( ang->y );
		RotX( ang->x );
		break;
	case HGMODEL_ROTORDER_XYZ:
		RotX( ang->x );
		RotY( ang->y );
		RotZ( ang->z );
		break;
	case HGMODEL_ROTORDER_YXZ:
		RotY( ang->y );
		RotX( ang->x );
		RotZ( ang->z );
		break;
	}
	ApplyMatrix( res, &v );
}
Пример #2
0
int main(void)
{
    //ClockInit();

    InitMatrix();
    LAT_CS = 0;
    BlankMatrix();
    LAT_CS = 1;

    drawChar('1', 0, 0);
    drawChar('2', 5, 0);
    drawChar(':', 10, 0);
    drawChar('3', 15, 0);
    drawChar('4', 20, 0);

    while(1)
    {
        /*
        //moved to ISR
        if(matrixDoesNeedService())
        {
            LAT_CS = 0;
            ScanMatrix();
            LAT_CS = 1;
        }
        */
    }
    return 0;
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	InitMatrix();
	InitTexture();
	InitVB();
	InitPS();
	return S_OK;
}
Пример #4
0
/**
**  Allocate a new matrix and initialize
*/
unsigned char *MakeMatrix(void)
{
	unsigned char *matrix;

	matrix = new unsigned char[(Map.Info.MapWidth + 2) * (Map.Info.MapHeight + 3) + 2];
	InitMatrix(matrix);

	return matrix;
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	InitMatrix();

	// 최초의 마우스 위치 보관
	POINT	pt;
	GetCursorPos( &pt );
	g_dwMouseX = pt.x;
	g_dwMouseY = pt.y;
	return S_OK;
}
Пример #6
0
void EigenVectors::GetEigenVectors(DMatrix &egvts, DArray &egvls) const {
    EigenValues egvl(input_);
    egvl.ComputeEigenValues();
    egvls = egvl.GetRealEigenValues();
    int size = egvls.size();
    InitMatrix(egvts, size);
    for(int i = 0; i < size; ++i) {
        egvls[i] = RoundToZero(egvls[i]);
        FindEigenVector(egvts, egvls[i], i);
    }
}
Пример #7
0
void SClock::OnPaint(SOUI::IRenderTarget * pRT)
{
	SWindow::OnPaint(pRT);

	CRect rcClient;
	GetClientRect(&rcClient);

	CPoint center = rcClient.CenterPoint();

	// 计算矩形
	// 35 * 16
	CRect rcDraw(center, SOUI::CPoint(center.x + 200, center.y + 32));
	rcDraw.OffsetRect(-35, -16);
	CRect rcSrc(0, 0, 200, 32);


    SYSTEMTIME last_refresh_time;
    ::GetLocalTime(&last_refresh_time);

    {
        double angle = GetHourAngle(last_refresh_time.wHour,last_refresh_time.wMinute);
        SMatrix form = InitMatrix(angle,  center);
        pRT->SetTransform(&form, NULL);
        pRT->DrawBitmapEx(rcDraw, pointer_hour, &rcSrc, EM_STRETCH, 255);
    }

    {
        double angle = GetMinuteSecondAngle(last_refresh_time.wMinute);
        SMatrix form = InitMatrix(angle, center);
        pRT->SetTransform(&form, NULL);
        pRT->DrawBitmapEx(rcDraw, pointer_minute, &rcSrc, EM_STRETCH, 255);
    }

    {
        double angle = GetMinuteSecondAngle(last_refresh_time.wSecond);
        SMatrix form = InitMatrix(angle, center);
        pRT->SetTransform(&form, NULL);
        pRT->DrawBitmapEx(rcDraw, pointer_second, &rcSrc, EM_STRETCH, 255);
    }
	pRT->SetTransform(&SMatrix());
}
Пример #8
0
float
CRebuildGraph::compareMatrix(gsl_matrix* matrixA, gsl_matrix*matrixB){

    
    float delta;
    gsl_vector *work ,*s;
    
    
    if (matrixA->size1 != matrixB->size1)
        throw runtime_error(" size 1 and size 2 are different");
    
    gsl_matrix *U1, *U2,*V1,*V2;
    
    InitMatrix((int)matrixA->size1,&work,&s,&U1,&U2,&V1,&V2);

    gsl_matrix_memcpy (U1, matrixA);
    //gsl_linalg_SV_decomp (gsl_matrix * A, gsl_matrix * V, gsl_vector * S, gsl_vector * work)
    //La matriu A es substitueix per U a la sortida
    gsl_linalg_SV_decomp(U1,V1,s,work);

    gsl_matrix_memcpy (U2, matrixB);
    gsl_linalg_SV_decomp(U2,V2,s,work);

    //F = U1 VS2 V1^T = U1 U2^T A2 V2 V1^T
    gsl_matrix *F=gsl_matrix_alloc(matrixA->size1,matrixA->size1);
    gsl_matrix_transpose(U2);
    multiplica(F,U1,U2);
    multiplica(F,F,matrixB);
    multiplica(F,F,V2);
    gsl_matrix_transpose(V1);
    multiplica(F,F,V1);

    //F ja esta calculada. Calculem la norma.
    delta=0;
    for(int i=0; i<matrixA->size1; i++){
    for(int j=0; j<matrixA->size1; j++){
        delta+=pow(gsl_matrix_get(matrixA,i,j)-gsl_matrix_get(F,i,j),2);
    }
    }
    delta=std::pow(delta,0.5f);
    delta/=matrixA->size1;

    printingCompareMatrixResults(delta,F,matrixA);
    FreeMatrix(&work,
               &s,
              &U1,
               &U2,
               &V1,
               &V2,
               &F );

    return delta;
}
Пример #9
0
void AcceptPolygon(Matrix *polygon)
{
	int i,nv;
	printf("Give number of vertices: ");
	scanf("%d",&nv);
	InitMatrix(polygon,nv+1,4);
	for(i=0;i<nv;i++)
	{
		printf("Give coordinates of vertex(%d): ",i+1);
		scanf("%f%f",&polygon->matrix[i][0],&polygon->matrix[i][1]);
	}
	polygon->matrix[i][0] = polygon->matrix[0][0];
	polygon->matrix[i][1] = polygon->matrix[0][1];
}
Пример #10
0
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	InitMatrix();
	// 빌보드로 사용할 텍스처 이미지
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree01S.dds", &g_pTexBillboard[0] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree02S.dds", &g_pTexBillboard[1] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tree35S.dds", &g_pTexBillboard[2] );
	D3DXCreateTextureFromFile( g_pd3dDevice, "tex.jpg", &g_pTexBillboard[3] );
	
	// 최초의 마우스 위치 보관
	POINT	pt;
	GetCursorPos( &pt );
	g_dwMouseX = pt.x;
	g_dwMouseY = pt.y;
	return S_OK;
}
Пример #11
0
  ForceCeperley::ForceCeperley(ParticleSet& ions, ParticleSet& elns): 
    ForceBase(ions, elns)
    {
      ReportEngine PRE("ForceCeperley","ForceCeperley");
      myName = "Ceperley_Force_Base";
      prefix="HFCep";

      // hard wired parameters but these should be made user-defined
      Rcut = 0.4;
      m_exp = 2;
      N_basis = 4;
      ///////////////////////////////////////////////////////////////
      
      InitMatrix();
      forces = 0.0;
      forces_ShortRange.resize(Nnuc);
      forces_ShortRange = 0.0;
    }
Пример #12
0
void ScanlineFill()
{
	Matrix polygon;
	int boxLeft, boxRight, boxHigh, boxLow;
	int i,j,k;
	int edgeXat_i,lim_y_up,lim_y_down;
	Matrix xlist;
	AcceptPolygon(&polygon);
	InitGraph();
	DrawPolygon(&polygon);
	InitEdges(&polygon);
	MinMax(&polygon,0,0,polygon.rows-1,&boxLeft,&boxRight);
	MinMax(&polygon,1,0,polygon.rows-1,&boxLow,&boxHigh);
	InitMatrix(&xlist,polygon.rows-1,1);
	for(i=boxLow+1,k=0;i<boxHigh;i++,k=0)
	{
		for(j=0;j<polygon.rows-1;j++)
		{
			if((int)polygon.matrix[j][0] == (int)polygon.matrix[j+1][0])
				edgeXat_i = polygon.matrix[j][0];
			else if((int)polygon.matrix[j][1] == (int)polygon.matrix[j+1][1])
				edgeXat_i = polygon.matrix[j][0]<polygon.matrix[j+1][0]?polygon.matrix[j][0]:polygon.matrix[j+1][0];
			else
				edgeXat_i = (i - polygon.matrix[j][3])/polygon.matrix[j][2];
			if(edgeXat_i>=boxLeft && edgeXat_i<=boxRight )
			{
				lim_y_up = polygon.matrix[j][1]<polygon.matrix[j+1][1]?polygon.matrix[j][1]:polygon.matrix[j+1][1];
				lim_y_down = polygon.matrix[j][1]>polygon.matrix[j+1][1]?polygon.matrix[j][1]:polygon.matrix[j+1][1];
				if(lim_y_up<=i && i<=lim_y_down)
					xlist.matrix[k++][0] = edgeXat_i;
			}
			DPQS(&xlist,0,0,k-1);
		}
		for(j=0;j<k;j+=2)
			line(xlist.matrix[j][0]+1,i,xlist.matrix[j+1][0],i);
	}
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	if ( FAILED( InitTexture() ) )
	{
		return E_FAIL;
	}
	if ( FAILED( InitVB() ) )
	{
		return E_FAIL;
	}
	if ( FAILED( InitIB() ) )
	{
		return E_FAIL;
	}

	InitMatrix();

	// 최초의 마우스 위치 보관
	POINT	pt;
	GetCursorPos( &pt );
	g_dwMouseX = pt.x;
	g_dwMouseY = pt.y;
	return S_OK;
}
Пример #14
0
/**
     * Construct an ELM
     * @param
     * elm_type              - 0 for regression; 1 for (both binary and multi-classes) classification
     */
void ELMTrain(int elm_type)
{
	double starttime,endtime;
	double TrainingAccuracy;
	int i,j,k = 0;
	float **input,**weight,*biase,**tranpI,**tempH,**H;
	float **PIMatrix;
	float **train_set;
	float **T,**Y;
	float **out;
	
	train_set = (float **)calloc(DATASET,sizeof(float *));
	tranpI = (float **)calloc(INPUT_NEURONS,sizeof(float *));
	input = (float **)calloc(DATASET,sizeof(float *));        		/*datasize * INPUT_NEURONS*/
	weight = (float **)calloc(HIDDEN_NEURONS,sizeof(float *));		/*HIDDEN_NEURONS * INPUT_NEURONS*/
	biase = (float *)calloc(HIDDEN_NEURONS,sizeof(float)); 			/*HIDDEN_NEURONS*/
	tempH = (float **)calloc(HIDDEN_NEURONS,sizeof(float *)); 		/*HIDDEN_NEURONS * datasize*/
	PIMatrix = (float **)calloc(HIDDEN_NEURONS,sizeof(float *));
	H = (float **)calloc(DATASET,sizeof(float *));
	T = (float **)calloc(DATASET,sizeof(float *));
	Y = (float **)calloc(DATASET,sizeof(float *));
	out = (float **)calloc(HIDDEN_NEURONS,sizeof(float *));
	
	for(i=0;i<DATASET;i++){
		train_set[i] = (float *)calloc(NUMROWS,sizeof(float));
		input[i] = (float *)calloc(INPUT_NEURONS,sizeof(float));
		H[i] = (float *)calloc(HIDDEN_NEURONS,sizeof(float));
	}
	for(i=0;i<DATASET;i++)
	{
		T[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
		Y[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
	}
	for(i=0;i<INPUT_NEURONS;i++)
		tranpI[i] = (float *)calloc(DATASET,sizeof(float));
	
	for(i=0;i<HIDDEN_NEURONS;i++)
	{
		weight[i] = (float *)calloc(INPUT_NEURONS,sizeof(float));
		tempH[i] = (float *)calloc(DATASET,sizeof(float));
		out[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
		PIMatrix[i] = (float *)calloc(DATASET,sizeof(float));
	}
	
	printf("begin to random weight and biase...\n");
	/*得到随机的偏置和权重*/
	RandomWeight(weight,HIDDEN_NEURONS,INPUT_NEURONS);
	RandomBiase(biase,HIDDEN_NEURONS);
	SaveMatrix(weight,"./result/weight",HIDDEN_NEURONS,INPUT_NEURONS);
	SaveMatrix_s(biase,"./result/biase",1,HIDDEN_NEURONS);
	/*加载数据集到内存*/
	printf("begin to load input from the file...\n");
	if(LoadMatrix(train_set,"./sample/frieman",DATASET,NUMROWS) == 0){
		printf("load input file error!!!\n");	
		return;
	}
	
	/*将数据集划分成输入和输出*/
	if(elm_type == 0){ 	//regression
		/*
			the first column is the output of the dataset
		*/
		for(i = 0;i < DATASET ;i++)
		{
			T[k++][0] = train_set[i][0];
			for(j = 1;j <= INPUT_NEURONS;j++)
			{
				input[i][j-1] = train_set[i][j];
			}
		}
	}else{				//classification
		/*
			the last column is the lable of class of the dataset
		*/
		InitMatrix(T,DATASET,OUTPUT_NEURONS,-1);
		for(i = 0;i < DATASET ;i++)
		{
			//get the last column
			T[k++][0] = train_set[i][0] - 1;//class label starts from 0,so minus one
			for(j = 1;j <= INPUT_NEURONS;j++)
			{
				input[i][j-1] = train_set[i][j];
			}
		}
		for(i = 0;i < DATASET ;i++)
		{
			for(j = 0;j < OUTPUT_NEURONS;j++)
			{
				k =  T[i][0];
				if(k < OUTPUT_NEURONS && k >= 0){
					T[i][k] = 1;
				}
				if(k != 0){
					T[i][0] = -1;
				}
			}
		}
	}
	/*ELM*/
	printf("begin to compute...\n");
	starttime = omp_get_wtime();	
	TranspositionMatrix(input,tranpI,DATASET,INPUT_NEURONS);
	printf("begin to compute step 1...\n");
	MultiplyMatrix(weight,HIDDEN_NEURONS,INPUT_NEURONS, tranpI,INPUT_NEURONS,DATASET,tempH);
	printf("begin to compute setp 2...\n");
	AddMatrix_bais(tempH,biase,HIDDEN_NEURONS,DATASET);
	printf("begin to compute step 3...\n");
	SigmoidHandle(tempH,HIDDEN_NEURONS,DATASET);
	printf("begin to compute step 4...\n");
	TranspositionMatrix(tempH,H,HIDDEN_NEURONS,DATASET);
	PseudoInverseMatrix(H,DATASET,HIDDEN_NEURONS,PIMatrix);
	MultiplyMatrix(PIMatrix,HIDDEN_NEURONS,DATASET,T,DATASET,OUTPUT_NEURONS,out);

	//SaveMatrix(H,"./result/H",DATASET,HIDDEN_NEURONS);
	//SaveMatrix(PIMatrix,"./result/PIMatrix",HIDDEN_NEURONS,DATASET);
	printf("begin to compute step 5...\n");
	endtime = omp_get_wtime();
	//保存输出权值
	SaveMatrix(out,"./result/result",HIDDEN_NEURONS,OUTPUT_NEURONS);
	MultiplyMatrix(H,DATASET,HIDDEN_NEURONS,out,HIDDEN_NEURONS,OUTPUT_NEURONS,Y);
	printf("use time :%f\n",endtime - starttime);
	printf("train complete...\n");

	if(elm_type == 0){
	//检测准确率
		double MSE = 0;
		for(i = 0;i< DATASET;i++)
		{
			MSE += (Y[i][0] - T[i][0])*(Y[i][0] - T[i][0]);
		}
		TrainingAccuracy = sqrt(MSE/DATASET);
		printf("Regression/trainning accuracy :%f\n",TrainingAccuracy);
	}else{
		float MissClassificationRate_Training=0;
		double maxtag1,maxtag2;
		int tag1 = 0,tag2 = 0;
		for (i = 0; i < DATASET; i++) {
				maxtag1 = Y[i][0];
				tag1 = 0;
				maxtag2 = T[i][0];
				tag2 = 0;
		    	for (j = 1; j < OUTPUT_NEURONS; j++) {
					if(Y[i][j] > maxtag1){
						maxtag1 = Y[i][j];
						tag1 = j;
					}
					if(T[i][j] > maxtag2){
						maxtag2 = T[i][j];
						tag2 = j;
					}
				}
		    	if(tag1 != tag2)
		    		MissClassificationRate_Training ++;
			}
		    TrainingAccuracy = 1 - MissClassificationRate_Training*1.0f/DATASET;
			printf("Classification/training accuracy :%f\n",TrainingAccuracy);
	}
	FreeMatrix(train_set,DATASET);
	FreeMatrix(tranpI,INPUT_NEURONS);
	FreeMatrix(input,DATASET);
	FreeMatrix(weight,HIDDEN_NEURONS);
	free(biase);
	FreeMatrix(tempH,HIDDEN_NEURONS);
	FreeMatrix(PIMatrix,HIDDEN_NEURONS);
	FreeMatrix(H,DATASET);
	FreeMatrix(T,DATASET);
	FreeMatrix(Y,DATASET);
	FreeMatrix(out,HIDDEN_NEURONS);
}
Пример #15
0
// 
// Here we want to rotate by Y, then by X. If we rotate by X first, the Y rotation
// will cause the camera to be rotated on its Y axis, not the world's, distorting the view.
//
void FreelookCamera::ConstructMatrix()
{
	InitMatrix();
	RotateY();
	RotateX();
}
Пример #16
0
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    double *matrix, *U, *P;
    double *idmatrix, *L;
    double *B, *X, *Y;
    int n_row,n_column;
    int i;
    printf("please input the dimonsion of the Matrix you'll make:m & n:\n");
    scanf("%d %d",&n_row,&n_column);

/*--intialize the matrix which would be triangular factorize and the identity matrix--*/
    matrix = InitMatrix(n_row, n_column, matrix,1);
    double *matrix2;
    matrix2 = InitMatrix(n_row, n_column, matrix2,1);
    idmatrix = InitIdMatrix(n_row, n_column, idmatrix);
    P = InitIdMatrix(n_row, n_column, P);

/*--show the matrixs--*/
    //printf("\nthe A(matrix) = ");
    //PrintMatrix(n_row, n_column, matrix);
    //PrintMatrix(n_row, n_column, idmatrix);

    B = InitBMatrix(n_row, B);
    printf("\nB = ");
    PrintMatrix(n_row, 1, B);
//pivoting the matrix
    Pivoting(n_row, n_column, matrix,P);
    B = AB(n_row,n_column,1,P,B);
    //printf("after pivoting, P = ");
    //PrintMatrix(n_row,n_column,P);
    //printf("after pivoting, B = ");
    //PrintMatrix(n_row,1,B);
    //printf("after pivoting, matrix = ");
    //PrintMatrix(n_row,n_column,matrix);
/*--Using the triangular factorization to factorize the matrix--*/
//matrix had been changed
    LUFact(n_row, n_column, matrix, idmatrix);

/*--show the result of the matrix had been factorized--*/
    //printf("L = ");//show the lower-triangular matrix
    L = idmatrix;
    //PrintMatrix(n_row, n_column, L);
    //printf("U = ");//show the upper-triangular matrix
    U = matrix;
    //PrintMatrix(n_row, n_column, U);

    X = InitMatrix(n_row, 1, X,0);
    Y = InitMatrix(n_row, 1, Y,0);
    //printf("check the B will used:");
    //PrintMatrix(n_row,1,B);
    /*--use back sub to calculate X and Y--*/
    BackSub4Y(n_row, n_column, L, Y, B);
    BackSub4X(n_row, n_column, U, X, Y);

    /*printf("X = ");
    PrintMatrix(n_row, 1, X);
    B=AB(n_row,n_column,1,U,X);
    printf("UX = ");
    PrintMatrix(n_row, 1, B);
    B=AB(n_row,n_column,1,L,B);
    printf("LUX = ");
    PrintMatrix(n_row, 1, B);
    printf("A=");
    PrintMatrix(n_row,n_column,matrix2);*/
    //verify the answer
    B = AB(n_row,n_column,1,matrix2,X);
    printf("AX = ");
    PrintMatrix(n_row,1,B);
    return 0;
}
Пример #17
0
/**
**  Create empty movement matrix.
*/
unsigned char *CreateMatrix(void)
{
	InitMatrix(Matrix);
	return Matrix;
}
Пример #18
0
CMatrix::CMatrix()
{
	InitMatrix();
}
Пример #19
0
int main(int argc,char **argv){

	int i,j,k = 0;
	double TrainingAccuracy;
	float **input,**weight,*biase,**tranpI,**tempH,**H;
	float **train_set;
	float **T,**Y;
	float **out;
	
	train_set = (float **)calloc(TESTSET,sizeof(float *));
	tranpI = (float **)calloc(INPUT_NEURONS,sizeof(float *));
	input = (float **)calloc(TESTSET,sizeof(float *));        		/*datasize * INPUT_NEURONS*/
	weight = (float **)calloc(HIDDEN_NEURONS,sizeof(float *));		/*HIDDEN_NEURONS * INPUT_NEURONS*/
	biase = (float *)calloc(HIDDEN_NEURONS,sizeof(float)); 			/*HIDDEN_NEURONS*/
	tempH = (float **)calloc(HIDDEN_NEURONS,sizeof(float *)); 		/*HIDDEN_NEURONS * datasize*/
	H = (float **)calloc(TESTSET,sizeof(float *));
	T = (float **)calloc(TESTSET,sizeof(float *));
	Y = (float **)calloc(TESTSET,sizeof(float *));
	out = (float **)calloc(HIDDEN_NEURONS,sizeof(float *));
	
	for(i=0;i<TESTSET;i++){
		train_set[i] = (float *)calloc(NUMROWS,sizeof(float));
		input[i] = (float *)calloc(INPUT_NEURONS,sizeof(float));
		H[i] = (float *)calloc(HIDDEN_NEURONS,sizeof(float));
	}
	for(i=0;i<TESTSET;i++)
	{
		T[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
		Y[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
	}
	for(i=0;i<INPUT_NEURONS;i++){
		tranpI[i] = (float *)calloc(TESTSET,sizeof(float));
	}
	
	for(i=0;i<HIDDEN_NEURONS;i++)
	{
		weight[i] = (float *)calloc(INPUT_NEURONS,sizeof(float));
		tempH[i] = (float *)calloc(TESTSET,sizeof(float));
		out[i] = (float *)calloc(OUTPUT_NEURONS,sizeof(float));
	}
	printf("begin to classification test...\n");	
	/*得到随机的偏置和权重*/
	//RandomWeight(weight,HIDDEN_NEURONS,INPUT_NEURONS);
	//RandomBiase(biase,HIDDEN_NEURONS);
	printf("begin to load weight...\n");
	if(LoadMatrix(weight,"../result/weight",HIDDEN_NEURONS,INPUT_NEURONS) == 0){
		printf("load weight file error!!!\n");	
		return 0;
	}
	printf("begin to load bias...\n");
	if(LoadMatrix_s(biase,"../result/biase",1,HIDDEN_NEURONS) == 0){
		printf("load bias file error!!!\n");	
		return 0;
	}
	/*加载数据集到内存*/
	printf("begin to load test file...\n");
	if(LoadMatrix(train_set,"../sample/covtype_test",TESTSET,NUMROWS) == 0){
		printf("load input file error!!!\n");	
		return 0;
	}
	InitMatrix(T,TESTSET,OUTPUT_NEURONS,-1);
	/*将数据集划分成输入和输出*/
	for(i = 0;i < TESTSET ;i++)
	{
			//get the last column
		T[k++][0] = train_set[i][0] - 1;//class label starts from 0,so minus one
		for(j = 1;j <= INPUT_NEURONS;j++)
		{
			input[i][j-1] = train_set[i][j];
		}
	}
	for(i = 0;i < TESTSET ;i++)
	{
		for(j = 0;j < OUTPUT_NEURONS;j++)
		{
			k =  T[i][0];
			if(k < OUTPUT_NEURONS && k >= 0){
				T[i][k] = 1;
			}
			if(k != 0){
				T[i][0] = -1;
			}
		}
	}
	/*ELM*/
	printf("begin to compute...\n");
	
	TranspositionMatrix(input,tranpI,TESTSET,INPUT_NEURONS);
	printf("begin to compute step 1...\n");
	MultiplyMatrix(weight,HIDDEN_NEURONS,INPUT_NEURONS, tranpI,INPUT_NEURONS,TESTSET,tempH);
	printf("begin to compute setp 2...\n");
	AddMatrix_bais(tempH,biase,HIDDEN_NEURONS,TESTSET);
	printf("begin to compute step 3...\n");
	SigmoidHandle(tempH,HIDDEN_NEURONS,TESTSET);
	printf("begin to compute step 4...\n");
	TranspositionMatrix(tempH,H,HIDDEN_NEURONS,TESTSET);
	printf("begin to load hidden output matrix from the file...\n");
	if(LoadMatrix(out,"../result/result",HIDDEN_NEURONS,OUTPUT_NEURONS) == 0){
		printf("load input file error!!!\n");	
		return 0;
	}
	MultiplyMatrix(H,TESTSET,HIDDEN_NEURONS,out,HIDDEN_NEURONS,OUTPUT_NEURONS,Y);
	float MissClassificationRate_Training=0;
	double maxtag1,maxtag2;
	int tag1 = 0,tag2 = 0;
	for (i = 0; i < TESTSET; i++) {
		maxtag1 = Y[i][0];
		tag1 = 0;
		maxtag2 = T[i][0];
		tag2 = 0;
		for (j = 1; j < OUTPUT_NEURONS; j++) {
			if(Y[i][j] > maxtag1){
				maxtag1 = Y[i][j];
				tag1 = j;
			}
			if(T[i][j] > maxtag2){
				maxtag2 = T[i][j];
				tag2 = j;
			}
		}
		if(tag1 != tag2)
		    	MissClassificationRate_Training ++;
	}
	TrainingAccuracy = 1 - MissClassificationRate_Training*1.0f/TESTSET;
	printf("trainning accuracy :%f\n",TrainingAccuracy);
	printf("test complete...\n");
	//print(PIMatrix,TESTSET,HIDDEN_NEURONS);
		
	return 0;
}
Пример #20
0
//---------------------------------------------------------------------------
//	コンストラクタ
//---------------------------------------------------------------------------
void GeometryInit(void)
{
  InitMatrix();
  //RightHand();
  LeftHand();
}
Пример #21
0
int main(){
	int gd=DETECT, gm;
	int Return=0;
	char Key, ScanCode;
	int Counter=0;                          //Divide total delay & take multiple input
	initgraph(&gd, &gm,"c:\\tc\\bgi");      //initialize graphics mode
	randomize();                            //Randomize block's shapes & color
	cleardevice();                          //clear screen
	InitPalette();                          //for setting color pallete
	InitMatrix();                           //Initialize Matrix
	GetImages();                            //Saving the images
	StartScreen();                          //for start screen
	cleardevice();                          //clear screen
	AssignShape(GetRandomShape(), GetRandomColor());      //for the falling block
	NextShape=GetRandomShape();
	NextColor=GetRandomColor();                                         	DisplayScreen();                        //Show main screen
	DisplayNextShape();                     //show next brick
	MoveBlock(LEFT);                        //keep the block on center & check game over
	while(kbhit()) getch();  		//empty the keyboard input
	while (!Quit && !GameOver) {            //Moving the blocks down
		if(++Counter >= Speed)          //For controling the speed
		{	Counter=0;
			MoveBlock(DOWN);
			SoundDrop();
		}
		if(kbhit())                     //For the arrow keys
		{  Key = getch();
		   if(Key == 0)
		   {	   ScanCode = getch();
			   if(ScanCode == KEY_UP)
					RotateBlock();
			   else if(ScanCode == KEY_LEFT)
					MoveBlock(LEFT);
			   else if(ScanCode == KEY_RIGHT)
					MoveBlock(RIGHT);
			   else if(ScanCode == KEY_DOWN)
			   {		Score++;         //increase score
					PrintScore();
					MoveBlock(DOWN);
			   }
			   if(!Return)
				   SoundDrop();
			   Return = 0;
		   }
		   else if(Key == KEY_ENTER || Key == KEY_SPACE)   //Rotating bricks
				RotateBlock();
		   else if(Key == 'P' || Key == 'p')      //For pause
		   {	  MessageBox("  Paused");
			  while(kbhit()) getch();         //clear the keyboard input
			  for(int x=0; x<COLS; x++)
				 for(int y=0; y<ROWS; y++)
					PreviousScreenLayout[x][y] -= 1;    //Clear the present screen layout to refresh the whole screen
			  UpdateScreen();                //refresh screen
		   }
		   else if(Key == KEY_ESC)                                      //For quit
		   {	  char ret = MessageBox("Are you sure, you want to Quit?", 563, 2);
			  if(ret == 'y' || ret == 'Y' || ret == KEY_ENTER)
			  {	  Quit = 1;
				  break;
			  }
			  cleardevice();                              //Clear the message box
			  while(kbhit()) getch();  		      //Clear the keyboard input
			  for(int x=0; x<COLS; x++)
				 for(int y=0; y<ROWS; y++)
					PreviousScreenLayout[x][y] -= 1;    // Clear the present screen layout to refresh the whole screen
			  UpdateScreen();                //refresh screen
			  DisplayScreen();               //show the main screen again
			  DisplayNextShape();            //show next brick box
		   }
		   else if(Key == 's' || Key == 'S')        //For sound on/off
		   {
			  SoundOn = !SoundOn;

		   }
		   else if(Key=='a' || Key=='A')                      //For author
		   {	 MessageBox("Author: Aguntuk Group",450);
			 cleardevice();                               //Clear the message box
			 while(kbhit()) getch();                      //Clear the keyboard input
			 for(int x=0;x<COLS;x++)
				for(int y=0;y<ROWS;y++)
					PreviousScreenLayout[x][y] -=1;     //Clear the present screen layout to refresh the whole screen
			 UpdateScreen();                   //refresh screen
			 DisplayScreen();                  //show the main screen again
			 DisplayNextShape();               //show next brick box
		   }
		}
		delay(6);      	      //For moving down the blocks slowly
	}
	if(GameOver)                  //For game over option
	{      	DisplayBlock(6,0);    //For display the top most brick
		ShowGameOver();       //For display game over message box
	}
	restorecrtmode();    //For closing graphicg mode
	return 0;
}
Пример #22
0
// ****************************************************************************
//
//  Function Name:	RTrueTypeFont::ExtractCharacterOutline( )
//
//  Description:		Retrieve a glyph outline and parse it into segment records 
//							in the global buffer
//
//  Returns:			Boolean indicating successful completion
//
//  Exceptions:		Memory
//
// ****************************************************************************
//
BOOLEAN	RTrueTypeFont::ExtractCharacterOutline( int character, uLONG cookie )
{
YTTSegmentInfoRecord*	pSegments = (YTTSegmentInfoRecord *)( cookie + sizeof(uLONG) );
const YFontInfo			fontInfo = GetInfo();
GlyphOutline 				glyph;
Matrix 						matrix;
long 							glyphIndex = 0;					// zero is the missing character

	// retrieve font resource
	if ( m_hSfnt == NULL )
	{
		short		rId;
		ResType	rType;
		Str255	rName;
		m_hSfnt = GetSfntHandle( (const LPSZ)fontInfo.sbName, RFont::GetMacStyleBits( fontInfo.attributes ) );
		GetResInfo( m_hSfnt, &rId, &rType, rName);
		m_sSfntId = rId;
	}
	else if ( *m_hSfnt == NULL )
	{
		::LoadResource( m_hSfnt );
//		m_hSfnt = ::GetResource( 'sfnt', m_sSfntId );
	}
	if ( m_hSfnt == NULL || *m_hSfnt == NULL )
		return FALSE;
	::HNoPurge( m_hSfnt );

	// extract character outline
	InitMatrix( matrix );
	InitGlyphOutline( &glyph );
	MakeIdentityMatrix( matrix );
	try
	{
		glyphIndex = GetCharGlyphIndex( m_hSfnt, character );
		GetGlyphOutline( m_hSfnt, glyphIndex, &glyph, matrix );
		ScaleGlyphOutline( &glyph, ::Long2Fix( fontInfo.height ), ::Long2Fix( fontInfo.height ) );
	}
	catch ( YException except )
	{
		::HPurge( m_hSfnt );
		KillGlyphOutline( &glyph );
		switch ( except ) 
		{
			case kResource:
				return FALSE;
				break;
			default:
				throw;
				break;
		}
	}
	catch ( ... )
	{
		::HPurge( m_hSfnt );
		KillGlyphOutline( &glyph );
		throw;
	}

	// loop thru the contours
	LockGlyphOutline( &glyph );
	{
		long			nrSegments = 0;
		long			sp = 0;
		Fixed*		x = *glyph.x;
		Fixed*		y = *glyph.y;
		short*		ep = *glyph.endPoints;
		Byte*			onCurve = *glyph.onCurve;
		RIntPoint	ptStart;
		for ( int i = 0; i < glyph.contourCount; i++ )
		{	
			long	pts = *ep - sp + 1;													// nr pts in contour
			// contour start point
			if ( *onCurve != 0 )															// 1st point on curve
			{
				ptStart.m_x = RoundFixed( *x );
				ptStart.m_y = -RoundFixed( *y ); 
				x++;
				y++;
				onCurve++;
				pts--;
			}
			else if ( *((*glyph.onCurve) + *ep) != 0 )							// use end point
			{
				ptStart.m_x = RoundFixed( *((*glyph.x) + *ep) );
				ptStart.m_y = -RoundFixed( *((*glyph.y) + *ep) ); 
			}
			else																				// compute midpoint between 1st and last curve points
			{	
				Fixed	x2 = ::FixDiv( (*x + *((*glyph.x) + *ep)), ::Long2Fix( 2 ) );
				Fixed	y2 = ::FixDiv( (*y + *((*glyph.y) + *ep)), ::Long2Fix( 2 ) );
				ptStart.m_x = RoundFixed( x2 );
				ptStart.m_y = -RoundFixed( y2 );
			}
			// initial move to
			pSegments->opCode = MOVE_TO;
			pSegments->pt1 = ptStart;
			nrSegments++;
			pSegments++;
			// load segments of contour
			while ( pts-- > 0 )
			{	
				Fixed	x0 = *x;
				Fixed	y0 = *y;
				Byte	onCurve0 = *onCurve;
				x++;
				y++;
				onCurve++;
				pSegments->pt1.m_x = RoundFixed( x0 );
				pSegments->pt1.m_y = -RoundFixed( y0 );
				if ( onCurve0 != 0 )
					pSegments->opCode = LINE_TO;
				else if ( pts < 1 )														// quadratic w/ contour start point as end
				{
					pSegments->opCode = QUADRATIC_TO;
					pSegments->pt2 = ptStart;
				}
				else if ( *onCurve != 0 )												// quadratic w/ end point next line to
				{
					pSegments->opCode = QUADRATIC_TO;
					pSegments->pt2.m_x = RoundFixed( *x );
					pSegments->pt2.m_y = -RoundFixed( *y );
					x++;
					y++;
					onCurve++;
					pts--;
				}
				else 																			// compute end point of quadratic as midpoint to next curve
				{
					Fixed	x2 = ::FixDiv( (x0 + *x), ::Long2Fix( 2 ) );
					Fixed	y2 = ::FixDiv( (y0 + *y), ::Long2Fix( 2 ) );
					pSegments->opCode = QUADRATIC_TO;
					pSegments->pt2.m_x = RoundFixed( x2 );
					pSegments->pt2.m_y = -RoundFixed( y2 );
				}
				nrSegments++;
				pSegments++;
			}
			pSegments->opCode = CLOSE_PATH;											// end of contour
			pSegments->pt1.m_x = pSegments->pt2.m_x = 0;
			pSegments->pt1.m_y = pSegments->pt2.m_y = 0;
			nrSegments++;
			pSegments++;
			sp = *ep++ + 1;
		}
		pSegments->opCode = 0;															// end of glyph
		pSegments->pt1.m_x = pSegments->pt2.m_x = 0;
		pSegments->pt1.m_y = pSegments->pt2.m_y = 0;
		*(uLONG *)cookie = nrSegments;
	}
	UnlockGlyphOutline( &glyph );

	// cleanup
	::HPurge( m_hSfnt );
	KillGlyphOutline( &glyph );

	return TRUE;
}