1#ifndef KMEANS_LLOYD_HPP
2#define KMEANS_LLOYD_HPP
9#include "QuickSearch.hpp"
10#include "is_edge_case.hpp"
11#include "compute_centroids.hpp"
60template<
typename Matrix_ = SimpleMatrix<
double,
int>,
typename Cluster_ =
int,
typename Float_ =
double>
65 typedef typename Matrix_::index_type Index_;
91 return internal::process_edge_case(
data,
ncenters, centers, clusters);
94 int iter = 0, status = 0;
103 auto work = data.create_workspace(start, length);
104 for (Index_ obs = start, end = start + length; obs < end; ++obs) {
105 auto dptr = data.get_observation(work);
106 copy[obs] = index.find(dptr);
121 std::copy(
copy.begin(),
copy.end(), clusters);
123 std::fill(sizes.begin(), sizes.end(), 0);
125 ++sizes[clusters[
obs]];
127 internal::compute_centroids(
data,
ncenters, centers, clusters, sizes);
134 return Details<Index_>(std::move(sizes), iter, status);
Report detailed clustering statistics.
Interface for k-means refinement.
Implements the variance partitioning method of Su and Dy (2007).
Definition InitializeVariancePartition.hpp:164
Implements the Lloyd algorithm for k-means clustering.
Definition RefineLloyd.hpp:61
Details< Index_ > run(const Matrix_ &data, Cluster_ ncenters, Float_ *centers, Cluster_ *clusters) const
Definition RefineLloyd.hpp:88
RefineLloyd(RefineLloydOptions options)
Definition RefineLloyd.hpp:71
RefineLloydOptions & get_options()
Definition RefineLloyd.hpp:83
Interface for all k-means refinement algorithms.
Definition Refine.hpp:23
Namespace for k-means clustering.
Definition compute_wcss.hpp:12
void parallelize(int num_workers, Task_ num_tasks, Run_ run_task_range)
Definition parallelize.hpp:28
Utilities for parallelization.
Options for RefineLloyd construction.
Definition RefineLloyd.hpp:25
int num_threads
Definition RefineLloyd.hpp:36
int max_iterations
Definition RefineLloyd.hpp:30