A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Kmeans< Point > Class Template Referenceabstract

#include <genesis/utils/math/kmeans.hpp>

Detailed Description

template<typename Point>
class genesis::utils::Kmeans< Point >

Definition at line 65 of file utils/math/kmeans.hpp.

Public Member Functions

 Kmeans ()=default
 
 Kmeans (Kmeans const &)=default
 
 Kmeans (Kmeans &&)=default
 
virtual ~Kmeans ()=default
 
std::vector< size_t > const & assignments () const
 
Kmeansassignments (std::vector< size_t > const &value)
 
std::vector< Point > const & centroids () const
 
Kmeanscentroids (std::vector< Point > const &value)
 
void clear ()
 
std::vector< size_t > cluster_sizes () const
 
InitializationStrategy initialization_strategy () const
 
Kmeansinitialization_strategy (InitializationStrategy value)
 
size_t max_iterations () const
 
Kmeansmax_iterations (size_t value)
 
Kmeansoperator= (Kmeans const &)=default
 
Kmeansoperator= (Kmeans &&)=default
 
size_t run (std::vector< Point > const &data, size_t const k)
 

Public Types

enum  InitializationStrategy { kRandomAssignments, kRandomCentroids, kKmeansPlusPlus, kNone }
 
using value_type = Point
 

Classes

struct  ClusteringInfo
 Helper POD that stores the variances and number of data points of each centroid, as well as the distances from all data points to their assigned centroids. More...
 

Protected Member Functions

virtual bool assign_to_centroids (std::vector< Point > const &data, std::vector< Point > const &centroids, std::vector< size_t > &assignments)
 
virtual ClusteringInfo cluster_info (std::vector< Point > const &data, std::vector< size_t > const &assignments, std::vector< Point > const &centroids) const
 
virtual bool data_validation (std::vector< Point > const &data) const
 
virtual double distance (Point const &lhs, Point const &rhs) const =0
 
virtual std::pair< size_t, double > find_nearest_cluster (std::vector< Point > const &centroids, Point const &datum) const
 
virtual void initialize (std::vector< Point > const &data, size_t const k)
 
virtual bool lloyd_step (std::vector< Point > const &data, std::vector< size_t > &assignments, std::vector< Point > &centroids)
 
virtual void post_loop_hook (std::vector< Point > const &data, std::vector< size_t > &assignments, std::vector< Point > &centroids)
 
virtual void pre_loop_hook (std::vector< Point > const &data, std::vector< size_t > &assignments, std::vector< Point > &centroids)
 
virtual bool treat_empty_centroids (std::vector< Point > const &data, std::vector< size_t > &assignments, std::vector< Point > &centroids, std::unordered_set< size_t > const &empty_centroids)
 
virtual void update_centroids (std::vector< Point > const &data, std::vector< size_t > const &assignments, std::vector< Point > &centroids)=0
 

Constructor & Destructor Documentation

Kmeans ( )
default
virtual ~Kmeans ( )
virtualdefault
Kmeans ( Kmeans< Point > const &  )
default
Kmeans ( Kmeans< Point > &&  )
default

Member Function Documentation

virtual bool assign_to_centroids ( std::vector< Point > const &  data,
std::vector< Point > const &  centroids,
std::vector< size_t > &  assignments 
)
inlineprotectedvirtual

Definition at line 311 of file utils/math/kmeans.hpp.

std::vector<size_t> const& assignments ( ) const
inline

Definition at line 160 of file utils/math/kmeans.hpp.

Kmeans& assignments ( std::vector< size_t > const &  value)
inline

Definition at line 165 of file utils/math/kmeans.hpp.

std::vector<Point> const& centroids ( ) const
inline

Definition at line 171 of file utils/math/kmeans.hpp.

Kmeans& centroids ( std::vector< Point > const &  value)
inline

Definition at line 176 of file utils/math/kmeans.hpp.

void clear ( )
inline

Definition at line 195 of file utils/math/kmeans.hpp.

virtual ClusteringInfo cluster_info ( std::vector< Point > const &  data,
std::vector< size_t > const &  assignments,
std::vector< Point > const &  centroids 
) const
inlineprotectedvirtual

Definition at line 357 of file utils/math/kmeans.hpp.

std::vector<size_t> cluster_sizes ( ) const
inline

Definition at line 182 of file utils/math/kmeans.hpp.

virtual bool data_validation ( std::vector< Point > const &  data) const
inlineprotectedvirtual

Definition at line 281 of file utils/math/kmeans.hpp.

virtual double distance ( Point const &  lhs,
Point const &  rhs 
) const
protectedpure virtual
virtual std::pair<size_t, double> find_nearest_cluster ( std::vector< Point > const &  centroids,
Point const &  datum 
) const
inlineprotectedvirtual

Definition at line 338 of file utils/math/kmeans.hpp.

InitializationStrategy initialization_strategy ( ) const
inline

Definition at line 219 of file utils/math/kmeans.hpp.

Kmeans& initialization_strategy ( InitializationStrategy  value)
inline

Definition at line 224 of file utils/math/kmeans.hpp.

virtual void initialize ( std::vector< Point > const &  data,
size_t const  k 
)
inlineprotectedvirtual

Definition at line 236 of file utils/math/kmeans.hpp.

virtual bool lloyd_step ( std::vector< Point > const &  data,
std::vector< size_t > &  assignments,
std::vector< Point > &  centroids 
)
inlineprotectedvirtual

Definition at line 297 of file utils/math/kmeans.hpp.

size_t max_iterations ( ) const
inline

Definition at line 205 of file utils/math/kmeans.hpp.

Kmeans& max_iterations ( size_t  value)
inline

Definition at line 210 of file utils/math/kmeans.hpp.

Kmeans& operator= ( Kmeans< Point > const &  )
default
Kmeans& operator= ( Kmeans< Point > &&  )
default
virtual void post_loop_hook ( std::vector< Point > const &  data,
std::vector< size_t > &  assignments,
std::vector< Point > &  centroids 
)
inlineprotectedvirtual

Definition at line 491 of file utils/math/kmeans.hpp.

virtual void pre_loop_hook ( std::vector< Point > const &  data,
std::vector< size_t > &  assignments,
std::vector< Point > &  centroids 
)
inlineprotectedvirtual

Definition at line 287 of file utils/math/kmeans.hpp.

size_t run ( std::vector< Point > const &  data,
size_t const  k 
)
inline

Definition at line 111 of file utils/math/kmeans.hpp.

virtual bool treat_empty_centroids ( std::vector< Point > const &  data,
std::vector< size_t > &  assignments,
std::vector< Point > &  centroids,
std::unordered_set< size_t > const &  empty_centroids 
)
inlineprotectedvirtual

Definition at line 399 of file utils/math/kmeans.hpp.

virtual void update_centroids ( std::vector< Point > const &  data,
std::vector< size_t > const &  assignments,
std::vector< Point > &  centroids 
)
protectedpure virtual

Member Typedef Documentation

using value_type = Point

Definition at line 73 of file utils/math/kmeans.hpp.

Member Enumeration Documentation

Enumerator
kRandomAssignments 
kRandomCentroids 
kKmeansPlusPlus 
kNone 

Definition at line 75 of file utils/math/kmeans.hpp.


The documentation for this class was generated from the following file: