28 #ifndef mrpt_math_kmeans_H
29 #define mrpt_math_kmeans_H
40 template <
typename SCALAR>
42 const bool use_kmeansplusplus_method,
47 const size_t attempts,
53 template <
class LIST_OF_VECTORS1,
class LIST_OF_VECTORS2>
55 const bool use_kmeansplusplus_method,
57 const LIST_OF_VECTORS1 & points,
58 std::vector<int> &assignments,
59 LIST_OF_VECTORS2 *out_centers,
65 const size_t N = points.size();
66 assignments.resize(N);
67 if (out_centers) out_centers->clear();
76 std::vector<typename TInnerVector::value_type> raw_vals;
83 ASSERTMSG_(dims>0,
"Dimensionality of points can't be zero.")
84 raw_vals.resize(N*dims);
85 trg_ptr = &raw_vals[0];
89 ASSERTMSG_(
size_t(dims)==
size_t(it->size()),
"All points must have the same dimensionality.")
96 std::vector<typename TInnerVectorCenters::value_type> centers(dims*k);
97 const double ret =
detail::internal_kmeans(
false,N,k,points.begin()->size(),&raw_vals[0],attempts,¢ers[0],&assignments[0]);
102 for (
size_t i=0;i<k;i++)
104 TInnerVectorCenters c;
106 for (
size_t j=0;j<dims;j++) c[j]= *center_ptr++;
107 out_centers->push_back(c);
135 template <
class LIST_OF_VECTORS1,
class LIST_OF_VECTORS2>
138 const LIST_OF_VECTORS1 & points,
139 std::vector<int> &assignments,
140 LIST_OF_VECTORS2 *out_centers = NULL,
141 const size_t attempts = 3
163 template <
class LIST_OF_VECTORS1,
class LIST_OF_VECTORS2>
166 const LIST_OF_VECTORS1 & points,
167 std::vector<int> &assignments,
168 LIST_OF_VECTORS2 *out_centers = NULL,
169 const size_t attempts = 3