1#ifndef KMEANS_INITIALIZE_RANDOM_HPP
2#define KMEANS_INITIALIZE_RANDOM_HPP
9#include "copy_into_array.hpp"
11#include "aarand/aarand.hpp"
42template<
typename Index_,
typename Data_,
typename Cluster_,
typename Float_,
class Matrix_ = Matrix<Index_, Data_> >
71 Cluster_
run(
const Matrix_& data, Cluster_ ncenters, Float_* centers)
const {
72 std::mt19937_64 eng(my_options.
seed);
73 auto nobs = data.num_observations();
74 std::vector<Index_> chosen(std::min(nobs,
static_cast<Index_
>(ncenters)));
75 aarand::sample(nobs, ncenters, chosen.begin(), eng);
76 internal::copy_into_array(data, chosen, centers);
Interface for k-means initialization.
Initialize by sampling random observations without replacement.
Definition InitializeRandom.hpp:43
InitializeRandom()=default
InitializeRandom(InitializeRandomOptions options)
Definition InitializeRandom.hpp:51
InitializeRandomOptions & get_options()
Definition InitializeRandom.hpp:63
Interface for k-means initialization algorithms.
Definition Initialize.hpp:27
virtual Cluster_ run(const Matrix_ &data, Cluster_ num_centers, Float_ *centers) const =0
Namespace for k-means clustering.
Definition compute_wcss.hpp:12
Options to use for InitializeRandom.
Definition InitializeRandom.hpp:24
uint64_t seed
Definition InitializeRandom.hpp:28