A library for working with phylogenetic and population genetic data.
v0.27.0
accumulator.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_MATH_HISTOGRAM_ACCUMULATOR_H_
2 #define GENESIS_UTILS_MATH_HISTOGRAM_ACCUMULATOR_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2019 Lucas Czech and HITS gGmbH
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #include <map>
35 #include <utility>
36 #include <vector>
37 #include <cstddef>
38 
39 namespace genesis {
40 namespace utils {
41 
42 // =================================================================================================
43 // Forward Declarations
44 // =================================================================================================
45 
46 class Histogram;
47 
48 // =================================================================================================
49 // Histogram Accumulator
50 // =================================================================================================
51 
64 {
65  // -------------------------------------------------------------------------
66  // Typedefs and Enums
67  // -------------------------------------------------------------------------
68 
69 public:
70 
71  typedef std::map<double, double>::const_iterator const_iterator;
72 
73  // -------------------------------------------------------------------------
74  // Constructors and Rule of Five
75  // -------------------------------------------------------------------------
76 
78 
79  explicit HistogramAccumulator (const std::vector<double>& values, double weight = 1.0);
80 
81  explicit HistogramAccumulator (const std::vector<std::pair<double,double>>& weighted_values);
82 
83  ~HistogramAccumulator() = default;
84 
87 
90 
91  void swap (HistogramAccumulator& other);
92 
93  // -------------------------------------------------------------------------
94  // Accessors
95  // -------------------------------------------------------------------------
96 
97  const_iterator begin() const;
98 
99  const_iterator end() const;
100 
101  // -------------------------------------------------------------------------
102  // Modifiers
103  // -------------------------------------------------------------------------
104 
105  void clear();
106 
107  void increment (double x);
108 
109  void accumulate (double x, double weight);
110 
111  // -------------------------------------------------------------------------
112  // Properties
113  // -------------------------------------------------------------------------
114 
115  double min() const;
116 
117  double max() const;
118 
119  size_t size() const;
120 
121  bool empty() const;
122 
123  size_t added_values() const;
124 
125  // -------------------------------------------------------------------------
126  // Factory Methods
127  // -------------------------------------------------------------------------
128 
130  size_t num_bins,
131  bool integer_ranges = false
132  ) const;
133 
135  size_t num_bins,
136  double min,
137  double max
138  ) const;
139 
140  // -------------------------------------------------------------------------
141  // Data Members
142  // -------------------------------------------------------------------------
143 
144 private:
145 
146  std::map<double, double> values_;
147  size_t added_values_ = 0;
148 };
149 
150 // =================================================================================================
151 // Basic Operators
152 // =================================================================================================
153 
155 {
156  lhs.swap(rhs);
157 }
158 
159 } // namespace utils
160 } // namespace genesis
161 
162 #endif // include guard
genesis::utils::HistogramAccumulator::clear
void clear()
Definition: accumulator.cpp:86
genesis::utils::HistogramAccumulator::added_values
size_t added_values() const
Return the number of values that have been added to the Accumulator.
Definition: accumulator.cpp:133
genesis::utils::HistogramAccumulator::HistogramAccumulator
HistogramAccumulator()
Definition: accumulator.hpp:77
genesis::utils::HistogramAccumulator::empty
bool empty() const
Definition: accumulator.cpp:122
genesis::utils::HistogramAccumulator::~HistogramAccumulator
~HistogramAccumulator()=default
genesis::utils::HistogramAccumulator::accumulate
void accumulate(double x, double weight)
Definition: accumulator.cpp:97
genesis::utils::HistogramAccumulator::increment
void increment(double x)
Definition: accumulator.cpp:92
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::HistogramAccumulator::operator=
HistogramAccumulator & operator=(HistogramAccumulator const &)=default
genesis::utils::HistogramAccumulator::const_iterator
std::map< double, double >::const_iterator const_iterator
Definition: accumulator.hpp:71
genesis::utils::HistogramAccumulator::size
size_t size() const
Definition: accumulator.cpp:117
genesis::utils::HistogramAccumulator::build_uniform_ranges_histogram
Histogram build_uniform_ranges_histogram(size_t num_bins, bool integer_ranges=false) const
Definition: accumulator.cpp:142
genesis::utils::HistogramAccumulator::min
double min() const
Definition: accumulator.cpp:107
genesis::utils::HistogramAccumulator::begin
const_iterator begin() const
Definition: accumulator.cpp:72
genesis::utils::HistogramAccumulator
Histogram helper class that collects data and builds a fitting Histogram.
Definition: accumulator.hpp:63
genesis::utils::HistogramAccumulator::end
const_iterator end() const
Definition: accumulator.cpp:77
genesis::utils::swap
void swap(Optional< T > &x, Optional< T > &y)
Definition: optional.hpp:566
genesis::utils::HistogramAccumulator::max
double max() const
Definition: accumulator.cpp:112
genesis::utils::HistogramAccumulator::swap
void swap(HistogramAccumulator &other)
Definition: accumulator.cpp:62
genesis::utils::Histogram
Histogram class for accumulating and summarizing data.
Definition: histogram.hpp:68