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

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