Main MRPT website > C++ reference for MRPT 1.9.9
kmeans.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://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
25 {
26 namespace math
27 {
28 namespace detail
29 {
30 /* -------------------------------------------
31  internal_kmeans
32  ------------------------------------------- */
33 template <>
35  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
36  const size_t dims, const double* points, const size_t attempts,
37  double* out_center, int* out_assignments)
38 {
39  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
40  return RunKMeans(
41  nPoints, k, dims, const_cast<double*>(points), attempts, out_center,
42  out_assignments);
43 }
44 
45 template <>
47  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
48  const size_t dims, const float* points, const size_t attempts,
49  float* out_center, int* out_assignments)
50 {
51  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
52  std::vector<double> points_d(nPoints * dims);
53  std::vector<double> centers_d(k * dims);
54  // Convert: float -> double
55  for (size_t i = 0; i < nPoints * dims; i++) points_d[i] = double(points[i]);
56 
57  const double ret = RunKMeans(
58  nPoints, k, dims, &points_d[0], attempts, &centers_d[0],
59  out_assignments);
60 
61  // Convert: double -> float
62  if (out_center)
63  for (size_t i = 0; i < k * dims; i++)
64  out_center[i] = float(centers_d[i]);
65 
66  return ret;
67 }
68 }
69 }
70 }
kmeans.h
math-precomp.h
points
GLsizei const GLfloat * points
Definition: glext.h:5339
MRPT_UNUSED_PARAM
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::math::detail::internal_kmeans< float >
double internal_kmeans< float >(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:46
RunKMeans
Scalar RunKMeans(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_centers, int *ret_assignment)
Definition: kmeans++/KMeans.cpp:118
KMeans.h
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::math::detail::internal_kmeans< double >
double internal_kmeans< double >(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:34



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST