资源简介
C语言实现的主成分分析法,PCA算法用于各个领域妥妥的
代码片段和文件信息
C*********************** Contents ****************************************
C* Principal Components Analysis: C 638 lines. ****************************
C* Sample input data set (final 36 lines). *********************************
C***************************************************************************
/*********************************/
/* Principal Components Analysis */
/*********************************/
/*********************************************************************/
/* Principal Components Analysis or the Karhunen-Loeve expansion is a
classical method for dimensionality reduction or exploratory data
analysis. One reference among many is: F. Murtagh and A. Heck
Multivariate Data Analysis Kluwer Academic Dordrecht 1987.
Author:
F. Murtagh
Phone: + 49 89 32006298 (work)
+ 49 89 965307 (home)
Earn/Bitnet: fionn@dgaeso51 fim@dgaipp1s murtagh@stsci
Span: esomc1::fionn
Internet: murtagh@scivax.stsci.edu
F. Murtagh Munich 6 June 1989 */
/*********************************************************************/
#include
#include
#include
#define SIGN(a b) ( (b) < 0 ? -fabs(a) : fabs(a) )
main(argc argv)
int argc;
char *argv[];
{
FILE *stream;
int n m i j k k2;
float **data **matrix() **symmat **symmat2 *vector() *evals *interm;
void free_matrix() free_vector() corcol() covcol() scpcol();
void tred2() tqli();
float in_value;
char option *strncpy();
/*********************************************************************
Get from command line:
input data file name #rows #cols option.
Open input file: fopen opens the file whose name is stored in the
pointer argv[argc-1]; if unsuccessful error message is printed to
stderr.
*********************************************************************/
if (argc != 5)
{
printf(“Syntax help: PCA filename #rows #cols option\n\n“);
printf(“(filename -- give full path name\n“);
printf(“ #rows \n“);
printf(“ #cols -- integer values\n“);
printf(“ option -- R (recommended) for correlation analysis\n“);
printf(“ V for variance/covariance analysis\n“);
printf(“ S for SSCP analysis.)\n“);
exit(1);
}
n = atoi(argv[2]); /* # rows */
m = atoi(argv[3]); /* # columns */
strncpy(&optionargv[4]1); /* Analysis option */
printf(“No. of rows: %d no. of columns: %d.\n“nm);
printf(“Input file: %s.\n“argv[1]);
if ((stream = fopen(argv[1]“r“)) == NULL)
{
fprintf(stderr “Program %s : cannot open file %s\n“
argv[0] argv[1]);
fprintf(stderr “Exiting to system.“);
exit(1);
/* Note: in versions of DOS prior to
- 上一篇:多项式秦九韶算法实现
- 下一篇:2019年华南师范大学计算机学院复试笔试回忆.md
评论
共有 条评论