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
histogram.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009 INESC Porto
3
//
4
// SPDX-License-Identifier: GPL-2.0-only
5
//
6
// Author: Pedro Fortuna <pedro.fortuna@inescporto.pt> <pedro.fortuna@gmail.com>
7
//
8
9
#ifndef NS3_HISTOGRAM_H
10
#define NS3_HISTOGRAM_H
11
12
#include <ostream>
13
#include <stdint.h>
14
#include <vector>
15
16
namespace
ns3
17
{
18
19
/**
20
* \brief Class used to store data and make an histogram of the data frequency.
21
*
22
* Data are grouped in "bins", i.e., intervals. Each value is assigned to the
23
* bin according to the following formula: floor(value/binWidth).
24
* Hence, bin \a i groups the data from [i*binWidth, (i+1)binWidth).
25
*
26
* This class only handles \a positive bins, i.e., it does \a not handles negative data.
27
*
28
* \todo Add support for negative data.
29
*
30
* \todo Add method(s) to estimate parameters from the histogram,
31
* see http://www.dspguide.com/ch2/4.htm
32
*
33
*/
34
class
Histogram
35
{
36
public
:
37
// --- basic methods ---
38
/**
39
* \brief Constructor
40
* \param binWidth width of the histogram "bin".
41
*/
42
Histogram
(
double
binWidth);
43
Histogram
();
44
45
// Methods for Getting the Histogram Results
46
/**
47
* \brief Returns the number of bins in the histogram.
48
* \return the number of bins in the histogram
49
*/
50
uint32_t
GetNBins
()
const
;
51
/**
52
* \brief Returns the bin start, i.e., index*binWidth
53
* \param index the bin index
54
* \return the bin start
55
*/
56
double
GetBinStart
(
uint32_t
index)
const
;
57
/**
58
* \brief Returns the bin end, i.e., (index+1)*binWidth
59
* \param index the bin index
60
* \return the bin start
61
*/
62
double
GetBinEnd
(
uint32_t
index)
const
;
63
/**
64
* \brief Returns the bin width.
65
*
66
* Note that all the bins have the same width.
67
*
68
* \param index the bin index
69
* \return the bin width
70
*/
71
double
GetBinWidth
(
uint32_t
index)
const
;
72
/**
73
* \brief Set the bin width.
74
*
75
* Note that you can change the bin width only if the histogram is empty.
76
*
77
* \param binWidth the bin width
78
*/
79
void
SetDefaultBinWidth
(
double
binWidth);
80
/**
81
* \brief Get the number of data added to the bin.
82
* \param index the bin index
83
* \return the number of data added to the bin
84
*/
85
uint32_t
GetBinCount
(
uint32_t
index)
const
;
86
87
// Method for adding values
88
/**
89
* \brief Add a value to the histogram
90
* \param value the value to add
91
*/
92
void
AddValue
(
double
value);
93
94
/**
95
* Clear the histogram content.
96
*/
97
void
Clear
();
98
99
/**
100
* \brief Serializes the results to an std::ostream in XML format.
101
* \param os the output stream
102
* \param indent number of spaces to use as base indentation level
103
* \param elementName name of the element to serialize.
104
*/
105
void
SerializeToXmlStream
(std::ostream& os, uint16_t indent, std::string elementName)
const
;
106
107
private
:
108
std::vector<uint32_t>
m_histogram
;
//!< Histogram data
109
double
m_binWidth
;
//!< Bin width
110
};
111
112
}
// namespace ns3
113
114
#endif
/* NS3_HISTOGRAM_H */
ns3::Histogram
Class used to store data and make an histogram of the data frequency.
Definition
histogram.h:35
ns3::Histogram::Clear
void Clear()
Clear the histogram content.
Definition
histogram.cc:85
ns3::Histogram::GetBinWidth
double GetBinWidth(uint32_t index) const
Returns the bin width.
Definition
histogram.cc:50
ns3::Histogram::GetBinCount
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
Definition
histogram.cc:63
ns3::Histogram::m_histogram
std::vector< uint32_t > m_histogram
Histogram data.
Definition
histogram.h:108
ns3::Histogram::SetDefaultBinWidth
void SetDefaultBinWidth(double binWidth)
Set the bin width.
Definition
histogram.cc:56
ns3::Histogram::m_binWidth
double m_binWidth
Bin width.
Definition
histogram.h:109
ns3::Histogram::GetNBins
uint32_t GetNBins() const
Returns the number of bins in the histogram.
Definition
histogram.cc:32
ns3::Histogram::SerializeToXmlStream
void SerializeToXmlStream(std::ostream &os, uint16_t indent, std::string elementName) const
Serializes the results to an std::ostream in XML format.
Definition
histogram.cc:101
ns3::Histogram::GetBinEnd
double GetBinEnd(uint32_t index) const
Returns the bin end, i.e., (index+1)*binWidth.
Definition
histogram.cc:44
ns3::Histogram::AddValue
void AddValue(double value)
Add a value to the histogram.
Definition
histogram.cc:70
ns3::Histogram::Histogram
Histogram()
Definition
histogram.cc:95
ns3::Histogram::GetBinStart
double GetBinStart(uint32_t index) const
Returns the bin start, i.e., index*binWidth.
Definition
histogram.cc:38
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
stats
model
histogram.h
Generated on Fri Nov 8 2024 13:59:06 for ns-3 by
1.11.0