OpendTect-6_4  6.4
statgrubbs.h
Go to the documentation of this file.
1 #ifndef statgrubbs_h
2 #define statgrubbs_h
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert/Bruno
8  Date: Feb 2011
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "algomod.h"
15 #include "gendefs.h"
16 #include <math.h>
17 
18 namespace Stats
19 {
20 
26 {
27 public:
28 
29  template <class T,class SzTp>
30  static T getMax(T*,SzTp sz,SzTp& index_of_max);
31 
32 };
33 
34 
35 template <class T,class SzTp>
36 inline T Stats::Grubbs::getMax( T* arr, SzTp sz, SzTp& idxof )
37 {
38  if ( sz < 3 )
39  { idxof = 0; return sz > 0 ? 0 : mUdf(T); }
40  SzTp startidx = 0;
41  for ( ; startidx<sz && mIsUdf(arr[startidx]); startidx++ )
42  /* just skip undefs at start */;
43  if ( startidx+3 > sz )
44  { idxof = startidx; return 0; }
45 
46  T maxval = arr[startidx]; T minval = maxval, sum = maxval;
47  SzTp minidx = startidx, maxidx = startidx;
48  SzTp nonudfsz = 1;
49  for ( SzTp idx=startidx+1; idx<sz; idx++ )
50  {
51  const T val = arr[idx];
52  if ( mIsUdf(val) ) continue;
53 
54  if ( maxval < val ) { maxidx = idx; maxval = val; }
55  if ( minval > val ) { minidx = idx; minval = val; }
56  sum += val;
57  nonudfsz++;
58  }
59  if ( maxval == minval || nonudfsz < 3 )
60  { idxof = startidx; return 0; }
61 
62  const T avg = sum / nonudfsz;
63  sum = 0;
64  for ( SzTp idx=startidx; idx<sz; idx++ )
65  {
66  const T val = arr[idx];
67  if ( mIsUdf(val) ) continue;
68 
69  const T delta = avg - arr[idx];
70  sum += delta * delta;
71  }
72  const T stdev = Math::Sqrt( sum / nonudfsz );
73 
74  const T diffmin = avg - minval;
75  const T diffmax = maxval - avg;
76  idxof = diffmin > diffmax ? minidx : maxidx;
77  return (diffmin > diffmax ? diffmin : diffmax) / stdev;
78 }
79 
80 } // namespace Stats
81 
82 #endif
#define mExpClass(module)
Definition: commondefs.h:160
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
Grubbs&#39; test to detect outliers in a univariate data set assumed to come from a normally distributed ...
Definition: statgrubbs.h:25
static T getMax(T *, SzTp sz, SzTp &index_of_max)
Definition: statgrubbs.h:36
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
T getMax(const ArrayND< T > &in)
returns the Maximum of all defined values in the ArrrayND. Returns UDF if empty or only udfs encounte...
Definition: arrayndalgo.h:202
Statistics.
Definition: array2dinterpol.h:28
float Sqrt(float)

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