Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <pca.h>

Collaboration diagram for Running_PCA:
Collaboration graph
[legend]

Public Member Functions

 Running_PCA (int _J, int _d)
 
void project (const Matrix1D< double > &input, Matrix1D< double > &output) const
 
void get_eigenvector (int j, Matrix1D< double > &result) const
 Get a certain eigenvector. More...
 
double get_eigenvector_variance (int j) const
 Get the variance associated to a certain eigenvector. More...
 

Public Attributes

int J
 Total number of eigenvectors to be computed. More...
 
int d
 Dimension of the sample vectors. More...
 
Matrix1D< double > current_sample_mean
 Current estimate of the population mean. More...
 
long n
 Current number of samples seen. More...
 
Matrix2D< double > eigenvectors
 
Matrix1D< double > sum_all_samples
 
Matrix1D< double > sum_proj
 
Matrix1D< double > sum_proj2
 

Detailed Description

Running PCA. Running PCA is an algorithm that estimates iteratively the principal components of a dataset that is provided to the algorithm as vectors are available.

See J. Weng, Y. Zhang, W.S. Hwang. Candid covariance-free incremental principal component analysis. IEEE Trans. On Pattern Analysis and Machine Intelligence, 25(8): 1034-1040 (2003).

Definition at line 227 of file pca.h.

Constructor & Destructor Documentation

◆ Running_PCA()

Running_PCA::Running_PCA ( int  _J,
int  _d 
)

Constructor. J is the number of eigenvectors to compute. d is the dimension of the sample vectors.

Definition at line 462 of file pca.cpp.

463 {
464  J = _J;
465  d = _d;
466  n = 0;
472 }
long n
Current number of samples seen.
Definition: pca.h:240
Matrix1D< double > sum_all_samples
Definition: pca.h:275
int J
Total number of eigenvectors to be computed.
Definition: pca.h:231
Matrix1D< double > sum_proj
Definition: pca.h:278
Matrix2D< double > eigenvectors
Definition: pca.h:244
void initZeros()
Definition: matrix1d.h:592
Matrix1D< double > sum_proj2
Definition: pca.h:281
void initZeros()
Definition: matrix2d.h:626
int d
Dimension of the sample vectors.
Definition: pca.h:234
Matrix1D< double > current_sample_mean
Current estimate of the population mean.
Definition: pca.h:237

Member Function Documentation

◆ get_eigenvector()

void Running_PCA::get_eigenvector ( int  j,
Matrix1D< double > &  result 
) const
inline

Get a certain eigenvector.

Definition at line 260 of file pca.h.

261  {
262  eigenvectors.getCol(j, result);
263  }
Matrix2D< double > eigenvectors
Definition: pca.h:244
#define j
void getCol(size_t j, Matrix1D< T > &v) const
Definition: matrix2d.cpp:890

◆ get_eigenvector_variance()

double Running_PCA::get_eigenvector_variance ( int  j) const
inline

Get the variance associated to a certain eigenvector.

Definition at line 266 of file pca.h.

267  {
268  if (n <= j)
269  return 0.0;
270  double mean_proj = sum_proj(j) / n;
271  return sum_proj2(j) / n - mean_proj*mean_proj;
272  }
long n
Current number of samples seen.
Definition: pca.h:240
Matrix1D< double > sum_proj
Definition: pca.h:278
#define j
Matrix1D< double > sum_proj2
Definition: pca.h:281

◆ project()

void Running_PCA::project ( const Matrix1D< double > &  input,
Matrix1D< double > &  output 
) const

Project a sample vector on the PCA space.

Definition at line 548 of file pca.cpp.

550 {
551  output.initZeros(J);
552  for (int j = 0; j < J; j++)
553  for (int i = 0; i < d; i++)
554  output(j) += (input(i) - current_sample_mean(i)) * eigenvectors(i, j);
555 }
int J
Total number of eigenvectors to be computed.
Definition: pca.h:231
#define i
Matrix2D< double > eigenvectors
Definition: pca.h:244
void initZeros()
Definition: matrix1d.h:592
#define j
int d
Dimension of the sample vectors.
Definition: pca.h:234
Matrix1D< double > current_sample_mean
Current estimate of the population mean.
Definition: pca.h:237

Member Data Documentation

◆ current_sample_mean

Matrix1D<double> Running_PCA::current_sample_mean

Current estimate of the population mean.

Definition at line 237 of file pca.h.

◆ d

int Running_PCA::d

Dimension of the sample vectors.

Definition at line 234 of file pca.h.

◆ eigenvectors

Matrix2D<double> Running_PCA::eigenvectors

Current estimate of the eigenvectors. Each column is an eigenvector.

Definition at line 244 of file pca.h.

◆ J

int Running_PCA::J

Total number of eigenvectors to be computed.

Definition at line 231 of file pca.h.

◆ n

long Running_PCA::n

Current number of samples seen.

Definition at line 240 of file pca.h.

◆ sum_all_samples

Matrix1D<double> Running_PCA::sum_all_samples

Definition at line 275 of file pca.h.

◆ sum_proj

Matrix1D<double> Running_PCA::sum_proj

Definition at line 278 of file pca.h.

◆ sum_proj2

Matrix1D<double> Running_PCA::sum_proj2

Definition at line 281 of file pca.h.


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