/workspaces/astro/sol3-sdk/cpp/sol3/math/rolling_stats.h Source File

Space-ng SDK: /workspaces/astro/sol3-sdk/cpp/sol3/math/rolling_stats.h Source File
Space-ng SDK
rolling_stats.h
Go to the documentation of this file.
1 // Copyright (c) Space-ng, inc. All rights reserved.
2 
3 #pragma once
4 
5 #include <cmath>
6 #include <cstddef>
7 #include <deque>
8 #include <numeric>
9 #include <stdexcept>
10 
11 namespace sol3::math {
12 
24 class RollingStats {
25  public:
28  explicit RollingStats(size_t window_size);
29 
32  template <typename T>
33  void add(T value) {
34  if (samples_.size() == window_size_) {
35  samples_.pop_front();
36  }
37  samples_.push_back(static_cast<double>(value));
38  }
39 
41  void clear();
42 
44  size_t count() const;
45 
47  size_t windowSize() const;
48 
50  bool isFull() const;
51 
53  double mean() const;
54 
57  double variance() const;
58 
60  double stddev() const;
61 
62  private:
63  size_t window_size_;
64  std::deque<double> samples_;
65 };
66 
67 } // namespace sol3::math
Definition: rolling_stats.h:24
double stddev() const
Standard deviation (square root of variance).
void clear()
Clear all samples and reset statistics.
RollingStats(size_t window_size)
bool isFull() const
Returns true if the window is full.
void add(T value)
Definition: rolling_stats.h:33
double mean() const
Mean (first moment).
double variance() const
size_t windowSize() const
Maximum window size.
size_t count() const
Number of samples currently in the window.
Definition: conversions.h:5