mlpack 3.4.2
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
18namespace mlpack {
19namespace 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 unsigned int /* version */) { }
56};
57
58} // namespace kmeans
59} // namespace mlpack
60
61#endif
A very simple partitioner which partitions the data randomly into the number of desired clusters.
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.
void serialize(Archive &, const unsigned int)
Serialize the partitioner (nothing to do).
RandomPartition()
Empty constructor, required by the InitialPartitionPolicy policy.
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.