votca
2024.2-dev
Loading...
Searching...
No Matches
tools
include
votca
tools
average.h
Go to the documentation of this file.
1
/*
2
* Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
18
#ifndef VOTCA_TOOLS_AVERAGE_H
19
#define VOTCA_TOOLS_AVERAGE_H
20
21
// Standard includes
22
#include <cmath>
23
24
namespace
votca
{
25
namespace
tools {
26
27
template
<
typename
T>
28
class
Average
{
29
public
:
30
void
Process
(
const
T &value);
31
void
Clear
();
32
template
<
typename
iterator_type>
33
void
ProcessRange
(
const
iterator_type &begin,
const
iterator_type &end);
34
35
T
CalcDev
()
const
;
36
T
CalcSig2
()
const
;
37
const
T &
getAvg
()
const
;
38
const
T
getM2
()
const
;
39
size_t
getN
()
const
;
40
41
private
:
42
size_t
n_
= 0;
43
T
av_
= 0;
// average
44
T
m2_
= 0;
// second moment
45
};
46
47
template
<
typename
T>
48
inline
void
Average<T>::Process
(
const
T &value) {
49
av_ = av_ * (double)n_ / (
double
)(n_ + 1) + value / (
double
)(n_ + 1);
50
n_++;
51
m2_ += value * value;
52
}
53
54
template
<
typename
T>
55
inline
void
Average<T>::Clear
() {
56
av_ = 0;
57
n_ = 0;
58
m2_ = 0;
59
}
60
61
template
<
typename
T>
62
template
<
typename
iterator_type>
63
void
Average<T>::ProcessRange
(
const
iterator_type &begin,
64
const
iterator_type &end) {
65
for
(iterator_type iter = begin; iter != end; ++iter) {
66
Process(*iter);
67
}
68
}
69
70
template
<
typename
T>
71
T
Average<T>::CalcDev
()
const
{
72
return
std::sqrt((m2_ - n_ * av_ * av_) / (n_ - 1));
73
}
74
75
template
<
typename
T>
76
T
Average<T>::CalcSig2
()
const
{
77
double
dev = 0.0;
78
dev = m2_ / n_ - av_ * av_;
79
return
dev;
80
}
81
82
template
<
typename
T>
83
const
T &
Average<T>::getAvg
()
const
{
84
return
av_;
85
}
86
87
template
<
typename
T>
88
const
T
Average<T>::getM2
()
const
{
89
double
m2 = 0.0;
90
m2 = m2_ / n_;
91
return
m2;
92
}
93
94
template
<
typename
T>
95
size_t
Average<T>::getN
()
const
{
96
return
n_;
97
}
98
99
}
// namespace tools
100
}
// namespace votca
101
102
#endif
// VOTCA_TOOLS_AVERAGE_H
votca::tools::Average
Definition
average.h:28
votca::tools::Average::n_
size_t n_
Definition
average.h:42
votca::tools::Average::Clear
void Clear()
Definition
average.h:55
votca::tools::Average::Process
void Process(const T &value)
Definition
average.h:48
votca::tools::Average::ProcessRange
void ProcessRange(const iterator_type &begin, const iterator_type &end)
Definition
average.h:63
votca::tools::Average::getM2
const T getM2() const
Definition
average.h:88
votca::tools::Average::getAvg
const T & getAvg() const
Definition
average.h:83
votca::tools::Average::av_
T av_
Definition
average.h:43
votca::tools::Average::CalcSig2
T CalcSig2() const
Definition
average.h:76
votca::tools::Average::getN
size_t getN() const
Definition
average.h:95
votca::tools::Average::CalcDev
T CalcDev() const
Definition
average.h:71
votca::tools::Average::m2_
T m2_
Definition
average.h:44
votca
base class for all analysis tools
Definition
basebead.h:33
Generated by
1.12.0