A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
average.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 IITP RAS
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Pavel Boyko <boyko@iitp.ru>
19
* Corrections and extensions: Timo Bingmann <tbns@idlebox.net>
20
*/
21
22
#ifndef AVERAGE_H
23
#define AVERAGE_H
24
#include <cmath>
25
#include <ostream>
26
#include <limits>
27
#include <stdint.h>
28
#include "ns3/basic-data-calculators.h"
29
30
namespace
ns3
{
31
39
template
<
typename
T =
double
>
40
class
Average
41
{
42
public
:
43
Average
()
44
:
m_size
(0),
m_min
(std::numeric_limits<T>::
max
()),
m_max
(0)
45
{
46
}
47
52
void
Update
(T
const
&
x
)
53
{
54
// Give the variance calculator the next value.
55
m_varianceCalculator
.
Update
(
x
);
56
57
m_min
=
std::min
(
x
,
m_min
);
58
m_max
=
std::max
(
x
,
m_max
);
59
m_size
++;
60
}
62
void
Reset
()
63
{
64
m_varianceCalculator
.
Reset
();
65
66
m_size
= 0;
67
m_min
=
std::numeric_limits<T>::max
();
68
m_max
= 0;
69
}
70
71
// Sample statistics
76
uint32_t
Count
()
const
{
return
m_size
; }
81
T
Min
()
const
{
return
m_min
; }
86
T
Max
()
const
{
return
m_max
; }
91
double
Avg
()
const
{
return
m_varianceCalculator
.
getMean
();}
96
double
Mean
()
const
{
return
Avg
(); }
101
double
Var
()
const
{
return
m_varianceCalculator
.
getVariance
();}
106
double
Stddev
()
const
{
return
std::sqrt (
Var
()); }
107
123
double
Error90
()
const
{
return
1.645 * std::sqrt (
Var
() /
Count
()); }
134
double
Error95
()
const
{
return
1.960 * std::sqrt (
Var
() /
Count
()); }
146
double
Error99
()
const
{
return
2.576 * std::sqrt (
Var
() /
Count
()); }
149
private
:
150
uint32_t
m_size
;
151
T
m_min
;
152
T
m_max
;
153
MinMaxAvgTotalCalculator<double>
m_varianceCalculator
;
154
};
155
162
template
<
typename
T>
163
std::ostream &
operator<<
(std::ostream & os,
Average<T>
const
&
x
)
164
{
165
if
(
x
.Count () != 0)
166
os <<
x
.Avg () <<
" ("
<<
x
.Stddev () <<
") ["
<<
x
.Min () <<
", "
<<
x
.Max () <<
"]"
;
167
else
168
os <<
"NA"
;
// not available
169
return
os;
170
}
171
}
172
#endif
/* AVERAGE_H */
min
#define min(a, b)
Definition:
80211b.c:42
max
#define max(a, b)
Definition:
80211b.c:43
ns3::Average
Simple average, min, max and std.
Definition:
average.h:41
ns3::Average::m_max
T m_max
Maximum value observed.
Definition:
average.h:152
ns3::Average::Error90
double Error90() const
Margin of error of the mean for 90% confidence level.
Definition:
average.h:123
ns3::Average::Avg
double Avg() const
Sample average.
Definition:
average.h:91
ns3::Average::Update
void Update(T const &x)
Add new sample.
Definition:
average.h:52
ns3::Average::Min
T Min() const
Sample minimum.
Definition:
average.h:81
ns3::Average::Var
double Var() const
Sample unbiased nbiased estimate of variance.
Definition:
average.h:101
ns3::Average::Max
T Max() const
Sample maximum.
Definition:
average.h:86
ns3::Average::m_size
uint32_t m_size
Number of sampled data.
Definition:
average.h:150
ns3::Average::m_min
T m_min
Minimum value observed.
Definition:
average.h:151
ns3::Average::Average
Average()
Definition:
average.h:43
ns3::Average::Reset
void Reset()
Reset statistics.
Definition:
average.h:62
ns3::Average::Error95
double Error95() const
Margin of error of the mean for 95% confidence level.
Definition:
average.h:134
ns3::Average::Error99
double Error99() const
Margin of error of the mean for 99% confidence level.
Definition:
average.h:146
ns3::Average::Count
uint32_t Count() const
Sample size.
Definition:
average.h:76
ns3::Average::m_varianceCalculator
MinMaxAvgTotalCalculator< double > m_varianceCalculator
Variance calculator.
Definition:
average.h:153
ns3::Average::Stddev
double Stddev() const
Sample standard deviation.
Definition:
average.h:106
ns3::Average::Mean
double Mean() const
Sample estimate of mean, alias to Avg.
Definition:
average.h:96
ns3::MinMaxAvgTotalCalculator< double >
ns3::MinMaxAvgTotalCalculator::Reset
void Reset()
Reinitializes all variables of MinMaxAvgTotalCalculator.
Definition:
basic-data-calculators.h:238
ns3::MinMaxAvgTotalCalculator::getMean
double getMean() const
Returns the mean value.
Definition:
basic-data-calculators.h:91
ns3::MinMaxAvgTotalCalculator::getVariance
double getVariance() const
Returns the current variance.
Definition:
basic-data-calculators.h:101
ns3::MinMaxAvgTotalCalculator::Update
void Update(const T i)
Updates all variables of MinMaxAvgTotalCalculator.
Definition:
basic-data-calculators.h:178
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:139
sample-rng-plot.x
list x
Random number samples.
Definition:
sample-rng-plot.py:37
src
stats
model
average.h
Generated on Tue Feb 6 2024 19:21:27 for ns-3 by
1.9.1