kmeans.hpp

Go to the documentation of this file.
00001 
00022 #ifndef __MLPACK_METHODS_KMEANS_KMEANS_HPP
00023 #define __MLPACK_METHODS_KMEANS_KMEANS_HPP
00024 
00025 #include <mlpack/core.hpp>
00026 
00027 #include <mlpack/core/metrics/lmetric.hpp>
00028 #include "random_partition.hpp"
00029 #include "max_variance_new_cluster.hpp"
00030 
00031 #include <mlpack/core/tree/binary_space_tree.hpp>
00032 
00033 namespace mlpack {
00034 namespace kmeans  {
00035 
00072 template<typename MetricType = metric::SquaredEuclideanDistance,
00073          typename InitialPartitionPolicy = RandomPartition,
00074          typename EmptyClusterPolicy = MaxVarianceNewCluster>
00075 class KMeans
00076 {
00077  public:
00100   KMeans(const size_t maxIterations = 1000,
00101          const double overclusteringFactor = 1.0,
00102          const MetricType metric = MetricType(),
00103          const InitialPartitionPolicy partitioner = InitialPartitionPolicy(),
00104          const EmptyClusterPolicy emptyClusterAction = EmptyClusterPolicy());
00105 
00106 
00120   template<typename MatType>
00121   void Cluster(const MatType& data,
00122                const size_t clusters,
00123                arma::Col<size_t>& assignments,
00124                const bool initialGuess = false) const;
00125 
00152   template<typename MatType>
00153   void Cluster(const MatType& data,
00154                const size_t clusters,
00155                arma::Col<size_t>& assignments,
00156                MatType& centroids,
00157                const bool initialAssignmentGuess = false,
00158                const bool initialCentroidGuess = false) const;
00159 
00165   template<typename MatType>
00166   void FastCluster(MatType& data,
00167                    const size_t clusters,
00168                    arma::Col<size_t>& assignments) const;
00169 
00171   double OverclusteringFactor() const { return overclusteringFactor; }
00173   double& OverclusteringFactor() { return overclusteringFactor; }
00174 
00176   size_t MaxIterations() const { return maxIterations; }
00178   size_t& MaxIterations() { return maxIterations; }
00179 
00181   const MetricType& Metric() const { return metric; }
00183   MetricType& Metric() { return metric; }
00184 
00186   const InitialPartitionPolicy& Partitioner() const { return partitioner; }
00188   InitialPartitionPolicy& Partitioner() { return partitioner; }
00189 
00191   const EmptyClusterPolicy& EmptyClusterAction() const
00192   { return emptyClusterAction; }
00194   EmptyClusterPolicy& EmptyClusterAction() { return emptyClusterAction; }
00195 
00196  private:
00198   double overclusteringFactor;
00200   size_t maxIterations;
00202   MetricType metric;
00204   InitialPartitionPolicy partitioner;
00206   EmptyClusterPolicy emptyClusterAction;
00207 };
00208 
00209 }; // namespace kmeans
00210 }; // namespace mlpack
00211 
00212 // Include implementation.
00213 #include "kmeans_impl.hpp"
00214 
00215 #endif // __MLPACK_METHODS_MOG_KMEANS_HPP

Generated on 29 Sep 2016 for MLPACK by  doxygen 1.6.1