pca

Functions

int main(int argc, char *argv[])

pca [ option ] [ infile ]

  • -l int

    • length of vector \((1 \le L)\)

  • -m int

    • order of vector \((0 \le M)\)

  • -n int

    • number of principal components \((1 \le N \le L)\)

  • -i int

    • number of iterations \((1 \le I)\)

  • -d double

    • convergence threshold \((0 \le \epsilon)\)

  • -u int

    • covariance type

      • 0 sample covariance

      • 1 unbiased covariance

      • 2 correlation

  • -v str

    • double-type eigenvalues and proportions

  • infile str

    • double-type vector sequence

  • stdout

    • double-type mean vector and eigenvectors

In the below example, principal component analysis is applied to the three-dimensional training vectors contained in data.d. The eigenvectors and the eigenvalues are written to eigvec.dat and eigval.dat, repectively.

pca -l 3 -n 2 -v eigval.dat < data.d > eigvec.dat

The eigenvalues are sorted in descending order.

Parameters:
  • argc[in] Number of arguments.

  • argv[in] Argument vector.

Returns:

0 on success, 1 on failure.

See also

pcas

class PrincipalComponentAnalysis

Perform principal component analysis.

The input is the \(M\)-th order vectors:

\[ \begin{array}{cccc} \boldsymbol{x}(0), & \boldsymbol{x}(1), & \ldots, & \boldsymbol{x}(T-1), \end{array} \]
and the outputs are the \(M\)-th order mean vector
\[ \boldsymbol{m} = \frac{1}{T} \sum_{t=0}^{T-1} \boldsymbol{x}(t), \]
the \(M\)-th order eigenvectors
\[ \begin{array}{cccc} \boldsymbol{v}(0), & \boldsymbol{v}(1), & \ldots, & \boldsymbol{v}(M), \end{array} \]
and the corresponding eigenvalues:
\[ \begin{array}{cccc} \lambda(0), & \lambda(1), & \ldots, & \lambda(M). \end{array} \]
The eigenvalue problem is solved by the Jacobi iterative method.

Public Types

enum CovarianceType

Type of covariance.

Values:

enumerator kSampleCovariance
enumerator kUnbiasedCovariance
enumerator kCorrelation
enumerator kNumCovarianceTypes

Public Functions

PrincipalComponentAnalysis(int num_order, int num_iteration, double convergence_threshold, CovarianceType covariance_type)
Parameters:
  • num_order[in] Order of vector, \(M\).

  • num_iteration[in] Number of iterations.

  • convergence_threshold[in] Convergence threshold.

  • covariance_type[in] Type of covariance.

inline int GetNumOrder() const
Returns:

Order of vector.

inline int GetNumIteration() const
Returns:

Number of iterations.

inline double GetConvergenceThreshold() const
Returns:

Convergence threshold.

inline CovarianceType GetCovarianceType() const
Returns:

Type of covariance.

inline bool IsValid() const
Returns:

True if this object is valid.

bool Run(const std::vector<std::vector<double>> &input_vectors, std::vector<double> *mean_vector, std::vector<double> *eigenvalues, Matrix *eigenvectors, PrincipalComponentAnalysis::Buffer *buffer) const
Parameters:
  • input_vectors[in] \(M\)-th order input vectors. The shape is \([T, M+1]\).

  • mean_vector[out] \(M\)-th order mean vector.

  • eigenvalues[out] \(M+1\) eigenvalues.

  • eigenvectors[out] \(M\)-th order eigenvectors. The shape is \([M+1, M+1]\).

  • buffer[out] Buffer.

Returns:

True on success, false on failure.

class Buffer

Buffer for PrincipalComponentAnalysis class.