Performs Pricipal Component Analysis on samples with N variables.
More...
List of all members.
Detailed Description
Performs Pricipal Component Analysis on samples with N variables.
Example of usage:
PCA pca( 3 );
const float sample0[] = { 0, 1, 2 };
pca.addSample( sample0 );
const float sample1[] = { 4.343, 9.8, 2.72 };
pca.addSample( sample1 );
const float sample2[] = { 23.15, 210, -15 };
pca.addSample( sample2 );
const float sample3[] = { -0.36, 0.68, 3 };
pca.addSample( sample3 );
const float sample4[] = { 4.4, 9,6, 11 };
pca.addSample( sample4 );
TypeSet<float> sample5; sample5 += 34.1; sample5 += 8.37; sample5 += -44;
pca.addSample( sample5 );
pca.calculate();
TypeSet<float> eigenvec0(3,0);
float eigenval0 = pca.getEigenValue(0);
pca.getEigenVector( 0, eigenvec0 );
float[3] eigenvec1;
float eigenval1 = pca.getEigenValue(1);
pca.getEigenVector( 1, eigenvec1 );
float[3] eigenvec2;
float eigenval2 = pca.getEigenValue(2);
pca.getEigenVector( 2, eigenvec2 );
Constructor & Destructor Documentation
- Parameters:
-
| nrvars | The number of variables that the samples have. |
| virtual PCA::~PCA |
( |
|
) |
[virtual] |
Member Function Documentation
template<class IDXABL >
| void PCA::addSample |
( |
const IDXABL & |
sample |
) |
[inline] |
Adds a sample to the analysis.
- Parameters:
-
| sample | The sample that should be added. The sample can be of any type that have [] operators. |
Computes the pca for all added samples.
| void PCA::clearAllSamples |
( |
|
) |
|
Removes all samples so a new analysis can be made (by adding new samples)
| float PCA::getEigenValue |
( |
int |
idx |
) |
const |
- Returns:
- an eigenvalue.
- Parameters:
-
| idx | Determines which eigenvalue to return. The eigenvalues are sorted in descending order, so idx==0 gives the largest eigenvalue. |
template<class IDXABL >
| void PCA::getEigenVector |
( |
int |
idx, |
|
|
IDXABL & |
vec | |
|
) |
| | const [inline] |
Returns the eigenvector corresponding to the eigenvalue idx.
- Parameters:
-
| idx | Determines which eigenvector to return. The eigenvectors are sorted in order of descending eigenvalue, so idx==0 gives the eigenvector corresponding to the largest eigenvalue. |
| vec | The object where the to store the eigenvector. Any object that has a writable [] operator can be used, for example float* and TypeSet<T>. |
Enables multi-threaded calculation, which is beneficial when the number of samples and/or number of variables are large. The object does however work without setting the threadworkmanager.
- Note:
- threadworkmanager is managed (i.e. deleted) by caller, and it can be shared with many other objects (such as other PCAs).
| bool PCA::tqli |
( |
float |
[], |
|
|
float |
[], |
|
|
int |
, |
|
|
ObjectSet< float > & |
| |
|
) |
| | [protected] |
| void PCA::tred2 |
( |
ObjectSet< float > & |
, |
|
|
int |
, |
|
|
float |
[], |
|
|
float |
[] | |
|
) |
| | [protected] |
Member Data Documentation
The negation of the eigenval, to get the sorting right.