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