A library for working with phylogenetic and population genetic data.
v0.32.0
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-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 "
genesis/utils/math/kmeans.hpp
"
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
59
class
EuclideanKmeans
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
()
override
=
default
;
76
77
EuclideanKmeans
(
EuclideanKmeans
const
& ) =
default
;
78
EuclideanKmeans
(
EuclideanKmeans
&& ) =
default
;
79
80
EuclideanKmeans
&
operator=
(
EuclideanKmeans
const
& ) =
default
;
81
EuclideanKmeans
&
operator=
(
EuclideanKmeans
&& ) =
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
genesis::utils::EuclideanKmeans::EuclideanKmeans
EuclideanKmeans(size_t dimensions)
Definition:
euclidean_kmeans.cpp:47
genesis::utils::Kmeans< std::vector< double > >::assignments
std::vector< size_t > const & assignments() const
Definition:
utils/math/kmeans.hpp:174
genesis::utils::EuclideanKmeans::~EuclideanKmeans
virtual ~EuclideanKmeans() override=default
genesis::utils::Kmeans
Definition:
utils/math/kmeans.hpp:91
kmeans.hpp
genesis::utils::EuclideanKmeans::Point
std::vector< double > Point
Definition:
euclidean_kmeans.hpp:68
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::Kmeans< std::vector< double > >::centroids
std::vector< std::vector< double > > const & centroids() const
Definition:
utils/math/kmeans.hpp:185
genesis::utils::EuclideanKmeans::operator=
EuclideanKmeans & operator=(EuclideanKmeans const &)=default
genesis::utils::EuclideanKmeans
Definition:
euclidean_kmeans.hpp:59
lib
genesis
utils
math
euclidean_kmeans.hpp
Generated on Mon Aug 5 2024 16:57:51 for genesis by
1.8.17