A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
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
#include "ns3/basic-data-calculators.h"
24
25
#include <cmath>
26
#include <limits>
27
#include <ostream>
28
#include <stdint.h>
29
30
namespace
ns3
31
{
32
40
template
<
typename
T =
double
>
41
class
Average
42
{
43
public
:
44
Average
()
45
:
m_size
(0),
46
m_min
(
std
::numeric_limits<T>::
max
()),
47
m_max
(0)
48
{
49
}
50
55
void
Update
(
const
T& x)
56
{
57
// Give the variance calculator the next value.
58
m_varianceCalculator
.
Update
(x);
59
60
m_min
= std::min(x,
m_min
);
61
m_max
= std::max(x,
m_max
);
62
m_size
++;
63
}
64
66
void
Reset
()
67
{
68
m_varianceCalculator
.
Reset
();
69
70
m_size
= 0;
71
m_min
= std::numeric_limits<T>::max();
72
m_max
= 0;
73
}
74
75
// Sample statistics
80
uint32_t
Count
()
const
81
{
82
return
m_size
;
83
}
84
89
T
Min
()
const
90
{
91
return
m_min
;
92
}
93
98
T
Max
()
const
99
{
100
return
m_max
;
101
}
102
107
double
Avg
()
const
108
{
109
return
m_varianceCalculator
.
getMean
();
110
}
111
116
double
Mean
()
const
117
{
118
return
Avg
();
119
}
120
125
double
Var
()
const
126
{
127
return
m_varianceCalculator
.
getVariance
();
128
}
129
134
double
Stddev
()
const
135
{
136
return
std::sqrt(
Var
());
137
}
138
154
double
Error90
()
const
155
{
156
return
1.645 * std::sqrt(
Var
() /
Count
());
157
}
158
169
double
Error95
()
const
170
{
171
return
1.960 * std::sqrt(
Var
() /
Count
());
172
}
173
185
double
Error99
()
const
186
{
187
return
2.576 * std::sqrt(
Var
() /
Count
());
188
}
189
192
private
:
193
uint32_t
m_size
;
194
T
m_min
;
195
T
m_max
;
196
MinMaxAvgTotalCalculator<double>
m_varianceCalculator
;
197
};
198
205
template
<
typename
T>
206
std::ostream&
207
operator<<
(std::ostream& os,
const
Average<T>
& x)
208
{
209
if
(x.Count() != 0)
210
{
211
os << x.Avg() <<
" ("
<< x.Stddev() <<
") ["
<< x.Min() <<
", "
<< x.Max() <<
"]"
;
212
}
213
else
214
{
215
os <<
"NA"
;
// not available
216
}
217
return
os;
218
}
219
}
// namespace ns3
220
#endif
/* AVERAGE_H */
max
#define max(a, b)
Definition:
80211b.c:42
ns3::Average
Simple average, min, max and std.
Definition:
average.h:42
ns3::Average::m_max
T m_max
Maximum value observed.
Definition:
average.h:195
ns3::Average::Error90
double Error90() const
Margin of error of the mean for 90% confidence level.
Definition:
average.h:154
ns3::Average::Avg
double Avg() const
Sample average.
Definition:
average.h:107
ns3::Average::Min
T Min() const
Sample minimum.
Definition:
average.h:89
ns3::Average::Var
double Var() const
Sample unbiased nbiased estimate of variance.
Definition:
average.h:125
ns3::Average::Max
T Max() const
Sample maximum.
Definition:
average.h:98
ns3::Average::m_size
uint32_t m_size
Number of sampled data.
Definition:
average.h:193
ns3::Average::m_min
T m_min
Minimum value observed.
Definition:
average.h:194
ns3::Average::Average
Average()
Definition:
average.h:44
ns3::Average::Reset
void Reset()
Reset statistics.
Definition:
average.h:66
ns3::Average::Update
void Update(const T &x)
Add new sample.
Definition:
average.h:55
ns3::Average::Error95
double Error95() const
Margin of error of the mean for 95% confidence level.
Definition:
average.h:169
ns3::Average::Error99
double Error99() const
Margin of error of the mean for 99% confidence level.
Definition:
average.h:185
ns3::Average::Count
uint32_t Count() const
Sample size.
Definition:
average.h:80
ns3::Average::m_varianceCalculator
MinMaxAvgTotalCalculator< double > m_varianceCalculator
Variance calculator.
Definition:
average.h:196
ns3::Average::Stddev
double Stddev() const
Sample standard deviation.
Definition:
average.h:134
ns3::Average::Mean
double Mean() const
Sample estimate of mean, alias to Avg.
Definition:
average.h:116
ns3::MinMaxAvgTotalCalculator
Template class MinMaxAvgTotalCalculator.
Definition:
basic-data-calculators.h:41
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
uint32_t
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:129
std
STL namespace.
src
stats
model
average.h
Generated on Sun Jul 2 2023 18:22:04 for ns-3 by
1.9.6