mlpack 3.4.2
sample_initialization.hpp
Go to the documentation of this file.
1
14#ifndef __MLPACK_METHODS_KMEANS_SAMPLE_INITIALIZATION_HPP
15#define __MLPACK_METHODS_KMEANS_SAMPLE_INITIALIZATION_HPP
16
17#include <mlpack/prereqs.hpp>
19
20namespace mlpack {
21namespace kmeans {
22
24{
25 public:
28
37 template<typename MatType>
38 inline static void Cluster(const MatType& data,
39 const size_t clusters,
40 arma::mat& centroids)
41 {
42 centroids.set_size(data.n_rows, clusters);
43 for (size_t i = 0; i < clusters; ++i)
44 {
45 // Randomly sample a point.
46 const size_t index = math::RandInt(0, data.n_cols);
47 centroids.col(i) = data.col(index);
48 }
49 }
50};
51
52} // namespace kmeans
53} // namespace mlpack
54
55#endif
SampleInitialization()
Empty constructor, required by the InitialPartitionPolicy type definition.
static void Cluster(const MatType &data, const size_t clusters, arma::mat &centroids)
Initialize the centroids matrix by randomly sampling points from the data matrix.
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:110
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
Miscellaneous math random-related routines.