21 template <
typename SCALAR>
    23     const bool use_kmeansplusplus_method, 
const size_t nPoints, 
const size_t k,
    24     const size_t dims, 
const SCALAR* points, 
const size_t attempts,
    25     SCALAR* out_center, 
int* out_assignments);
    29 template <
class LIST_OF_VECTORS1, 
class LIST_OF_VECTORS2>
    31     [[maybe_unused]] 
const bool use_kmeansplusplus_method, 
const size_t k,
    32     const LIST_OF_VECTORS1& points, std::vector<int>& assignments,
    33     LIST_OF_VECTORS2* out_centers, 
const size_t attempts)
    37     const size_t N = points.size();
    38     assignments.resize(N);
    39     if (out_centers) out_centers->clear();
    43     const auto it_first = points.begin();
    44     const auto it_end = points.end();
    45     using TInnerVector = 
typename LIST_OF_VECTORS1::value_type;
    46     using TInnerVectorCenters = 
typename LIST_OF_VECTORS2::value_type;
    47     std::vector<typename TInnerVector::value_type> raw_vals;
    48     typename TInnerVector::value_type* trg_ptr = 
nullptr;
    49     for (
typename LIST_OF_VECTORS1::const_iterator it = it_first; it != it_end;
    55             ASSERTMSG_(dims > 0, 
"Dimensionality of points can't be zero.");
    56             raw_vals.resize(N * dims);
    57             trg_ptr = &raw_vals[0];
    62                 size_t(dims) == 
size_t(it->size()),
    63                 "All points must have the same dimensionality.");
    68             dims * 
sizeof(
typename TInnerVector::value_type));
    72     std::vector<typename TInnerVectorCenters::value_type> centers(dims * k);
    74         false, N, k, points.begin()->size(), &raw_vals[0], attempts,
    75         ¢ers[0], &assignments[0]);
    79         const typename TInnerVectorCenters::value_type* center_ptr =
    81         for (
size_t i = 0; i < k; i++)
    83             TInnerVectorCenters c;
    85             for (
size_t j = 0; j < dims; j++) c[j] = *center_ptr++;
    86             out_centers->push_back(c);
   121 template <
class LIST_OF_VECTORS1, 
class LIST_OF_VECTORS2>
   123     const size_t k, 
const LIST_OF_VECTORS1& points,
   124     std::vector<int>& assignments, LIST_OF_VECTORS2* out_centers = 
nullptr,
   125     const size_t attempts = 3)
   128         false , k, points, assignments, out_centers,
   156 template <
class LIST_OF_VECTORS1, 
class LIST_OF_VECTORS2 = LIST_OF_VECTORS1>
   158     const size_t k, 
const LIST_OF_VECTORS1& points,
   159     std::vector<int>& assignments, LIST_OF_VECTORS2* out_centers = 
nullptr,
   160     const size_t attempts = 3)
   163         true , k, points, assignments, out_centers,
 
double kmeans(const size_t k, const LIST_OF_VECTORS1 &points, std::vector< int > &assignments, LIST_OF_VECTORS2 *out_centers=nullptr, const size_t attempts=3)
k-means algorithm to cluster a list of N points of arbitrary dimensionality into exactly K clusters...
 
#define ASSERT_(f)
Defines an assertion mechanism. 
 
double stub_kmeans([[maybe_unused]] const bool use_kmeansplusplus_method, const size_t k, const LIST_OF_VECTORS1 &points, std::vector< int > &assignments, LIST_OF_VECTORS2 *out_centers, const size_t attempts)
 
double kmeanspp(const size_t k, const LIST_OF_VECTORS1 &points, std::vector< int > &assignments, LIST_OF_VECTORS2 *out_centers=nullptr, const size_t attempts=3)
k-means++ algorithm to cluster a list of N points of arbitrary dimensionality into exactly K clusters...
 
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
double internal_kmeans(const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k, const size_t dims, const SCALAR *points, const size_t attempts, SCALAR *out_center, int *out_assignments)
 
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".