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

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