首页 > 代码库 > PCA降维

PCA降维

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

这篇比较棒


openCV版

void PrintMatrix(CvMat *Matrix,int Rows,int Cols)  {      for(int i=0;i<Rows;i++)      {          for(int j=0;j<Cols;j++)          {              printf("%.2f ",cvGet2D(Matrix,i,j).val[0]);          }          printf("\n");      }  }  int main(){    float Coordinates[20]={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(10,2,CV_32FC1);      cvSetData(Vector1,Coordinates,Vector1->step);      AvgVector=cvCreateMat(1,2,CV_32FC1);      EigenValue_Row=cvCreateMat(2,1,CV_32FC1);      EigenVector=cvCreateMat(2,2,CV_32FC1);        cvCalcPCA(Vector1,AvgVector,EigenValue_Row,EigenVector,CV_PCA_DATA_AS_ROW);        printf("Original Data:\n");      PrintMatrix(Vector1,10,2);        printf("==========\n");      PrintMatrix(AvgVector,1,2);        printf("\nEigne Value:\n");      PrintMatrix(EigenValue_Row,2,1);        printf("\nEigne Vector:\n");   //每一行是一个特征向量。    PrintMatrix(EigenVector,2,2);    cout<<"******************************"<<endl;system("pause");return 0;}

 

PCA降维