A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 
38 namespace genesis {
39 namespace utils {
40 
41 // =================================================================================================
42 // Forward Declarations
43 // =================================================================================================
44 
45 class Histogram;
46 
47 // =================================================================================================
48 // Histogram Accumulator
49 // =================================================================================================
50 
63 {
64  // -------------------------------------------------------------------------
65  // Typedefs and Enums
66  // -------------------------------------------------------------------------
67 
68 public:
69 
70  typedef std::map<double, double>::const_iterator const_iterator;
71 
72  // -------------------------------------------------------------------------
73  // Constructors and Rule of Five
74  // -------------------------------------------------------------------------
75 
77 
78  HistogramAccumulator (const std::vector<double>& values, double weight = 1.0);
79 
80  HistogramAccumulator (const std::vector<std::pair<double,double>>& weighted_values);
81 
82  ~HistogramAccumulator() = default;
83 
86 
89 
90  void swap (HistogramAccumulator& other);
91 
92  // -------------------------------------------------------------------------
93  // Accessors
94  // -------------------------------------------------------------------------
95 
96  const_iterator begin() const;
97 
98  const_iterator end() const;
99 
100  // -------------------------------------------------------------------------
101  // Modifiers
102  // -------------------------------------------------------------------------
103 
104  void clear();
105 
106  void increment (double x);
107 
108  void accumulate (double x, double weight);
109 
110  // -------------------------------------------------------------------------
111  // Properties
112  // -------------------------------------------------------------------------
113 
114  double min() const;
115 
116  double max() const;
117 
118  size_t size() const;
119 
120  bool empty() const;
121 
122  size_t added_values() const;
123 
124  // -------------------------------------------------------------------------
125  // Factory Methods
126  // -------------------------------------------------------------------------
127 
129  size_t num_bins,
130  bool integer_ranges = false
131  ) const;
132 
134  size_t num_bins,
135  double min,
136  double max
137  ) const;
138 
139  // -------------------------------------------------------------------------
140  // Data Members
141  // -------------------------------------------------------------------------
142 
143 private:
144 
145  std::map<double, double> values_;
146  size_t added_values_ = 0;
147 };
148 
149 // =================================================================================================
150 // Basic Operators
151 // =================================================================================================
152 
154 {
155  lhs.swap(rhs);
156 }
157 
158 } // namespace utils
159 } // namespace genesis
160 
161 #endif // include guard
Histogram build_uniform_ranges_histogram(size_t num_bins, bool integer_ranges=false) const
void swap(HistogramAccumulator &other)
Definition: accumulator.cpp:62
Histogram class for accumulating and summarizing data.
Definition: histogram.hpp:68
Histogram helper class that collects data and builds a fitting Histogram.
Definition: accumulator.hpp:62
void swap(NexusTaxa &lhs, NexusTaxa &rhs)
Definition: taxa.hpp:207
size_t added_values() const
Return the number of values that have been added to the Accumulator.
void accumulate(double x, double weight)
Definition: accumulator.cpp:97
const_iterator begin() const
Definition: accumulator.cpp:72
std::map< double, double >::const_iterator const_iterator
Definition: accumulator.hpp:70
HistogramAccumulator & operator=(HistogramAccumulator const &)=default