A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
average.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2009 IITP RAS
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Authors: Pavel Boyko <boyko@iitp.ru>
18
* Corrections and extensions: Timo Bingmann <tbns@idlebox.net>
19
*/
20
21
#ifndef AVERAGE_H
22
#define AVERAGE_H
23
24
#include "
basic-data-calculators.h
"
25
26
#include <cmath>
27
#include <limits>
28
#include <ostream>
29
#include <stdint.h>
30
31
namespace
ns3
32
{
33
41
template
<
typename
T =
double
>
42
class
Average
43
{
44
public
:
45
Average
()
46
:
m_size
(0),
47
m_min
(std::numeric_limits<T>::
max
()),
48
m_max
(0)
49
{
50
}
51
56
void
Update
(
const
T&
x
)
57
{
58
// Give the variance calculator the next value.
59
m_varianceCalculator
.
Update
(
x
);
60
61
m_min
=
std::min
(
x
,
m_min
);
62
m_max
=
std::max
(
x
,
m_max
);
63
m_size
++;
64
}
65
67
void
Reset
()
68
{
69
m_varianceCalculator
.
Reset
();
70
71
m_size
= 0;
72
m_min
=
std::numeric_limits<T>::max
();
73
m_max
= 0;
74
}
75
76
// Sample statistics
81
uint32_t
Count
()
const
82
{
83
return
m_size
;
84
}
85
90
T
Min
()
const
91
{
92
return
m_min
;
93
}
94
99
T
Max
()
const
100
{
101
return
m_max
;
102
}
103
108
double
Avg
()
const
109
{
110
return
m_varianceCalculator
.
getMean
();
111
}
112
117
double
Mean
()
const
118
{
119
return
Avg
();
120
}
121
126
double
Var
()
const
127
{
128
return
m_varianceCalculator
.
getVariance
();
129
}
130
135
double
Stddev
()
const
136
{
137
return
std::sqrt(
Var
());
138
}
139
155
double
Error90
()
const
156
{
157
return
1.645 * std::sqrt(
Var
() /
Count
());
158
}
159
170
double
Error95
()
const
171
{
172
return
1.960 * std::sqrt(
Var
() /
Count
());
173
}
174
186
double
Error99
()
const
187
{
188
return
2.576 * std::sqrt(
Var
() /
Count
());
189
}
190
193
private
:
194
uint32_t
m_size
;
195
T
m_min
;
196
T
m_max
;
197
MinMaxAvgTotalCalculator<double>
m_varianceCalculator
;
198
};
199
206
template
<
typename
T>
207
std::ostream&
208
operator<<
(std::ostream& os,
const
Average<T>
&
x
)
209
{
210
if
(
x
.Count() != 0)
211
{
212
os <<
x
.Avg() <<
" ("
<<
x
.Stddev() <<
") ["
<<
x
.Min() <<
", "
<<
x
.Max() <<
"]"
;
213
}
214
else
215
{
216
os <<
"NA"
;
// not available
217
}
218
return
os;
219
}
220
}
// namespace ns3
221
#endif
/* AVERAGE_H */
min
#define min(a, b)
Definition:
80211b.c:41
max
#define max(a, b)
Definition:
80211b.c:42
basic-data-calculators.h
ns3::Average
Simple average, min, max and std.
Definition:
average.h:43
ns3::Average::m_max
T m_max
Maximum value observed.
Definition:
average.h:196
ns3::Average::Error90
double Error90() const
Margin of error of the mean for 90% confidence level.
Definition:
average.h:155
ns3::Average::Avg
double Avg() const
Sample average.
Definition:
average.h:108
ns3::Average::Min
T Min() const
Sample minimum.
Definition:
average.h:90
ns3::Average::Var
double Var() const
Sample unbiased nbiased estimate of variance.
Definition:
average.h:126
ns3::Average::Max
T Max() const
Sample maximum.
Definition:
average.h:99
ns3::Average::m_size
uint32_t m_size
Number of sampled data.
Definition:
average.h:194
ns3::Average::m_min
T m_min
Minimum value observed.
Definition:
average.h:195
ns3::Average::Average
Average()
Definition:
average.h:45
ns3::Average::Reset
void Reset()
Reset statistics.
Definition:
average.h:67
ns3::Average::Update
void Update(const T &x)
Add new sample.
Definition:
average.h:56
ns3::Average::Error95
double Error95() const
Margin of error of the mean for 95% confidence level.
Definition:
average.h:170
ns3::Average::Error99
double Error99() const
Margin of error of the mean for 99% confidence level.
Definition:
average.h:186
ns3::Average::Count
uint32_t Count() const
Sample size.
Definition:
average.h:81
ns3::Average::m_varianceCalculator
MinMaxAvgTotalCalculator< double > m_varianceCalculator
Variance calculator.
Definition:
average.h:197
ns3::Average::Stddev
double Stddev() const
Sample standard deviation.
Definition:
average.h:135
ns3::Average::Mean
double Mean() const
Sample estimate of mean, alias to Avg.
Definition:
average.h:117
ns3::MinMaxAvgTotalCalculator< double >
ns3::MinMaxAvgTotalCalculator::Reset
void Reset()
Reinitializes all variables of MinMaxAvgTotalCalculator.
Definition:
basic-data-calculators.h:268
ns3::MinMaxAvgTotalCalculator::getVariance
double getVariance() const override
Returns the current variance.
Definition:
basic-data-calculators.h:126
ns3::MinMaxAvgTotalCalculator::getMean
double getMean() const override
Returns the mean value.
Definition:
basic-data-calculators.h:108
ns3::MinMaxAvgTotalCalculator::Update
void Update(const T i)
Updates all variables of MinMaxAvgTotalCalculator.
Definition:
basic-data-calculators.h:207
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition:
angles.cc:159
two-ray-to-three-gpp-ch-calibration.x
x
Definition:
two-ray-to-three-gpp-ch-calibration.py:603
src
stats
model
average.h
Generated on Sun Mar 3 2024 17:11:08 for ns-3 by
1.9.1