MRPT  2.0.1
kmeans.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "math-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/kmeans.h>
13 
14 // This file is just a stub for the k-means++ library so MRPT users don't need
15 // to include those headers too.
16 
17 // Include the kmeans++ library, by David Arthur (darthur@gmail.com), 2009:
18 #include "kmeans++/KMeans.h"
19 
20 using namespace std;
21 using namespace mrpt;
22 using namespace mrpt::math;
23 
24 namespace mrpt::math::detail
25 {
26 /* -------------------------------------------
27  internal_kmeans
28  ------------------------------------------- */
29 template <>
31  [[maybe_unused]] const bool use_kmeansplusplus_method, const size_t nPoints,
32  const size_t k, const size_t dims, const double* points,
33  const size_t attempts, double* out_center, int* out_assignments)
34 {
35  return RunKMeans(
36  nPoints, k, dims, const_cast<double*>(points), attempts, out_center,
37  out_assignments);
38 }
39 
40 template <>
42  [[maybe_unused]] const bool use_kmeansplusplus_method, const size_t nPoints,
43  const size_t k, const size_t dims, const float* points,
44  const size_t attempts, float* out_center, int* out_assignments)
45 {
46  std::vector<double> points_d(nPoints * dims);
47  std::vector<double> centers_d(k * dims);
48  // Convert: float -> double
49  for (size_t i = 0; i < nPoints * dims; i++) points_d[i] = double(points[i]);
50 
51  const double ret = RunKMeans(
52  nPoints, k, dims, &points_d[0], attempts, &centers_d[0],
53  out_assignments);
54 
55  // Convert: double -> float
56  if (out_center)
57  for (size_t i = 0; i < k * dims; i++)
58  out_center[i] = float(centers_d[i]);
59 
60  return ret;
61 }
62 } // namespace mrpt::math::detail
Scalar RunKMeans(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_centers, int *ret_assignment)
double internal_kmeans< float >([[maybe_unused]] const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k, const size_t dims, const float *points, const size_t attempts, float *out_center, int *out_assignments)
Definition: KMeans.cpp:41
STL namespace.
double internal_kmeans< double >([[maybe_unused]] const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k, const size_t dims, const double *points, const size_t attempts, double *out_center, int *out_assignments)
Definition: KMeans.cpp:30
This base provides a set of functions for maths stuff.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020