mlpack  2.0.1
random_partition.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_KMEANS_RANDOM_PARTITION_HPP
16 #define __MLPACK_METHODS_KMEANS_RANDOM_PARTITION_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace kmeans {
22 
29 {
30  public:
33 
45  template<typename MatType>
46  inline static void Cluster(const MatType& data,
47  const size_t clusters,
48  arma::Row<size_t>& assignments)
49  {
50  // Implementation is so simple we'll put it here in the header file.
51  assignments = arma::shuffle(arma::linspace<arma::Row<size_t>>(0,
52  (clusters - 1), data.n_cols));
53  }
54 
56  template<typename Archive>
57  void Serialize(Archive& /* ar */, const unsigned int /* version */) { }
58 };
59 
60 }
61 }
62 
63 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
RandomPartition()
Empty constructor, required by the InitialPartitionPolicy policy.
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).
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
A very simple partitioner which partitions the data randomly into the number of desired clusters...