nidas  v1.2-1520
AdaptiveDespiker.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2006, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_CORE_ADAPTIVE_DESPIKER_H
28 #define NIDAS_CORE_ADAPTIVE_DESPIKER_H
29 
30 #include <stdexcept>
31 
32 namespace nidas { namespace core {
33 
42 {
43 
44 public:
49 
57  void setOutlierProbability(float val);
58 
59  float getOutlierProbability() const { return _prob; }
60 
68  void setDiscLevelMultiplier(float val);
69 
70  float getDiscLevelMultiplier() const { return _levelMultiplier; }
71 
77  float getDiscLevel() const { return _level; }
78 
85  float despike(float u, bool* spike);
86 
91  float forecast() const
92  {
93  return _u1 * _corr + (1. - _corr) * _mean2;
94  }
95 
99  void reset();
100 
107  static float discrLevel(float prob);
108 
113  static float adjustLevel(float corr);
114 
115 private:
116 
117  static bool staticInit();
118 
119  static const size_t STATISTICS_SIZE = 100;
120 
121  static const int ADJUST_TABLE_SIZE = 100;
122 
123  static const int LEN_ERFC_ARRAY = 140;
124 
125  static float _adj[ADJUST_TABLE_SIZE][2];
126 
127  static bool staticInitDone;
128 
129  static void spline(float* x,float* y,int n,double yp1,double ypn,float* y2);
130 
131  static double splint (float* xa,float* ya,float* y2a,int n, double x)
132  throw(std::range_error);
133 
134  void initStatistics(float u);
135 
136  void incrementStatistics(float u);
137 
138  void updateStatistics(float u);
139 
140 
142  float _prob;
143 
146 
153 
155  float _u1;
156 
158  double _mean1;
159 
161  double _mean2;
162 
164  double _var1;
165 
167  double _var2;
168 
169 
171  double _corr;
172 
174  double _initLevel;
175 
176  double _level;
177 
179  float _missfreq;
180 
182  int _msize;
183 
185  size_t _npts;
186 };
187 
188 }} // namespace nidas namespace core
189 
190 #endif
float forecast() const
Forecast a value based on the previous point and correlation and mean.
Definition: AdaptiveDespiker.h:91
void reset()
Reset the statistics.
Definition: AdaptiveDespiker.cc:199
static const size_t STATISTICS_SIZE
Definition: AdaptiveDespiker.h:119
static bool staticInitDone
Definition: AdaptiveDespiker.h:127
float _levelMultiplier
Increase detection level with this factor.
Definition: AdaptiveDespiker.h:145
int _msize
Memory size.
Definition: AdaptiveDespiker.h:182
double _var1
Previous variance.
Definition: AdaptiveDespiker.h:164
Adaptive forecaster for despiking of time-series data.
Definition: AdaptiveDespiker.h:41
double _level
Definition: AdaptiveDespiker.h:176
float getDiscLevelMultiplier() const
Definition: AdaptiveDespiker.h:70
void updateStatistics(float u)
Definition: AdaptiveDespiker.cc:294
float _missfreq
Running ave of freq of missing data.
Definition: AdaptiveDespiker.h:179
double _initLevel
Discrimination level.
Definition: AdaptiveDespiker.h:174
double _var2
Current variance.
Definition: AdaptiveDespiker.h:167
static bool staticInit()
Definition: AdaptiveDespiker.cc:45
static double splint(float *xa, float *ya, float *y2a, int n, double x)
Definition: AdaptiveDespiker.cc:168
float _maxMissingFreq
If more than _maxMissingFreq of the recent 10 data points are missing data points, don&#39;t substitute forecasted data or update forecast statistics.
Definition: AdaptiveDespiker.h:152
AdaptiveDespiker()
Constructor.
Definition: AdaptiveDespiker.cc:69
float getOutlierProbability() const
Definition: AdaptiveDespiker.h:59
static float adjustLevel(float corr)
Adjust the discrimination level based on the current correlation.
Definition: AdaptiveDespiker.cc:340
void setDiscLevelMultiplier(float val)
Definition: AdaptiveDespiker.cc:96
size_t _npts
Number of points processed.
Definition: AdaptiveDespiker.h:185
static float discrLevel(float prob)
Compute a discrimination level from a Gaussan probability.
Definition: AdaptiveDespiker.cc:364
double _mean2
Current mean.
Definition: AdaptiveDespiker.h:161
void setOutlierProbability(float val)
Definition: AdaptiveDespiker.cc:90
void initStatistics(float u)
Definition: AdaptiveDespiker.cc:237
double _mean1
Previous mean.
Definition: AdaptiveDespiker.h:158
float _prob
Prob for detection of outlier in good Gaussian data.
Definition: AdaptiveDespiker.h:142
double _corr
Correlation.
Definition: AdaptiveDespiker.h:171
static void spline(float *x, float *y, int n, double yp1, double ypn, float *y2)
Copied from &quot;Numerical Recipies in C&quot;, the only changes being arrays are indexed from 0...
Definition: AdaptiveDespiker.cc:117
static const int LEN_ERFC_ARRAY
Definition: AdaptiveDespiker.h:123
float _u1
Last point.
Definition: AdaptiveDespiker.h:155
float getDiscLevel() const
If a value is more than discrLevel * sigma away from the mean, then it is considered a spike...
Definition: AdaptiveDespiker.h:77
static const int ADJUST_TABLE_SIZE
Definition: AdaptiveDespiker.h:121
static float _adj[ADJUST_TABLE_SIZE][2]
Definition: AdaptiveDespiker.h:125
float despike(float u, bool *spike)
Pass a value u, and return a forecasted value, along with a boolean indicating whether AdaptiveDespik...
Definition: AdaptiveDespiker.cc:206
void incrementStatistics(float u)
Definition: AdaptiveDespiker.cc:256