A library for working with phylogenetic and population genetic data.
v0.32.0
Kmeans< Point > Class Template Referenceabstract

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

Detailed Description

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

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

Public Member Functions

 Kmeans ()=default
 
 Kmeans (Kmeans &&)=default
 
 Kmeans (Kmeans const &)=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 ()
 
KmeansClusteringInfo cluster_info (std::vector< Point > const &data) const
 
std::vector< size_t > cluster_sizes () const
 
KmeansInitializationStrategy initialization_strategy () const
 
Kmeansinitialization_strategy (KmeansInitializationStrategy value)
 
size_t max_iterations () const
 
Kmeansmax_iterations (size_t value)
 
Kmeansoperator= (Kmeans &&)=default
 
Kmeansoperator= (Kmeans const &)=default
 
size_t run (std::vector< Point > const &data, size_t const k)
 

Public Types

using value_type = Point
 

Public Attributes

std::function< void(void)> report_initialization
 
std::function< void(size_t i)> report_iteration
 

Protected Member Functions

virtual bool assign_to_centroids (std::vector< Point > const &data, std::vector< Point > const &centroids, std::vector< size_t > &assignments)
 
virtual KmeansClusteringInfo 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() [1/3]

Kmeans ( )
default

◆ ~Kmeans()

virtual ~Kmeans ( )
virtualdefault

◆ Kmeans() [2/3]

Kmeans ( Kmeans< Point > const &  )
default

◆ Kmeans() [3/3]

Kmeans ( Kmeans< Point > &&  )
default

Member Function Documentation

◆ assign_to_centroids()

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

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

◆ assignments() [1/2]

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

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

◆ assignments() [2/2]

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

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

◆ centroids() [1/2]

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

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

◆ centroids() [2/2]

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

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

◆ clear()

void clear ( )
inline

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

◆ cluster_info() [1/2]

KmeansClusteringInfo cluster_info ( std::vector< Point > const &  data) const
inline

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

◆ cluster_info() [2/2]

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

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

◆ cluster_sizes()

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

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

◆ data_validation()

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

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

◆ distance()

virtual double distance ( Point const &  lhs,
Point const &  rhs 
) const
protectedpure virtual

◆ find_nearest_cluster()

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

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

◆ initialization_strategy() [1/2]

KmeansInitializationStrategy initialization_strategy ( ) const
inline

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

◆ initialization_strategy() [2/2]

Kmeans& initialization_strategy ( KmeansInitializationStrategy  value)
inline

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

◆ initialize()

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

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

◆ lloyd_step()

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

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

◆ max_iterations() [1/2]

size_t max_iterations ( ) const
inline

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

◆ max_iterations() [2/2]

Kmeans& max_iterations ( size_t  value)
inline

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

◆ operator=() [1/2]

Kmeans& operator= ( Kmeans< Point > &&  )
default

◆ operator=() [2/2]

Kmeans& operator= ( Kmeans< Point > const &  )
default

◆ post_loop_hook()

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

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

◆ pre_loop_hook()

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

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

◆ run()

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

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

◆ treat_empty_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 
)
inlineprotectedvirtual

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

◆ update_centroids()

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

Member Typedef Documentation

◆ value_type

using value_type = Point

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

Member Data Documentation

◆ report_initialization

std::function<void( void )> report_initialization

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

◆ report_iteration

std::function<void( size_t i )> report_iteration

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


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