OpendTect  7.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PCA Class Reference

Performs Pricipal Component Analysis on samples with N variables. More...

Public Member Functions

 PCA (int nrvars)
 
virtual ~PCA ()
 
template<class IDXABL >
void addSample (const IDXABL &sample)
 
bool calculate ()
 
void clearAllSamples ()
 
float getEigenValue (int idx) const
 
template<class IDXABL >
void getEigenVector (int idx, IDXABL &vec) const
 

Protected Member Functions

bool tqli (float[], float[], int, ObjectSet< float > &)
 
void tred2 (ObjectSet< float > &, int, float[], float[])
 

Protected Attributes

Array2DImpl< float > covariancematrix_
 
float * eigenvalues_
 
int * eigenvecindexes_
 
const int nrvars_
 
ObjectSet< TypeSet< float > > samples_
 
TypeSet< float > samplesums_
 
ObjectSet< SequentialTasktasks_
 
TypeSet< Threads::Workworkload_
 

Detailed Description

Performs Pricipal Component Analysis on samples with N variables.

Example of usage:

//The samples will have three variables
PCA pca( 3 );
//Samples can be added by any object that has a readable [] operator
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();
//Any object that has a writable [] operator can be used to fetch
//the resulting vectors:
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 );
Performs Pricipal Component Analysis on samples with N variables.
Definition: pca.h:68

<>

Constructor & Destructor Documentation

◆ PCA()

PCA::PCA ( int  nrvars)
Parameters
nrvarsThe number of variables that the samples have.

◆ ~PCA()

virtual PCA::~PCA ( )
virtual

Member Function Documentation

◆ addSample()

template<class IDXABL >
void PCA::addSample ( const IDXABL &  sample)
inline

Adds a sample to the analysis.

Parameters
sampleThe sample that should be added. The sample can be of any type that have [] operators.

◆ calculate()

bool PCA::calculate ( )

Computes the pca for all added samples.

◆ clearAllSamples()

void PCA::clearAllSamples ( )

Removes all samples so a new analysis can be made (by adding new samples)

◆ getEigenValue()

float PCA::getEigenValue ( int  idx) const
Returns
an eigenvalue.
Parameters
idxDetermines which eigenvalue to return. The eigenvalues are sorted in descending order, so idx==0 gives the largest eigenvalue.

◆ getEigenVector()

template<class IDXABL >
void PCA::getEigenVector ( int  idx,
IDXABL &  vec 
) const
inline

Returns the eigenvector corresponding to the eigenvalue idx.

Parameters
idxDetermines which eigenvector to return. The eigenvectors are sorted in order of descending eigenvalue, so idx==0 gives the eigenvector corresponding to the largest eigenvalue.
vecThe object where the to store the eigenvector. Any object that has a writable [] operator can be used, for example float* and TypeSet<T>.

◆ tqli()

bool PCA::tqli ( float  [],
float  [],
int  ,
ObjectSet< float > &   
)
protected

◆ tred2()

void PCA::tred2 ( ObjectSet< float > &  ,
int  ,
float  [],
float  [] 
)
protected

Member Data Documentation

◆ covariancematrix_

Array2DImpl<float> PCA::covariancematrix_
protected

◆ eigenvalues_

float* PCA::eigenvalues_
protected

The negation of the eigenval, to get the sorting right.

◆ eigenvecindexes_

int* PCA::eigenvecindexes_
protected

◆ nrvars_

const int PCA::nrvars_
protected

◆ samples_

ObjectSet<TypeSet<float> > PCA::samples_
protected

◆ samplesums_

TypeSet<float> PCA::samplesums_
protected

◆ tasks_

ObjectSet<SequentialTask> PCA::tasks_
protected

◆ workload_

TypeSet<Threads::Work> PCA::workload_
protected

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2024