A toolkit for working with phylogenetic data.
v0.20.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree/mass_tree/kmeans.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_TREE_MASS_TREE_KMEANS_H_
2 #define GENESIS_TREE_MASS_TREE_KMEANS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 Lucas Czech
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 namespace genesis {
37 namespace tree {
38 
39 // =================================================================================================
40 // Forward Declarations
41 // =================================================================================================
42 
43 class Tree;
44 class TreeNode;
45 class TreeEdge;
46 
47 using MassTree = Tree;
48 
49 // =================================================================================================
50 // Mass Tree Kmeans
51 // =================================================================================================
52 
54  : public utils::Kmeans< MassTree >
55 {
56 public:
57 
58  // -------------------------------------------------------------------------
59  // Typedefs and Constants
60  // -------------------------------------------------------------------------
61 
62  using Point = MassTree;
63 
64  // -------------------------------------------------------------------------
65  // Constructors and Rule of Five
66  // -------------------------------------------------------------------------
67 
68  MassTreeKmeans() = default;
69  virtual ~MassTreeKmeans() = default;
70 
71  MassTreeKmeans( MassTreeKmeans const& ) = default;
72  MassTreeKmeans( MassTreeKmeans&& ) = default;
73 
74  MassTreeKmeans& operator= ( MassTreeKmeans const& ) = default;
76 
77  // -------------------------------------------------------------------------
78  // Settings
79  // -------------------------------------------------------------------------
80 
81  size_t accumulate_centroid_masses() const;
82  void accumulate_centroid_masses( size_t value );
83 
84  // -------------------------------------------------------------------------
85  // Default K-Means Functions
86  // -------------------------------------------------------------------------
87 
88 private:
89 
90  virtual void pre_loop_hook(
91  std::vector<Point> const& data,
92  std::vector<size_t>& assignments,
93  std::vector<Point>& centroids
94  ) override;
95 
96  virtual bool data_validation( std::vector<Point> const& data ) const override;
97 
98  virtual void update_centroids(
99  std::vector<Point> const& data,
100  std::vector<size_t> const& assignments,
101  std::vector<Point>& centroids
102  ) override;
103 
104  virtual double distance( Point const& lhs, Point const& rhs ) const override;
105 
106  // -------------------------------------------------------------------------
107  // Data
108  // -------------------------------------------------------------------------
109 
110  size_t accumulate_centroid_masses_ = 1;
111 
112 };
113 
114 } // namespace tree
115 } // namespace genesis
116 
117 #endif // include guard
std::vector< MassTree > const & centroids() const
size_t accumulate_centroid_masses() const
Definition: kmeans.cpp:54
Tree MassTree
Alias for a Tree that stores masses on its TreeEdges.
Class for representing phylogenetic trees.
Definition: tree/tree.hpp:95
MassTreeKmeans & operator=(MassTreeKmeans const &)=default
virtual ~MassTreeKmeans()=default
std::vector< size_t > const & assignments() const