OpendTect  6.3
statruncalc.h
Go to the documentation of this file.
1 #pragma once
2 /*+
3 ________________________________________________________________________
4 
5  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
6  Author: Kristofer Tingdahl (org) / Bert Bril (rev)
7  Date: 10-12-1999 / Sep 2006
8 ________________________________________________________________________
9 
10 -*/
11 
12 #include "algomod.h"
13 #include "convert.h"
14 #include "math2.h"
15 #include "stattype.h"
16 #include "sorting.h"
17 #include "typeset.h"
18 
19 #define mUndefReplacement 0
20 
23 namespace Stats
24 {
25 
36 {
37 public:
38  CalcSetup( bool weighted=false )
39  : weighted_(weighted)
40  , needextreme_(false)
41  , needsums_(false)
42  , needmed_(false)
43  , needvariance_(false)
44  , needmostfreq_(false) {}
45 
46  CalcSetup& require(Type);
47 
48  static int medianEvenHandling();
49 
50  bool isWeighted() const { return weighted_; }
51  bool needExtreme() const { return needextreme_; }
52  bool needSums() const { return needsums_; }
53  bool needMedian() const { return needmed_; }
54  bool needMostFreq() const { return needmostfreq_; }
55  bool needVariance() const { return needvariance_; }
56 
57 protected:
58 
59  template <class T>
60  friend class BaseCalc;
61  template <class T>
62  friend class RunCalc;
63  template <class T>
64  friend class WindowedCalc;
65  template <class T>
66  friend class ParallelCalc;
67 
68  bool weighted_;
70  bool needsums_;
71  bool needmed_;
74 
75 };
76 
77 
96 template <class T>
98 {
99 public:
100 
101  virtual ~BaseCalc() {}
102 
103  inline void clear();
104  const CalcSetup& setup() const { return setup_; }
105  bool isWeighted() const { return setup_.weighted_; }
106 
107  inline double getValue(Type) const;
108  inline int getIndex(Type) const;
109 
110  inline bool hasUndefs() const { return nrused_ != nradded_; }
111  inline int size( bool used=true ) const
112  { return used ? nrused_ : nradded_; }
113 
114  inline bool isEmpty() const { return size() == 0; }
115 
116  inline int count() const { return nrused_; }
117  inline double average() const;
118  inline T mostFreq() const;
119  inline T sum() const;
120  inline T min(int* index_of_min=0) const;
121  inline T max(int* index_of_max=0) const;
122  inline T extreme(int* index_of_extr=0) const;
123  inline T median(int* index_of_median=0) const;
124  inline T sqSum() const;
125  inline double rms() const;
126  inline double stdDev() const;
127  inline double normvariance() const;
128  virtual inline double variance() const;
129 
130  inline T clipVal(float ratio,bool upper) const;
132 
134 
135 protected:
136  BaseCalc( const CalcSetup& s )
137  : setup_(s) { clear(); }
138 
140 
141  int nradded_;
142  int nrused_;
143  int minidx_;
144  int maxidx_;
152 
156 
157  inline bool isZero( const T& t ) const;
158 };
159 
160 
161 template <> inline
162 bool BaseCalc<float>::isZero( const float& val ) const
163 { return mIsZero(val,1e-6); }
164 
165 
166 template <> inline
167 bool BaseCalc<double>::isZero( const double& val ) const
168 { return mIsZero(val,1e-10); }
169 
170 
171 template <class T> inline
172 bool BaseCalc<T>::isZero( const T& val ) const
173 { return !val; }
174 
175 
187 template <class T>
188 mClass(Algo) RunCalc : public BaseCalc<T>
189 {
190 public:
191  RunCalc( const CalcSetup& s )
192  : BaseCalc<T>(s) {}
193 
194  inline RunCalc<T>& addValue(T data,T weight=1);
195  inline RunCalc<T>& addValues(int sz,const T* data,const T* weights=0);
196  inline RunCalc<T>& replaceValue(T olddata,T newdata,T wt=1);
197  inline RunCalc<T>& removeValue(T data,T weight=1);
198 
199  inline RunCalc<T>& operator +=( T t ) { return addValue(t); }
200 
201  using BaseCalc<T>::medvals_;
202 
203 protected:
204 
205  inline void setMostFrequent(T val,T wt);
206 
207  using BaseCalc<T>::setup_;
208  using BaseCalc<T>::nradded_;
209  using BaseCalc<T>::nrused_;
210  using BaseCalc<T>::minidx_;
211  using BaseCalc<T>::maxidx_;
212  using BaseCalc<T>::maxval_;
213  using BaseCalc<T>::minval_;
214  using BaseCalc<T>::sum_x_;
215  using BaseCalc<T>::sum_xx_;
216  using BaseCalc<T>::sum_w_;
217  using BaseCalc<T>::sum_wx_;
218  using BaseCalc<T>::sum_wxx_;
219  using BaseCalc<T>::clss_;
220  using BaseCalc<T>::clsswt_;
221  using BaseCalc<T>::medwts_;
222 };
223 
224 
225 
233 template <class T>
235 {
236 public:
237  WindowedCalc( const CalcSetup& rcs, int sz )
238  : calc_(rcs)
239  , sz_(sz)
240  , wts_(calc_.isWeighted() ? new T [sz] : 0)
241  , vals_(new T [sz]) { clear(); }
243  { delete [] vals_; delete [] wts_; }
244  inline void clear();
245 
246  inline WindowedCalc& addValue(T data,T weight=1);
247  inline WindowedCalc& operator +=( T t ) { return addValue(t); }
248 
249  inline int getIndex(Type) const;
251  inline double getValue(Type) const;
252 
253  inline T count() const { return full_ ? sz_ : posidx_; }
254 
255 # define mRunCalc_DefEqFn(ret,fn) \
256  inline ret fn() const { return calc_.fn(); }
257  mRunCalc_DefEqFn(double, average)
259  mRunCalc_DefEqFn(double, normvariance)
262  mRunCalc_DefEqFn(double, rms)
263  mRunCalc_DefEqFn(double, stdDev)
264  mRunCalc_DefEqFn(T, mostFreq)
265 # undef mRunCalc_DefEqFn
266 
267  inline T min(int* i=0) const;
268  inline T max(int* i=0) const;
269  inline T extreme(int* i=0) const;
270  inline T median(int* i=0) const;
271 
272 protected:
273 
274  RunCalc<T> calc_; // has to be before wts_ (see constructor inits)
275  const int sz_;
276  T* wts_;
277  T* vals_;
278  int posidx_;
279  bool empty_;
280  bool full_;
281  bool needcalc_;
282 
283  inline void fillCalc(RunCalc<T>&) const;
284 };
285 
286 
287 
288 template <class T> inline
290 {
291  sum_x_ = sum_w_ = sum_xx_ = sum_wx_ = sum_wxx_ = 0;
292  nradded_ = nrused_ = minidx_ = maxidx_ = 0;
293  minval_ = maxval_ = mUdf(T);
294  clss_.erase(); clsswt_.erase(); medvals_.erase(); medwts_.erase();
295 }
296 
297 
298 template <class T> inline
300 {
301  switch ( t )
302  {
303  case Count: return count();
304  case Average: return average();
305  case Median: return median();
306  case RMS: return rms();
307  case StdDev: return stdDev();
308  case Variance: return variance();
309  case NormVariance: return normvariance();
310  case Min: return min();
311  case Max: return max();
312  case Extreme: return extreme();
313  case Sum: return sum();
314  case SqSum: return sqSum();
315  case MostFreq: return mostFreq();
316  }
317 
318  return 0;
319 }
320 
321 
322 template <class T> inline
324 {
325  int ret;
326  switch ( t )
327  {
328  case Min: (void)min( &ret ); break;
329  case Max: (void)max( &ret ); break;
330  case Extreme: (void)extreme( &ret ); break;
331  case Median: (void)median( &ret ); break;
332  default: ret = 0; break;
333  }
334  return ret;
335 }
336 
337 
338 
339 #undef mBaseCalc_ChkEmpty
340 #define mBaseCalc_ChkEmpty(typ) \
341  if ( nrused_ < 1 ) return mUdf(typ);
342 
343 template <class T>
344 inline double BaseCalc<T>::stdDev() const
345 {
346  mBaseCalc_ChkEmpty(double);
347 
348  double v = variance();
349  return v > 0 ? Math::Sqrt( v ) : 0;
350 }
351 
352 
353 template <class T>
354 inline double BaseCalc<T>::average() const
355 {
356  mBaseCalc_ChkEmpty(double);
357 
358  if ( !setup_.weighted_ )
359  return ((double)sum_x_) / nrused_;
360 
361  return this->isZero(sum_w_) ? mUdf(double) : ((double)sum_wx_) / sum_w_;
362 }
363 
364 
365 template <class T>
366 inline T BaseCalc<T>::sum() const
367 {
369  return sum_x_;
370 }
371 
372 
373 template <class T>
374 inline T BaseCalc<T>::sqSum() const
375 {
377  return sum_xx_;
378 }
379 
380 
381 template <class T>
382 inline double BaseCalc<T>::rms() const
383 {
384  mBaseCalc_ChkEmpty(double);
385 
386  if ( !setup_.weighted_ )
387  return Math::Sqrt( ((double)sum_xx_) / nrused_ );
388 
389  return this->isZero(sum_w_) ? mUdf(double)
390  : Math::Sqrt( ((double)sum_wxx_)/sum_w_ );
391 }
392 
393 
394 template <class T>
395 inline double BaseCalc<T>::variance() const
396 {
397  if ( nrused_ < 2 ) return 0;
398 
399  if ( !setup_.weighted_ )
400  return ( sum_xx_ - (sum_x_ * ((double)sum_x_) / nrused_) )
401  / (nrused_ - 1);
402 
403  return (sum_wxx_ - (sum_wx_ * ((double)sum_wx_) / sum_w_) )
404  / ( (nrused_-1) * ((double)sum_w_) / nrused_ );
405 }
406 
407 
408 template <>
410 {
411  pErrMsg("Undefined operation for float_complex in template");
412  return mUdf(double);
413 }
414 
415 
416 template <class T>
417 inline double BaseCalc<T>::normvariance() const
418 {
419  if ( nrused_ < 2 ) return 0;
420 
421  double fact = 0.1;
422  double avg = average();
423  double var = variance();
424  const double divisor = avg*avg + fact*var;
425  if ( mIsZero(divisor,mDefEps) )
426  return 0;
427 
428  return var / divisor;
429 }
430 
431 
432 template <class T>
433 inline T BaseCalc<T>::min( int* index_of_min ) const
434 {
435  if ( index_of_min ) *index_of_min = minidx_;
437  return minval_;
438 }
439 
440 
441 template <class T>
442 inline T BaseCalc<T>::max( int* index_of_max ) const
443 {
444  if ( index_of_max ) *index_of_max = maxidx_;
446  return maxval_;
447 }
448 
449 
450 template <class T>
451 inline T BaseCalc<T>::extreme( int* index_of_extr ) const
452 {
453  if ( index_of_extr ) *index_of_extr = 0;
455 
456  const T maxcmp = maxval_ < 0 ? -maxval_ : maxval_;
457  const T mincmp = minval_ < 0 ? -minval_ : minval_;
458  if ( maxcmp < mincmp )
459  {
460  if ( index_of_extr ) *index_of_extr = minidx_;
461  return minval_;
462  }
463  else
464  {
465  if ( index_of_extr ) *index_of_extr = maxidx_;
466  return maxval_;
467  }
468 }
469 
470 
471 template <class T>
472 inline T BaseCalc<T>::clipVal( float ratio, bool upper ) const
473 {
475  (void)median();
476  const int lastidx = medvals_.size();
477  const float fidx = ratio * lastidx;
478  const int idx = fidx <= 0 ? 0 : (fidx > lastidx ? lastidx : (int)fidx);
479  return medvals_[upper ? lastidx - idx : idx];
480 }
481 
482 
483 template <class T>
484 inline T BaseCalc<T>::mostFreq() const
485 {
486  if ( clss_.isEmpty() )
487  return mUdf(T);
488 
489  T maxwt = clsswt_[0]; int ret = clss_[0];
490  for ( int idx=1; idx<clss_.size(); idx++ )
491  {
492  if ( clsswt_[idx] > maxwt )
493  { maxwt = clsswt_[idx]; ret = clss_[idx]; }
494  }
495 
496  return (T)ret;
497 }
498 
499 
500 template<> inline
502 { return mUdf(float_complex); }
503 
504 
505 template <class T> inline
506 T computeMedian( const T* data, int sz, int pol, int* idx_of_med )
507 {
508  if ( idx_of_med ) *idx_of_med = 0;
509  if ( sz < 2 )
510  return sz < 1 ? mUdf(T) : data[0];
511 
512  int mididx = sz / 2;
513  T* valarr = const_cast<T*>( data );
514  if ( !idx_of_med )
515  quickSort( valarr, sz );
516  else
517  {
518  mGetIdxArr( int, idxs, sz );
519  quickSort( valarr, idxs, sz );
520  *idx_of_med = idxs[ mididx ];
521  delete [] idxs;
522  }
523 
524  if ( sz%2 == 0 )
525  {
526  if ( pol == 0 )
527  return (data[mididx] + data[mididx-1]) / 2;
528  else if ( pol == 1 )
529  mididx--;
530  }
531 
532  return data[ mididx ];
533 }
534 
535 
536 template <class T> inline
537 T computeWeightedMedian( const T* data, const T* wts, int sz,
538  int* idx_of_med )
539 {
540  if ( idx_of_med ) *idx_of_med = 0;
541  if ( sz < 2 )
542  return sz < 1 ? mUdf(T) : data[0];
543 
544  T* valarr = const_cast<T*>( data );
545  mGetIdxArr( int, idxs, sz );
546  quickSort( valarr, idxs, sz );
547  T* wtcopy = new T[sz];
548  OD::memCopy( wtcopy, wts, sz*sizeof(T) );
549  float wsum = 0;
550  for ( int idx=0; idx<sz; idx++ )
551  {
552  const_cast<T&>(wts[idx]) = wtcopy[ idxs[idx] ];
553  wsum += (float) wts[idx];
554  }
555  delete [] idxs;
556 
557  const float hwsum = wsum * 0.5f;
558  wsum = 0;
559  int medidx = 0;
560  for ( int idx=0; idx<sz; idx++ )
561  {
562  wsum += (float) wts[idx];
563  if ( wsum >= hwsum )
564  { medidx = idx; break; }
565  }
566  if ( idx_of_med ) *idx_of_med = medidx;
567  return valarr[ medidx ];
568 }
569 
570 
571 template <class T>
572 inline T BaseCalc<T>::median( int* idx_of_med ) const
573 {
574  const int policy = setup_.medianEvenHandling();
575  const int sz = medvals_.size();
576  const T* vals = medvals_.arr();
577  return setup_.weighted_ ?
578  computeWeightedMedian( vals, medwts_.arr(), sz, idx_of_med )
579  : computeMedian( vals, sz, policy, idx_of_med );
580 }
581 
582 
583 
584 
585 template <class T> inline
587 {
588  nradded_++;
589  if ( mIsUdf(val) )
590  return *this;
591  if ( setup_.weighted_ && (mIsUdf(wt) || this->isZero(wt)) )
592  return *this;
593 
594  if ( setup_.needmed_ )
595  {
596  medvals_ += val;
597  if ( setup_.weighted_ )
598  medwts_ += wt;
599  }
600 
601  if ( setup_.needextreme_ )
602  {
603  if ( nrused_ == 0 )
604  minval_ = maxval_ = val;
605  else
606  {
607  if ( val < minval_ ) { minval_ = val; minidx_ = nradded_ - 1; }
608  if ( val > maxval_ ) { maxval_ = val; maxidx_ = nradded_ - 1; }
609  }
610  }
611 
612  if ( setup_.needmostfreq_ )
613  setMostFrequent( val, wt );
614 
615  if ( setup_.needsums_ )
616  {
617  sum_x_ += val;
618  sum_xx_ += val * val;
619  if ( setup_.weighted_ )
620  {
621  sum_w_ += wt;
622  sum_wx_ += wt * val;
623  sum_wxx_ += wt * val * val;
624  }
625  }
626 
627  nrused_++;
628  return *this;
629 }
630 
631 
632 template <class T> inline
633 void RunCalc<T>::setMostFrequent( T val, T wt )
634 {
635  int ival; Conv::set( ival, val );
636  int setidx = clss_.indexOf( ival );
637 
638  if ( setidx < 0 )
639  { clss_ += ival; clsswt_ += wt; }
640  else
641  clsswt_[setidx] += wt;
642 }
643 
644 
645 template <> inline
647  float_complex wt )
648 { pErrMsg("Undefined operation for float_complex in template"); }
649 
650 
651 template <class T> inline
653 {
654  nradded_--;
655  if ( mIsUdf(val) )
656  return *this;
657  if ( setup_.weighted_ && (mIsUdf(wt) || this->isZero(wt)) )
658  return *this;
659 
660  if ( setup_.needmed_ )
661  {
662  int idx = medvals_.size();
663  while ( true )
664  {
665  idx = medvals_.indexOf( val, false, idx-1 );
666  if ( idx < 0 ) break;
667  if ( setup_.weighted_ && medwts_[idx] == wt )
668  {
669  medvals_.removeSingle( idx );
670  medwts_.removeSingle( idx );
671  break;
672  }
673  }
674  }
675 
676  if ( setup_.needmostfreq_ )
677  {
678  int ival; Conv::set( ival, val );
679  int setidx = clss_.indexOf( ival );
680  int iwt = 1;
681  if ( setup_.weighted_ )
682  Conv::set( iwt, wt );
683 
684  if ( setidx >= 0 )
685  {
686  clsswt_[setidx] -= wt;
687  if ( clsswt_[setidx] <= 0 )
688  {
689  clss_.removeSingle( setidx );
690  clsswt_.removeSingle( setidx );
691  }
692  }
693  }
694 
695  if ( setup_.needsums_ )
696  {
697  sum_x_ -= val;
698  sum_xx_ -= val * val;
699  if ( setup_.weighted_ )
700  {
701  sum_w_ -= wt;
702  sum_wx_ -= wt * val;
703  sum_wxx_ -= wt * val * val;
704  }
705  }
706 
707  nrused_--;
708  return *this;
709 }
710 
711 
712 template <class T> inline
713 RunCalc<T>& RunCalc<T>::addValues( int sz, const T* data, const T* weights )
714 {
715  for ( int idx=0; idx<sz; idx++ )
716  addValue( data[idx], weights ? weights[idx] : 1 );
717  return *this;
718 }
719 
720 
721 template <class T> inline
722 RunCalc<T>& RunCalc<T>::replaceValue( T oldval, T newval, T wt )
723 {
724  removeValue( oldval, wt );
725  return addValue( newval, wt );
726 }
727 
728 
729 
730 
731 template <class T> inline
733 {
734  posidx_ = 0; empty_ = true; full_ = false;
735  needcalc_ = calc_.setup().needSums() || calc_.setup().needMostFreq();
736  calc_.clear();
737 }
738 
739 
740 template <class T> inline
742 {
743  if ( empty_ ) return;
744 
745  const int stopidx = full_ ? sz_ : posidx_;
746  for ( int idx=posidx_; idx<stopidx; idx++ )
747  calc.addValue( vals_[idx], wts_ ? wts_[idx] : 1 );
748  for ( int idx=0; idx<posidx_; idx++ )
749  calc.addValue( vals_[idx], wts_ ? wts_[idx] : 1 );
750 }
751 
752 
753 template <class T> inline
755 {
756  switch ( t )
757  {
758  case Min: return min();
759  case Max: return max();
760  case Extreme: return extreme();
761  case Median: return median();
762  default: break;
763  }
764  return calc_.getValue( t );
765 }
766 
767 
768 template <class T> inline
770 {
771  int ret;
772  switch ( t )
773  {
774  case Min: (void)min( &ret ); break;
775  case Max: (void)max( &ret ); break;
776  case Extreme: (void)extreme( &ret ); break;
777  case Median: (void)median( &ret ); break;
778  default: ret = 0; break;
779  }
780  return ret;
781 }
782 
783 
784 template <class T> inline
785 T WindowedCalc<T>::min( int* index_of_min ) const
786 {
787  RunCalc<T> calc( CalcSetup().require(Stats::Min) );
788  fillCalc( calc );
789  return calc.min( index_of_min );
790 }
791 
792 
793 template <class T> inline
794 T WindowedCalc<T>::max( int* index_of_max ) const
795 {
796  RunCalc<T> calc( CalcSetup().require(Stats::Max) );
797  fillCalc( calc );
798  return calc.max( index_of_max );
799 }
800 
801 
802 template <class T> inline
803 T WindowedCalc<T>::extreme( int* index_of_extr ) const
804 {
805  RunCalc<T> calc( CalcSetup().require(Stats::Extreme) );
806  fillCalc( calc );
807  return calc.extreme( index_of_extr );
808 }
809 
810 
811 template <class T> inline
812 T WindowedCalc<T>::median( int* index_of_med ) const
813 {
814  CalcSetup rcs( calc_.setup().weighted_ );
815  RunCalc<T> calc( rcs.require(Stats::Median) );
816  fillCalc( calc );
817  return calc.median( index_of_med );
818 }
819 
820 
821 template <class T>
823 {
824  if ( needcalc_ )
825  {
826  if ( !full_ )
827  calc_.addValue( val, wt );
828  else
829  {
830  if ( !wts_ || wt == wts_[posidx_] )
831  calc_.replaceValue( vals_[posidx_], val, wt );
832  else
833  {
834  calc_.removeValue( vals_[posidx_], wts_[posidx_] );
835  calc_.addValue( val, wt );
836  }
837  }
838  }
839 
840  vals_[posidx_] = val;
841  if ( wts_ ) wts_[posidx_] = wt;
842 
843  posidx_++;
844  if ( posidx_ >= sz_ )
845  { full_ = true; posidx_ = 0; }
846 
847  empty_ = false;
848  return *this;
849 }
850 
851 #undef mRunCalc_ChkEmpty
852 
853 }; // namespace Stats
bool needextreme_
Definition: statruncalc.h:69
Definition: stattype.h:25
#define mExpClass(module)
Definition: commondefs.h:157
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
T maxval_
Definition: statruncalc.h:146
#define mGetIdxArr(tp, var, sz)
Creates new array of an integer type filled with index.
Definition: commondefs.h:256
BaseCalc(const CalcSetup &s)
Definition: statruncalc.h:136
T median(int *i=0) const
Definition: statruncalc.h:812
bool needMedian() const
Definition: statruncalc.h:53
T count() const
Definition: statruncalc.h:253
#define mBaseCalc_ChkEmpty(typ)
Definition: statruncalc.h:340
int maxidx_
Definition: statruncalc.h:144
Setup for the Stats::RunCalc and Stats::ParallelCalc objects.
Definition: statruncalc.h:35
const CalcSetup & setup() const
Definition: statruncalc.h:104
Definition: stattype.h:25
int getIndex(Type) const
only for Median, Min and Max
Definition: statruncalc.h:323
bool needvariance_
Definition: statruncalc.h:73
T minval_
Definition: statruncalc.h:145
Definition: stattype.h:23
T sum() const
Definition: statruncalc.h:366
#define mIsZero(x, eps)
Definition: commondefs.h:55
double normvariance() const
Definition: statruncalc.h:417
RunCalc< T > & replaceValue(T olddata, T newdata, T wt=1)
Definition: statruncalc.h:722
void clear()
Definition: statruncalc.h:289
T * vals_
Definition: statruncalc.h:277
double getValue(Type) const
Definition: statruncalc.h:754
RunCalc< T > & removeValue(T data, T weight=1)
Definition: statruncalc.h:652
RunCalc< T > & addValues(int sz, const T *data, const T *weights=0)
Definition: statruncalc.h:713
void clear(std::ios &)
int minidx_
Definition: statruncalc.h:143
bool isWeighted() const
Definition: statruncalc.h:50
RunCalc(const CalcSetup &s)
Definition: statruncalc.h:191
void clear()
Definition: statruncalc.h:732
int posidx_
Definition: statruncalc.h:278
void set(T &_to, const F &fr)
template based type conversion
Definition: convert.h:27
double getValue(Type) const
Definition: statruncalc.h:299
T computeWeightedMedian(const T *data, const T *wts, int sz, int *idx_of_med)
Definition: statruncalc.h:537
TypeSet< int > clss_
Definition: statruncalc.h:153
T max(int *index_of_max=0) const
Definition: statruncalc.h:442
RunCalc< T > & addValue(T data, T weight=1)
Definition: statruncalc.h:586
Definition: stattype.h:24
Stats computation running in parallel.
Definition: statparallelcalc.h:31
T median(int *index_of_median=0) const
Definition: statruncalc.h:572
bool needVariance() const
Definition: statruncalc.h:55
int nrused_
Definition: statruncalc.h:142
float variance(const X &x, int sz)
Definition: simpnumer.h:286
virtual double variance() const
Definition: statruncalc.h:395
Type
Definition: stattype.h:19
bool needExtreme() const
Definition: statruncalc.h:51
void quickSort(T *arr, I sz)
Definition: sorting.h:257
bool needSums() const
Definition: statruncalc.h:52
int getIndex(Type) const
Only use for Min, Max or Median.
Definition: statruncalc.h:769
int count() const
Definition: statruncalc.h:116
bool needcalc_
Definition: statruncalc.h:281
TypeSet< T > clsswt_
Definition: statruncalc.h:154
void setMostFrequent(T val, T wt)
Definition: statruncalc.h:633
bool needmed_
Definition: statruncalc.h:71
bool isEmpty() const
Definition: statruncalc.h:114
Set of (small) copyable elements.
Definition: commontypes.h:26
Definition: stattype.h:24
bool needMostFreq() const
Definition: statruncalc.h:54
T sum_xx_
Definition: statruncalc.h:148
int nradded_
Definition: statruncalc.h:141
T computeMedian(const T *data, int sz, int pol, int *idx_of_med)
Definition: statruncalc.h:506
T * wts_
Definition: statruncalc.h:276
int size(bool used=true) const
Definition: statruncalc.h:111
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
T mostFreq() const
Definition: statruncalc.h:484
WindowedCalc(const CalcSetup &rcs, int sz)
Definition: statruncalc.h:237
T min(int *i=0) const
Definition: statruncalc.h:785
Definition: stattype.h:22
Definition: stattype.h:26
std::complex< float > float_complex
Definition: odcomplex.h:16
TypeSet< T > medvals_
Definition: statruncalc.h:133
RunCalc manager which buffers a part of the data.
Definition: statruncalc.h:234
T extreme(int *i=0) const
Definition: statruncalc.h:803
Definition: stattype.h:22
bool empty_
Definition: statruncalc.h:279
T extreme(int *index_of_extr=0) const
Definition: statruncalc.h:451
#define mDefEps
Definition: commondefs.h:60
Definition: stattype.h:23
~WindowedCalc()
Definition: statruncalc.h:242
double rms() const
Definition: statruncalc.h:382
bool weighted_
Definition: statruncalc.h:68
double stdDev() const
Definition: statruncalc.h:344
bool hasUndefs() const
Definition: statruncalc.h:110
CalcSetup(bool weighted=false)
Definition: statruncalc.h:38
Calculates mean, min, max etc., as running values.
Definition: statruncalc.h:188
void fillCalc(RunCalc< T > &) const
Definition: statruncalc.h:741
T clipVal(float ratio, bool upper) const
require median; 0 <= ratio <= 1
Definition: statruncalc.h:472
T sum_wx_
Definition: statruncalc.h:150
Definition: stattype.h:23
Base class to calculate mean, min, max, etc.. can be used either as running values (Stats::RunCalc) o...
Definition: statruncalc.h:97
virtual ~BaseCalc()
Definition: statruncalc.h:101
bool full_
Definition: statruncalc.h:280
Statistics.
Definition: array2dinterpol.h:27
T min(int *index_of_min=0) const
Definition: statruncalc.h:433
#define mRunCalc_DefEqFn(ret, fn)
Definition: statruncalc.h:255
Definition: stattype.h:21
const int sz_
Definition: statruncalc.h:275
T sum_x_
Definition: statruncalc.h:147
T sum_wxx_
Definition: statruncalc.h:151
T sum_w_
Definition: statruncalc.h:149
RunCalc< T > calc_
Definition: statruncalc.h:274
T sqSum() const
Definition: statruncalc.h:374
Definition: stattype.h:22
bool needsums_
Definition: statruncalc.h:70
CalcSetup setup_
Definition: statruncalc.h:139
double average() const
Definition: statruncalc.h:354
#define mClass(module)
Definition: commondefs.h:161
Definition: stattype.h:24
#define pErrMsg(msg)
Usual access point for programmer error messages.
Definition: errmsg.h:34
bool isZero(const T &t) const
Definition: statruncalc.h:172
T max(int *i=0) const
Definition: statruncalc.h:794
bool isWeighted() const
Definition: statruncalc.h:105
bool needmostfreq_
Definition: statruncalc.h:72
float Sqrt(float)
TypeSet< T > medwts_
Definition: statruncalc.h:155
WindowedCalc & addValue(T data, T weight=1)
Definition: statruncalc.h:822

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