All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
k_means_clustering_example.cpp
Go to the documentation of this file.
1 
8 
10 #include <vector>
11 #include <iostream>
12 
14 #include "paal/utils/functors.hpp"
15 
16 int main() {
17  using Point = std::vector<double>;
18 
19  // sample data
20  unsigned const int NUMBER_OF_CLUSTER = 2;
21  std::vector<Point> points = { { 0, 0 },
22  { 0, 3 },
23  { 4, 0 } };
24  std::vector<std::pair<Point , int>> point_cluster_pair;
25  std::vector<Point> centers(NUMBER_OF_CLUSTER);
26 
27  // solution
28  paal::get_random_centers(points, NUMBER_OF_CLUSTER, centers.begin());
29  paal::k_means(points , centers,
30  back_inserter(point_cluster_pair));
31 
32  for (auto i : point_cluster_pair) {
33  for(auto && j : i.first) {
34  std::cout << j << ",";
35  }
36 
37  std::cout<< " " << i.second << std::endl;
38  }
40 }
auto k_means(Points &&points, Centers &&centers, 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{})
int main()
[K Means Clustering Example]