Example #1
0
/*
  test: main function
*/
int main()
{
	double data[20] = { 2, 3, 8, 2, 3,
		7, 9, 29, 3, 5,
					   3, 8, 22, 12, 1,
					   3, 12, 12, 33, 2};
	int row = 4, col = 5;
	double signals[20], PC[16], V[4];
	int x, y;
	
	pca1( data, row, col, signals, PC, V );
	
	printf( "Project to Principal Component: \n" );
	for ( y = 0; y < row; y++ )
	{
		for ( x = 0; x < col; x++ )
		{
			printf( "%7.4f ", signals[y*col+x] );
		}
		printf( "\n" );
	}
	printf( "Eigen Values (in deceasing order): \n" );
	for ( y = 0; y < row; y++ )
		printf( "%7.4f ", V[y] );
	printf( "\n" );
	printf( "Eigen Vectors: \n" );
	for ( y = 0; y < row; y++ )
	{
		for ( x = 0; x < row; x++ )
		{
			printf( "%7.4f ", PC[y*row+x] );
		}
		printf( "\n" );
	}
	
	return( 1 );
}
Example #2
0
NeuronTree align_axis(NeuronTree input)
{
	NeuronTree result = input;
	V3DLONG siz = input.listNeuron.size();
	printf("size=%d\n", siz);
	
	double * coord = new double[siz * 3];
	for (V3DLONG i=0; i<siz; i++)
	{
		coord[i] = input.listNeuron[i].x;
		coord[siz + i] = input.listNeuron[i].y;
		coord[2*siz + i] = input.listNeuron[i].z;
	}


	double * coord_pca = new double[siz * 3];
	double * PC = new double[siz];
	double V[3];

	pca1(coord, 3, siz, coord_pca, PC, V);

	printf("PCA done\n");

	for (V3DLONG i=0;i<siz; i++)
	{
		result.listNeuron[i].x = coord_pca[i];
		result.listNeuron[i].y = coord_pca[siz + i];
		result.listNeuron[i].z = coord_pca[2*siz + i];
	}

	delete []coord;
	delete []coord_pca;
	delete []PC;
	
	return result;
}