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::math::detail
25 {
26 /* -------------------------------------------
27  internal_kmeans
28  ------------------------------------------- */
29 template <>
31  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
32  const size_t dims, const double* points, const size_t attempts,
33  double* out_center, int* out_assignments)
34 {
35  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
36  return RunKMeans(
37  nPoints, k, dims, const_cast<double*>(points), attempts, out_center,
38  out_assignments);
39 }
40 
41 template <>
43  const bool use_kmeansplusplus_method, const size_t nPoints, const size_t k,
44  const size_t dims, const float* points, const size_t attempts,
45  float* out_center, int* out_assignments)
46 {
47  MRPT_UNUSED_PARAM(use_kmeansplusplus_method);
48  std::vector<double> points_d(nPoints * dims);
49  std::vector<double> centers_d(k * dims);
50  // Convert: float -> double
51  for (size_t i = 0; i < nPoints * dims; i++) points_d[i] = double(points[i]);
52 
53  const double ret = RunKMeans(
54  nPoints, k, dims, &points_d[0], attempts, &centers_d[0],
55  out_assignments);
56 
57  // Convert: double -> float
58  if (out_center)
59  for (size_t i = 0; i < k * dims; i++)
60  out_center[i] = float(centers_d[i]);
61 
62  return ret;
63 }
64 }
65 
66 
Scalar RunKMeans(int n, int k, int d, Scalar *points, int attempts, Scalar *ret_centers, int *ret_assignment)
STL namespace.
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:42
GLsizei const GLfloat * points
Definition: glext.h:5339
This base provides a set of functions for maths stuff.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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:30
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.
Definition: common.h:186



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020