PCA降维

时间:2021-12-29 18:55:05

http://blog.csdn.net/a784763307/article/details/17289317

这篇比较棒


openCV版

void PrintMatrix(CvMat *Matrix,int Rows,int Cols)
{
for(int i=;i<Rows;i++)
{
for(int j=;j<Cols;j++)
{
printf("%.2f ",cvGet2D(Matrix,i,j).val[]);
}
printf("\n");
}
}
int main()
{
float Coordinates[]={1.5,2.3,
3.0,1.7,
1.2,2.9,
2.1,2.2,
3.1,3.1,
1.3,2.7,
2.0,1.7,
1.0,2.0,
0.5,0.6,
1.0,0.9};
CvMat *Vector1;
CvMat *AvgVector;
CvMat *EigenValue_Row;
CvMat *EigenVector; Vector1=cvCreateMat(,,CV_32FC1);
cvSetData(Vector1,Coordinates,Vector1->step);
AvgVector=cvCreateMat(,,CV_32FC1);
EigenValue_Row=cvCreateMat(,,CV_32FC1);
EigenVector=cvCreateMat(,,CV_32FC1); cvCalcPCA(Vector1,AvgVector,EigenValue_Row,EigenVector,CV_PCA_DATA_AS_ROW); printf("Original Data:\n");
PrintMatrix(Vector1,,); printf("==========\n");
PrintMatrix(AvgVector,,); printf("\nEigne Value:\n");
PrintMatrix(EigenValue_Row,,); printf("\nEigne Vector:\n"); //每一行是一个特征向量。
PrintMatrix(EigenVector,,);
cout<<"******************************"<<endl; system("pause");
return ; }