40 #include "../../Matrix/Matrix.h"    41 #include "../../Matrix/MatrixTools.h"    42 #include "../../VectorTools.h"    53   const vector<double>& rowW,
    54   const vector<double>& colW,
    68     center(tmpData, rowW);
    77   setData(tmpData, rowW, colW, nbAxes, tol, verbose);
    93   size_t nRow = data.getNumberOfRows();
    94   size_t nCol = data.getNumberOfColumns();
    96   vector<double> rowW(nRow);
    97   vector<double> colW(nCol);
   106     center(tmpData, rowW);
   112     scale(tmpData, rowW);
   115   setData(tmpData, rowW, colW, nbAxes, tol, verbose);
   122   size_t nRow = matrix.getNumberOfRows();
   123   size_t nCol = matrix.getNumberOfColumns();
   124   if (nRow != rowW.size())
   125     throw Exception(
"PrincipalComponentAnalysis::center. The number of row weigths have to be equal to the number of rows!");
   129   vector<double> columnMeans(nCol);
   130   for (
unsigned int i = 0; i < nCol; i++)
   133     for (
unsigned int j = 0; j < nRow; j++)
   135       tmp += matrix(j, i) * rowW[j];
   137     columnMeans[i] = tmp / sumRowWeights;
   140   for (
unsigned int i = 0; i < nCol; i++)
   142     for (
unsigned int j = 0; j < nRow; j++)
   144       matrix(j, i) -= columnMeans[i];
   153   size_t nRow = matrix.getNumberOfRows();
   154   size_t nCol = matrix.getNumberOfColumns();
   155   if (nRow != rowW.size())
   156     throw Exception(
"PrincipalComponentAnalysis::scale. The number of row weigths have to be equal to the number of rows!");
   160   vector<double> columnSd(nCol);
   161   for (
size_t i = 0; i < nCol; i++)
   164     for (
unsigned int j = 0; j < nRow; j++)
   166       tmp += pow(matrix(j, i), 2) * rowW[j];
   168     columnSd[i] = sqrt(tmp / sumRowWeights);
   171   for (
size_t i = 0; i < nCol; i++)
   173     for (
unsigned int j = 0; j < nRow; j++)
   175       if (columnSd[i] == 0.)
   178         matrix(j, i) /= columnSd[i];
 The matrix template interface. 
 
PrincipalComponentAnalysis(const Matrix< double > &data, unsigned int nbAxes, const std::vector< double > &rowW, const std::vector< double > &colW, bool centered=true, bool scaled=true, double tol=0.0000001, bool verbose=true)
Build a new PrincipalComponentAnalysis object. 
 
This class allows to perform a correspondence analysis. 
 
static void scale(Matrix< double > &matrix, const std::vector< double > &rowW)
This function allows to center an input matrix from its column means. 
 
static void center(Matrix< double > &matrix, const std::vector< double > &rowW)
This function allows to center an input matrix from its column means. 
 
The core class of a multivariate analysis.