21 using Point = std::vector<double>;
24 const int NUMBER_OF_CLUSTER = 2;
25 std::vector<Point> points = { { 0, 0 },
28 std::vector<Point> centers(NUMBER_OF_CLUSTER);
30 std::vector<std::pair<Point, int>> point_cluster_pairs(points.size());
33 auto centroid = [&](
const std::vector<std::vector<double>> &points) {
34 double best_dist = std::numeric_limits<double>::max();
35 std::vector<double> result;
36 for (
auto && center : points) {
38 for (
auto && point : points) {
42 if (dist < best_dist) {
47 assert(!result.empty());
59 point_cluster_pairs.begin());
auto closest_to(Point &&point, Centers &¢ers)
auto k_means(Points &&points, Centers &¢ers, OutputIterator result, Visitor visitor=Visitor{})
this is solve k_means_clustering problem and return vector of cluster example:
This file contains set of simple useful functors or functor adapters.
auto get_random_centers(Points &&points, int number_of_centers, OutputIterator out, RNG &&rng=std::default_random_engine{})
auto distance_square(RangeLeft &&lrange, RangeRight &&rrange)
int main()
[K Means Clustering Engine Example]