The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information.... CalcPrincComp

 Unit: SDL_math2 Class: none Declaration:  function CalcPrincComp (InData: TMatrix; LoC, HiC: integer; LoR, HiR: integer; Scaling: integer): boolean;  function CalcPrincComp (InData: TMatrix; LoC, HiC: integer; LoR, HiR: integer; Scaling: integer; NormalizeEV: boolean): boolean;

The procedure CalcPrincComp calculates the principal components (Principal Component Analysis, PCA) of the matrix Indata . The rows of the data matrix are objects, the columns are variables. The resulting principal components can be read using the routine GetEigenResult. In version  of the method, all eigenvalues are scaled to their sum equal to 1.0, in version  the user has the choice not to normalize the eigenvalues by setting the parameter NormalizeEV to FALSE. In this case, the unchanged eigenvalues are available. The eigenvectors are arranged according to decreasing eigenvalues, thus the first eigenvector corresponds to the first principal component.

The function CalcPrincComp allocates some memory for the storage of the covariance and the eigenvector matrix. The memory for the eigenvector matrix is not deallocated after finishing CalcPrincComp and must be deallocated explicitly by calling the routine RemoveEigenMatrix. If CalcPrincComp is called several times the old eigenvector matrix is released and a new one is allocated.

The parameters LoC, HiC, LoR, and HiR specify the area of the matrix which is used for the principal component analysis. This facilitates the calculation of the principal components of only parts of the input data. Usually, the PCA is applied to all the available data (LoC =1, HiC =InData.NrOfColumns, LoR =1, and HiR =InData.NrOfRows).

The parameter Scaling determines, whether the data should be before calculating the principal components:

 Scaling Result 0 PCA is based on scatter matrix of InData 1 PCA is based on covariance matrix of InData 2 PCA is based on correlation matrix of InData

The function CalcPrincComp returns a TRUE value, if the PCA has been completed successfully. If FALSE is returned, the calculation has been aborted (mostly due to lack of memory).

CalcPrincComp increments the global variable ProcStat and calls the feedback routine MathFeedBackProc in order to allow feedback to the user during time consuming calculations.

 Example: This procedure is used in the following example program (see http://www.lohninger.com/examples.html for downloading the code): simplepca

Last Update: 2012-Oct-20