Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
dune-raw-data
dune-raw-data
Overlays
SlidingAverage.hh
Go to the documentation of this file.
1
#ifndef SLIDING_AVERAGE_HH_
2
#define SLIDING_AVERAGE_HH_
3
4
/*
5
* Sliding Average
6
* Author: Thijs Miedema
7
* Description: Always up-to-date Sliding Average
8
* Date: July 2018
9
*/
10
11
#include <vector>
12
13
namespace
dune
{
14
15
template
16
<
typename
T
>
17
class
SlidingAverage
{
18
public
:
19
SlidingAverage
(
unsigned
_length) :
length
(_length),
pt
(0),
values
(_length),
current_sum
(0) {};
20
21
void
add_value
(
T
value
){
22
current_sum
-=
values
[
pt
];
23
current_sum
+=
value
;
24
values
[
pt
] =
value
;
25
pt
= (
pt
+ 1) %
length
;
26
}
27
28
T
sum
() {
29
return
current_sum
;
30
}
31
32
T
avg
() {
33
return
current_sum
/ (
T
)
length
;
34
}
35
36
private
:
37
const
unsigned
length
;
38
unsigned
pt
;
39
std::vector<T>
values
;
40
T
current_sum
;
41
};
42
43
template
class
SlidingAverage<unsigned>
;
44
template
class
SlidingAverage<int>
;
45
template
class
SlidingAverage<double>
;
46
47
}
// namespace dune
48
#endif
/* SLIDING_AVERAGE_HH_ */
dune
Definition:
PdspHDFFileReader.hh:29
dune::SlidingAverage::SlidingAverage
SlidingAverage(unsigned _length)
Definition:
SlidingAverage.hh:19
dune::SlidingAverage::avg
T avg()
Definition:
SlidingAverage.hh:32
dune::SlidingAverage::pt
unsigned pt
Definition:
SlidingAverage.hh:38
ValidateOpDetSimulation.T
T
Definition:
ValidateOpDetSimulation.py:52
dune::SlidingAverage::values
std::vector< T > values
Definition:
SlidingAverage.hh:39
dune::SlidingAverage
Definition:
SlidingAverage.hh:17
dune::SlidingAverage::sum
T sum()
Definition:
SlidingAverage.hh:28
dune::SlidingAverage::length
const unsigned length
Definition:
SlidingAverage.hh:37
dune::SlidingAverage::current_sum
T current_sum
Definition:
SlidingAverage.hh:40
submit_mcc.value
value
Definition:
submit_mcc.py:159
dune::SlidingAverage::add_value
void add_value(T value)
Definition:
SlidingAverage.hh:21
Generated by
1.8.11