#ifndef _Eigen_h_
#define _Eigen_h_
/* David Weenink, 19991006 */

#ifndef _Data_h_
	#include "Data.h"
#endif
#ifndef _Graphics_h_
	#include "Graphics.h"
#endif

#define Eigen_members Data_members \
	long numberOfEigenvalues, dimension;	\
	double *eigenvalues;	\
	double **eigenvectors; /* eigenvectors stored in row */
#define Eigen_methods Data_methods
class_create (Eigen, Data)

int Eigen_init (I, long numberOfEigenvalues, long dimension);

int Eigen_initFromSymmetricMatrix (I, double **a, long n);

int Eigen_initFromSquareRoot (I, double **a, long numberOfRows,
	long numberOfColumns);
/*
	Calculate eigenstructure for symmetric matrix A'A (e.g. covariance matrix),
	when only A is given.
	Precondition: numberOfRows > 1
	Method: SVD.
*/

int Eigen_initFromSquareRootPair (I, double **a, long numberOfRows,
	long numberOfColumns, double **b, long numberOfRows_b);
/*
	Calculate eigenstructure for A'Ax - lambda B'Bx = 0
	Preconditions: numberOfRows >= numberOfColumns &&
		numberOfRows_b >= numberOfColumns
	Method: Generalized SVD.
*/

Eigen Eigen_create (long numberOfEigenvalues, long dimension);

long Eigen_getNumberOfEigenvectors (I);

long Eigen_getDimensionOfComponents (I);

double Eigen_getCumulativeContributionOfComponents (I, long from, long to);

long Eigen_getDimensionOfFraction (I, double fraction);

double Eigen_getSumOfEigenvalues (I);

void Eigen_sort (I);
/*
	Sort eigenvalues and corresponding eigenvectors in decreasing order.
*/

void Eigen_invertEigenvector (I, long ivec);

void Eigen_drawEigenvalues_scree (I, Graphics g, long first, long last, double minimum,
	double maximum, double size_mm, const char *mark, int garnish);
	
void Eigen_drawEigenvector (I, Graphics g, long ivec, long first, long last,
	double minimum, double maximum, int weigh, double size_mm, const char *mark,
	int connect, int garnish);

#endif /* _Eigen_h_ */

/* End of file Eigen.h */
