File: SignalStats.hh

package info (click to toggle)
ignition-math4 4.0.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,840 kB
  • sloc: cpp: 18,143; python: 2,716; ansic: 503; sh: 168; makefile: 16
file content (262 lines) | stat: -rw-r--r-- 8,894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * Copyright (C) 2015 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
#ifndef IGNITION_MATH_SIGNALSTATS_HH_
#define IGNITION_MATH_SIGNALSTATS_HH_

#include <map>
#include <memory>
#include <string>
#include <ignition/math/Helpers.hh>
#include <ignition/math/config.hh>

namespace ignition
{
  namespace math
  {
    inline namespace IGNITION_MATH_VERSION_NAMESPACE
    {
    /// \brief Forward declare private data class.
    class SignalStatisticPrivate;

    /// \class SignalStatistic SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Statistical properties of a discrete time scalar signal.
    class IGNITION_MATH_VISIBLE SignalStatistic
    {
      /// \brief Constructor
      public: SignalStatistic();

      /// \brief Destructor
      public: virtual ~SignalStatistic();

      /// \brief Copy constructor
      /// \param[in] _ss SignalStatistic to copy
      public: SignalStatistic(const SignalStatistic &_ss);

      /// \brief Get the current value of the statistical measure.
      /// \return Current value of the statistical measure.
      public: virtual double Value() const = 0;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return Short name of the statistical measure.
      public: virtual std::string ShortName() const = 0;

      /// \brief Get number of data points in measurement.
      /// \return Number of data points in measurement.
      public: virtual size_t Count() const;

      /// \brief Add a new sample to the statistical measure.
      /// \param[in] _data New signal data point.
      public: virtual void InsertData(const double _data) = 0;

      /// \brief Forget all previous data.
      public: virtual void Reset();

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
      /// \brief Pointer to private data.
      protected: std::unique_ptr<SignalStatisticPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
    };
    /// \}

    /// \class SignalMaximum SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Computing the maximum value of a discretely sampled signal.
    class IGNITION_MATH_VISIBLE SignalMaximum : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "max"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \class SignalMean SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Computing the mean value of a discretely sampled signal.
    class IGNITION_MATH_VISIBLE SignalMean : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "mean"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \class SignalMinimum SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Computing the minimum value of a discretely sampled signal.
    class IGNITION_MATH_VISIBLE SignalMinimum : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "min"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \class SignalRootMeanSquare SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Computing the square root of the mean squared value
    /// of a discretely sampled signal.
    class IGNITION_MATH_VISIBLE SignalRootMeanSquare : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "rms"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \class SignalMaxAbsoluteValue SignalStats.hh
    /// ignition/math/SignalStats.hh
    /// \brief Computing the maximum of the absolute value
    /// of a discretely sampled signal.
    /// Also known as the maximum norm, infinity norm, or supremum norm.
    class IGNITION_MATH_VISIBLE SignalMaxAbsoluteValue : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "maxAbs"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \class SignalVariance SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Computing the incremental variance
    /// of a discretely sampled signal.
    class IGNITION_MATH_VISIBLE SignalVariance : public SignalStatistic
    {
      // Documentation inherited.
      public: virtual double Value() const;

      /// \brief Get a short version of the name of this statistical measure.
      /// \return "var"
      public: virtual std::string ShortName() const;

      // Documentation inherited.
      public: virtual void InsertData(const double _data);
    };
    /// \}

    /// \brief Forward declare private data class.
    class SignalStatsPrivate;

    /// \class SignalStats SignalStats.hh ignition/math/SignalStats.hh
    /// \brief Collection of statistics for a scalar signal.
    class IGNITION_MATH_VISIBLE SignalStats
    {
      /// \brief Constructor
      public: SignalStats();

      /// \brief Destructor
      public: ~SignalStats();

      /// \brief Copy constructor
      /// \param[in] _ss SignalStats to copy
      public: SignalStats(const SignalStats &_ss);

      /// \brief Get number of data points in first statistic.
      /// Technically you can have different numbers of data points
      /// in each statistic if you call InsertStatistic after InsertData,
      /// but this is not a recommended use case.
      /// \return Number of data points in first statistic.
      public: size_t Count() const;

      /// \brief Get the current values of each statistical measure,
      /// stored in a map using the short name as the key.
      /// \return Map with short name of each statistic as key
      /// and value of statistic as the value.
      public: std::map<std::string, double> Map() const;

      /// \brief Add a new sample to the statistical measures.
      /// \param[in] _data New signal data point.
      public: void InsertData(const double _data);

      /// \brief Add a new type of statistic.
      /// \param[in] _name Short name of new statistic.
      /// Valid values include:
      ///  "maxAbs"
      ///  "mean"
      ///  "rms"
      /// \return True if statistic was successfully added,
      /// false if name was not recognized or had already
      /// been inserted.
      public: bool InsertStatistic(const std::string &_name);

      /// \brief Add multiple statistics.
      /// \param[in] _names Comma-separated list of new statistics.
      /// For example, all statistics could be added with:
      ///  "maxAbs,mean,rms"
      /// \return True if all statistics were successfully added,
      /// false if any names were not recognized or had already
      /// been inserted.
      public: bool InsertStatistics(const std::string &_names);

      /// \brief Forget all previous data.
      public: void Reset();

      /// \brief Assignment operator
      /// \param[in] _v A SignalStats to copy
      /// \return this
      public: SignalStats &operator=(const SignalStats &_s);

#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
      /// \brief Pointer to private data.
      private: std::unique_ptr<SignalStatsPrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
    };
    }
    /// \}
  }
}
#endif