A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
euclidean_kmeans.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_MATH_EUCLIDEAN_KMEANS_H_
2 #define GENESIS_UTILS_MATH_EUCLIDEAN_KMEANS_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 
35 
36 #include <algorithm>
37 #include <cassert>
38 #include <cstddef>
39 #include <functional>
40 #include <limits>
41 #include <random>
42 #include <stdexcept>
43 #include <string>
44 #include <unordered_set>
45 #include <utility>
46 #include <vector>
47 
48 #ifdef GENESIS_OPENMP
49 # include <omp.h>
50 #endif
51 
52 namespace genesis {
53 namespace utils {
54 
55 // =================================================================================================
56 // Euclidean K-Means Specialization
57 // =================================================================================================
58 
60  : public Kmeans< std::vector<double> >
61 {
62 public:
63 
64  // -------------------------------------------------------------------------
65  // Typedefs and Constants
66  // -------------------------------------------------------------------------
67 
68  using Point = std::vector<double>;
69 
70  // -------------------------------------------------------------------------
71  // Constructors and Rule of Five
72  // -------------------------------------------------------------------------
73 
74  EuclideanKmeans( size_t dimensions );
75  virtual ~EuclideanKmeans() = default;
76 
77  EuclideanKmeans( EuclideanKmeans const& ) = default;
78  EuclideanKmeans( EuclideanKmeans&& ) = default;
79 
80  EuclideanKmeans& operator= ( EuclideanKmeans const& ) = default;
82 
83  // -------------------------------------------------------------------------
84  // Default K-Means Functions
85  // -------------------------------------------------------------------------
86 
87 private:
88 
89  virtual bool data_validation( std::vector<Point> const& data ) const override;
90 
91  virtual void update_centroids(
92  std::vector<Point> const& data,
93  std::vector<size_t> const& assignments,
94  std::vector<Point>& centroids
95  ) override;
96 
97  virtual double distance( Point const& lhs, Point const& rhs ) const override;
98 
99  // -------------------------------------------------------------------------
100  // Data Members
101  // -------------------------------------------------------------------------
102 
103 private:
104 
105  size_t dimensions_;
106 
107 };
108 
109 } // namespace utils
110 } // namespace genesis
111 
112 #endif // include guard
virtual ~EuclideanKmeans()=default
std::vector< std::vector< double > > const & centroids() const
EuclideanKmeans & operator=(EuclideanKmeans const &)=default
std::vector< size_t > const & assignments() const