1#ifndef KMEANS_INITIALIZE_RANDOM_HPP
2#define KMEANS_INITIALIZE_RANDOM_HPP
9#include "copy_into_array.hpp"
11#include "aarand/aarand.hpp"
39template<
class Matrix_ = SimpleMatrix<
double,
int>,
typename Cluster_ =
int,
typename Float_ =
double>
65 Cluster_
run(
const Matrix_& data, Cluster_ ncenters, Float_* centers)
const {
66 std::mt19937_64 eng(my_options.
seed);
67 auto nobs = data.num_observations();
68 std::vector<typename Matrix_::index_type> chosen(std::min(nobs,
static_cast<typename Matrix_::index_type
>(ncenters)));
69 aarand::sample(nobs, ncenters, chosen.begin(), eng);
70 internal::copy_into_array(data, chosen, centers);
Interface for k-means initialization.
Initialize by sampling random observations without replacement.
Definition InitializeRandom.hpp:40
Cluster_ run(const Matrix_ &data, Cluster_ ncenters, Float_ *centers) const
Definition InitializeRandom.hpp:65
InitializeRandom(InitializeRandomOptions options)
Definition InitializeRandom.hpp:48
InitializeRandomOptions & get_options()
Definition InitializeRandom.hpp:60
InitializeRandom()=default
Base class for initialization algorithms.
Definition Initialize.hpp:22
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