random_partition.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_KMEANS_RANDOM_PARTITION_HPP
14 #define MLPACK_METHODS_KMEANS_RANDOM_PARTITION_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace kmeans {
20 
27 {
28  public:
31 
43  template<typename MatType>
44  inline static void Cluster(const MatType& data,
45  const size_t clusters,
46  arma::Row<size_t>& assignments)
47  {
48  // Implementation is so simple we'll put it here in the header file.
49  assignments = arma::shuffle(arma::linspace<arma::Row<size_t>>(0,
50  (clusters - 1), data.n_cols));
51  }
52 
54  template<typename Archive>
55  void serialize(Archive& /* ar */, const uint32_t /* version */) { }
56 };
57 
58 } // namespace kmeans
59 } // namespace mlpack
60 
61 #endif
RandomPartition()
Empty constructor, required by the InitialPartitionPolicy policy.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void serialize(Archive &, const uint32_t)
Serialize the partitioner (nothing to do).
static void Cluster(const MatType &data, const size_t clusters, arma::Row< size_t > &assignments)
Partition the given dataset into the given number of clusters.
A very simple partitioner which partitions the data randomly into the number of desired clusters...