mean_shift.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_MEAN_SHIFT_MEAN_SHIFT_HPP
14 #define MLPACK_METHODS_MEAN_SHIFT_MEAN_SHIFT_HPP
15 
16 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace meanshift {
23 
47 template<bool UseKernel = false,
48  typename KernelType = kernel::GaussianKernel,
49  typename MatType = arma::mat>
50 class MeanShift
51 {
52  public:
64  MeanShift(const double radius = 0,
65  const size_t maxIterations = 1000,
66  const KernelType kernel = KernelType());
67 
74  double EstimateRadius(const MatType& data, const double ratio = 0.2);
75 
88  void Cluster(const MatType& data,
89  arma::Row<size_t>& assignments,
90  arma::mat& centroids,
91  bool forceConvergence = true,
92  bool useSeeds = true);
93 
95  size_t MaxIterations() const { return maxIterations; }
97  size_t& MaxIterations() { return maxIterations; }
98 
100  double Radius() const { return radius; }
102  void Radius(double radius);
103 
105  const KernelType& Kernel() const { return kernel; }
107  KernelType& Kernel() { return kernel; }
108 
109  private:
123  void GenSeeds(const MatType& data,
124  const double binSize,
125  const int minFreq,
126  MatType& seeds);
127 
136  template<bool ApplyKernel = UseKernel>
137  typename std::enable_if<ApplyKernel, bool>::type
138  CalculateCentroid(const MatType& data,
139  const std::vector<size_t>& neighbors,
140  const std::vector<double>& distances,
141  arma::colvec& centroid);
142 
151  template<bool ApplyKernel = UseKernel>
152  typename std::enable_if<!ApplyKernel, bool>::type
153  CalculateCentroid(const MatType& data,
154  const std::vector<size_t>& neighbors,
155  const std::vector<double>&, /*unused*/
156  arma::colvec& centroid);
157 
163  double radius;
164 
166  size_t maxIterations;
167 
169  KernelType kernel;
170 };
171 
172 } // namespace meanshift
173 } // namespace mlpack
174 
175 // Include implementation.
176 #include "mean_shift_impl.hpp"
177 
178 #endif // MLPACK_METHODS_MEAN_SHIFT_MEAN_SHIFT_HPP
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & MaxIterations()
Set the maximum number of iterations.
Definition: mean_shift.hpp:97
This class implements mean shift clustering.
Definition: mean_shift.hpp:50
double EstimateRadius(const MatType &data, const double ratio=0.2)
Give an estimation of radius based on given dataset.
size_t MaxIterations() const
Get the maximum number of iterations.
Definition: mean_shift.hpp:95
MeanShift(const double radius=0, const size_t maxIterations=1000, const KernelType kernel=KernelType())
Create a mean shift object and set the parameters which mean shift will be run with.
void Cluster(const MatType &data, arma::Row< size_t > &assignments, arma::mat &centroids, bool forceConvergence=true, bool useSeeds=true)
Perform mean shift clustering on the data, returning a list of cluster assignments and centroids...
The standard Gaussian kernel.
KernelType & Kernel()
Modify the kernel.
Definition: mean_shift.hpp:107
double Radius() const
Get the radius.
Definition: mean_shift.hpp:100
const KernelType & Kernel() const
Get the kernel.
Definition: mean_shift.hpp:105