OpendTect  6.3
pca.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Kristofer Tingdahl
8  Date: 4-11-2002
9 ________________________________________________________________________
10 
11 
12 -*/
13 
14 #include "algomod.h"
15 #include "arrayndimpl.h"
16 #include "sets.h"
17 #include "trigonometry.h"
18 #include "threadwork.h"
19 
20 template <class T> class Array2D;
21 class SequentialTask;
22 class PCACovarianceCalculator;
23 
71 {
72 public:
73  PCA( int nrvars );
77  virtual ~PCA();
78 
79  void clearAllSamples();
83  template <class IDXABL> void addSample( const IDXABL& sample );
90  bool calculate();
93  float getEigenValue(int idx) const;
100  template <class IDXABL> void getEigenVector(int idx,
101  IDXABL& vec) const;
119 protected:
120  bool tqli( float[], float[], int, ObjectSet<float>&);
121  void tred2( ObjectSet<float>&, int, float[],float[]);
122 
123  const int nrvars_;
129  float* eigenvalues_;
134 };
135 
136 
137 template <class IDXABL> inline
138 void PCA::addSample( const IDXABL& sample )
139 {
140  TypeSet<float>& ownsample = *new TypeSet<float>;
141  for ( int idx=0; idx<nrvars_; idx++ )
142  {
143  const float val = (float) sample[idx];
144  ownsample += val;
145  samplesums_[idx] += val;
146  }
147 
148  samples_ += &ownsample;
149 }
150 
151 template <class IDXABL> inline
152 void PCA::getEigenVector(int idy, IDXABL& vec ) const
153 {
154  for ( int idx=0; idx<nrvars_; idx++ )
155  vec[idx] = covariancematrix_.get(idx, eigenvecindexes_[idy] );
156 }
#define mExpClass(module)
Definition: commondefs.h:157
const int nrvars_
Definition: pca.h:123
TypeSet< Threads::Work > workload_
Definition: pca.h:127
T get(int, int) const
Definition: arrayndimpl.h:469
Performs Pricipal Component Analysis on samples with N variables.
Definition: pca.h:70
The generalization of something (e.g. a computation) where the steps must be done in sequence...
Definition: task.h:147
Array2D ( Subclass of ArrayND ) is a two dimensional array.
Definition: arraynd.h:127
Array2DImpl< float > covariancematrix_
Definition: pca.h:124
int * eigenvecindexes_
Definition: pca.h:133
TypeSet< float > samplesums_
Definition: pca.h:126
ObjectSet< SequentialTask > tasks_
Definition: pca.h:128
void addSample(const IDXABL &sample)
Definition: pca.h:138
ObjectSet< TypeSet< float > > samples_
Definition: pca.h:125
float * eigenvalues_
Definition: pca.h:129
void getEigenVector(int idx, IDXABL &vec) const
Definition: pca.h:152

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