bpp-core3  3.0.0
bpp::PrincipalComponentAnalysis Class Reference

This class allows to perform a principal component analysis. More...

#include <Bpp/Numeric/Stat/Mva/PrincipalComponentAnalysis.h>

+ Inheritance diagram for bpp::PrincipalComponentAnalysis:
+ Collaboration diagram for bpp::PrincipalComponentAnalysis:

Public Member Functions

 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. More...
 
 PrincipalComponentAnalysis (const Matrix< double > &data, unsigned int nbAxes, bool centered=true, bool scaled=true, double tol=0.0000001, bool verbose=true)
 Build a new PrincipalComponentAnalysis object and specify default row and column weights. More...
 
virtual ~PrincipalComponentAnalysis ()
 
PrincipalComponentAnalysisclone () const
 Create a copy of this object and send a pointer to it. More...
 
const std::vector< double > & getColumnMeans () const
 
const std::vector< double > & getColumnSd () const
 
void setData (const Matrix< double > &matrix, const std::vector< double > &rowWeights, const std::vector< double > &colWeights, unsigned int nbAxes, double tol=0.0000001, bool verbose=true)
 Set the data and perform computations. More...
 
std::vector< double > computeVariancePercentagePerAxis ()
 
size_t getNbOfKeptAxes () const
 
const std::vector< double > getRowWeights () const
 
const std::vector< double > getColumnWeights () const
 
const std::vector< double > & getEigenValues () const
 
const RowMatrix< double > & getRowCoordinates () const
 
const RowMatrix< double > & getColCoordinates () const
 
const RowMatrix< double > & getPrincipalAxes () const
 
const RowMatrix< double > & getPrincipalComponents () const
 

Static Public Member Functions

static void center (Matrix< double > &matrix, const std::vector< double > &rowW)
 This function allows to center an input matrix from its column means. More...
 
static void scale (Matrix< double > &matrix, const std::vector< double > &rowW)
 This function allows to center an input matrix from its column means. More...
 

Private Attributes

std::vector< double > columnMeans_
 
std::vector< double > columnSd_
 

Detailed Description

This class allows to perform a principal component analysis.

Two constructors are available. The first one allows the user to specify the row and column weights. The second one specify default weights: uniform weights unit weights are created for rows and columns respectively.

The code of this class is deeply inspired from the R code of the dudi.pca function available in the ade4 package.

Definition at line 22 of file PrincipalComponentAnalysis.h.

Constructor & Destructor Documentation

◆ PrincipalComponentAnalysis() [1/2]

PrincipalComponentAnalysis::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.

Parameters
dataThe input data (a RowMatrix) to analyse.
nbAxesThe number of kept axes during the analysis.
rowWA vector of values specifying the weights of rows.
colWA vector of values specifying the weights of columns.
centeredIf true the input matrix is centered according to the column means.
scaledIf true the input matrix is normalized according to the standard deviations of columns.
tolTolerance threshold for null eigenvalues (a value less than tol times the first one is considered as null)
verboseShould warnings be dispayed.
Exceptions
Exceptionif an error occured.

Definition at line 16 of file PrincipalComponentAnalysis.cpp.

References center(), scale(), and bpp::DualityDiagram::setData().

Referenced by clone().

◆ PrincipalComponentAnalysis() [2/2]

PrincipalComponentAnalysis::PrincipalComponentAnalysis ( const Matrix< double > &  data,
unsigned int  nbAxes,
bool  centered = true,
bool  scaled = true,
double  tol = 0.0000001,
bool  verbose = true 
)

Build a new PrincipalComponentAnalysis object and specify default row and column weights.

Parameters
dataThe input data (a RowMatrix) to analyse.
nbAxesThe number of kept axes during the analysis.
centeredIf true the input matrix is centered according to the column means.
scaledIf true the input matrix is normalized according to the standard deviations of columns.
tolTolerance threshold for null eigenvalues (a value less than tol times the first one is considered as null)
verboseShould warnings be dispayed.
Exceptions
Exceptionif an error occured.

Definition at line 48 of file PrincipalComponentAnalysis.cpp.

References center(), bpp::VectorTools::fill(), bpp::Matrix< Scalar >::getNumberOfColumns(), bpp::Matrix< Scalar >::getNumberOfRows(), scale(), and bpp::DualityDiagram::setData().

◆ ~PrincipalComponentAnalysis()

virtual bpp::PrincipalComponentAnalysis::~PrincipalComponentAnalysis ( )
inlinevirtual

Definition at line 72 of file PrincipalComponentAnalysis.h.

Member Function Documentation

◆ center()

void PrincipalComponentAnalysis::center ( Matrix< double > &  matrix,
const std::vector< double > &  rowW 
)
static

This function allows to center an input matrix from its column means.

Parameters
matrixThe input data (a Matrix) to center.
rowWA vector with row weights.

Definition at line 86 of file PrincipalComponentAnalysis.cpp.

References bpp::Matrix< Scalar >::getNumberOfColumns(), bpp::Matrix< Scalar >::getNumberOfRows(), and bpp::VectorTools::sum().

Referenced by clone(), and PrincipalComponentAnalysis().

◆ clone()

PrincipalComponentAnalysis* bpp::PrincipalComponentAnalysis::clone ( ) const
inlinevirtual

Create a copy of this object and send a pointer to it.

Returns
A pointer toward the copy object.

Reimplemented from bpp::DualityDiagram.

Definition at line 74 of file PrincipalComponentAnalysis.h.

References center(), PrincipalComponentAnalysis(), and scale().

◆ computeVariancePercentagePerAxis()

std::vector<double> bpp::DualityDiagram::computeVariancePercentagePerAxis ( )
inherited

◆ getColCoordinates()

const RowMatrix<double>& bpp::DualityDiagram::getColCoordinates ( ) const
inlineinherited

Definition at line 110 of file DualityDiagram.h.

References bpp::DualityDiagram::colCoord_.

◆ getColumnMeans()

const std::vector<double>& bpp::PrincipalComponentAnalysis::getColumnMeans ( ) const
inline

Definition at line 94 of file PrincipalComponentAnalysis.h.

References columnMeans_.

◆ getColumnSd()

const std::vector<double>& bpp::PrincipalComponentAnalysis::getColumnSd ( ) const
inline

Definition at line 95 of file PrincipalComponentAnalysis.h.

References columnSd_.

◆ getColumnWeights()

const std::vector<double> bpp::DualityDiagram::getColumnWeights ( ) const
inlineinherited

Definition at line 107 of file DualityDiagram.h.

References bpp::DualityDiagram::colWeights_.

◆ getEigenValues()

const std::vector<double>& bpp::DualityDiagram::getEigenValues ( ) const
inlineinherited

Definition at line 108 of file DualityDiagram.h.

References bpp::DualityDiagram::eigenValues_.

◆ getNbOfKeptAxes()

size_t bpp::DualityDiagram::getNbOfKeptAxes ( ) const
inlineinherited

Definition at line 105 of file DualityDiagram.h.

References bpp::DualityDiagram::nbAxes_.

◆ getPrincipalAxes()

const RowMatrix<double>& bpp::DualityDiagram::getPrincipalAxes ( ) const
inlineinherited

Definition at line 111 of file DualityDiagram.h.

References bpp::DualityDiagram::ppalAxes_.

◆ getPrincipalComponents()

const RowMatrix<double>& bpp::DualityDiagram::getPrincipalComponents ( ) const
inlineinherited

Definition at line 112 of file DualityDiagram.h.

References bpp::DualityDiagram::ppalComponents_.

◆ getRowCoordinates()

const RowMatrix<double>& bpp::DualityDiagram::getRowCoordinates ( ) const
inlineinherited

Definition at line 109 of file DualityDiagram.h.

References bpp::DualityDiagram::rowCoord_.

◆ getRowWeights()

const std::vector<double> bpp::DualityDiagram::getRowWeights ( ) const
inlineinherited

Definition at line 106 of file DualityDiagram.h.

References bpp::DualityDiagram::rowWeights_.

◆ scale()

void PrincipalComponentAnalysis::scale ( Matrix< double > &  matrix,
const std::vector< double > &  rowW 
)
static

This function allows to center an input matrix from its column means.

Parameters
matrixThe input data (a Matrix) to center.
rowWA vector with row weights.

Definition at line 117 of file PrincipalComponentAnalysis.cpp.

References bpp::Matrix< Scalar >::getNumberOfColumns(), bpp::Matrix< Scalar >::getNumberOfRows(), and bpp::VectorTools::sum().

Referenced by clone(), and PrincipalComponentAnalysis().

◆ setData()

void DualityDiagram::setData ( const Matrix< double > &  matrix,
const std::vector< double > &  rowWeights,
const std::vector< double > &  colWeights,
unsigned int  nbAxes,
double  tol = 0.0000001,
bool  verbose = true 
)
inherited

Set the data and perform computations.

Parameters
matrixThe input data to analyse.
rowWeightsA vector of values specifying the weights of rows.
colWeightsA vector of values specifying the weights of columns.
nbAxesThe number of kept axes during the analysis.
tolTolerance threshold for null eigenvalues (a value less than tol times the first one is considered as null)
verboseShould warnings be dispayed.
Exceptions
Exceptionif an error occured.

Definition at line 66 of file DualityDiagram.cpp.

References bpp::DualityDiagram::check_(), bpp::DualityDiagram::colWeights_, bpp::DualityDiagram::compute_(), bpp::DualityDiagram::nbAxes_, and bpp::DualityDiagram::rowWeights_.

Referenced by bpp::DualityDiagram::clone(), bpp::CorrespondenceAnalysis::CorrespondenceAnalysis(), and PrincipalComponentAnalysis().

Member Data Documentation

◆ columnMeans_

std::vector<double> bpp::PrincipalComponentAnalysis::columnMeans_
private

Definition at line 26 of file PrincipalComponentAnalysis.h.

Referenced by getColumnMeans().

◆ columnSd_

std::vector<double> bpp::PrincipalComponentAnalysis::columnSd_
private

Definition at line 27 of file PrincipalComponentAnalysis.h.

Referenced by getColumnSd().


The documentation for this class was generated from the following files: