A Discrete-Event Network Simulator
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
16namespace 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 */
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 */
Class used to store data and make an histogram of the data frequency.
Definition histogram.h:35
void Clear()
Clear the histogram content.
Definition histogram.cc:85
double GetBinWidth(uint32_t index) const
Returns the bin width.
Definition histogram.cc:50
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
Definition histogram.cc:63
std::vector< uint32_t > m_histogram
Histogram data.
Definition histogram.h:108
void SetDefaultBinWidth(double binWidth)
Set the bin width.
Definition histogram.cc:56
double m_binWidth
Bin width.
Definition histogram.h:109
uint32_t GetNBins() const
Returns the number of bins in the histogram.
Definition histogram.cc:32
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
double GetBinEnd(uint32_t index) const
Returns the bin end, i.e., (index+1)*binWidth.
Definition histogram.cc:44
void AddValue(double value)
Add a value to the histogram.
Definition histogram.cc:70
double GetBinStart(uint32_t index) const
Returns the bin start, i.e., index*binWidth.
Definition histogram.cc:38
Every class exported by the ns3 library is enclosed in the ns3 namespace.