mlpack
master
|
This class implements mean shift clustering. More...
Public Member Functions | |
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. More... | |
void | Cluster (const MatType &data, arma::Col< size_t > &assignments, arma::mat ¢roids, bool useSeeds=true) |
Perform mean shift clustering on the data, returning a list of cluster assignments and centroids. More... | |
double | EstimateRadius (const MatType &data, const double ratio=0.2) |
Give an estimation of radius based on given dataset. More... | |
const KernelType & | Kernel () const |
Get the kernel. More... | |
KernelType & | Kernel () |
Modify the kernel. More... | |
size_t | MaxIterations () const |
Get the maximum number of iterations. More... | |
size_t & | MaxIterations () |
Set the maximum number of iterations. More... | |
double | Radius () const |
Get the radius. More... | |
void | Radius (double radius) |
Set the radius. More... | |
Private Member Functions | |
template<bool ApplyKernel = UseKernel> | |
std::enable_if< ApplyKernel, bool >::type | CalculateCentroid (const MatType &data, const std::vector< size_t > &neighbors, const std::vector< double > &distances, arma::colvec ¢roid) |
Use kernel to calculate new centroid given dataset and valid neighbors. More... | |
template<bool ApplyKernel = UseKernel> | |
std::enable_if<!ApplyKernel, bool >::type | CalculateCentroid (const MatType &data, const std::vector< size_t > &neighbors, const std::vector< double > &, arma::colvec ¢roid) |
Use mean to calculate new centroid given dataset and valid neighbors. More... | |
void | GenSeeds (const MatType &data, const double binSize, const int minFreq, MatType &seeds) |
To speed up, we can generate some seeds from data set and use them as initial centroids rather than all the points in the data set. More... | |
Private Attributes | |
KernelType | kernel |
Instantiated kernel. More... | |
size_t | maxIterations |
Maximum number of iterations before giving up. More... | |
double | radius |
If distance of two centroids is less than radius, one will be removed. More... | |
This class implements mean shift clustering.
For each point in dataset, apply mean shift algorithm until maximum iterations or convergence. Then remove duplicate centroids.
A simple example of how to run mean shift clustering is shown below.
UseKernel | Use kernel or mean to calculate new centroid. If false, KernelType will be ignored. |
KernelType | The kernel to use. |
MatType | The type of matrix the data is stored in. |
Definition at line 49 of file mean_shift.hpp.
mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::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.
radius | If distance of two centroids is less than it, one will be removed. If this value isn't positive, an estimation will be given when clustering. |
maxIterations | Maximum number of iterations allowed before giving up iterations will terminate. |
kernel | Optional KernelType object. |
|
private |
Use kernel to calculate new centroid given dataset and valid neighbors.
data | The whole dataset |
neighbors | Valid neighbors |
distances | Distances to neighbors centroid Store calculated centroid |
Referenced by mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Kernel().
|
private |
Use mean to calculate new centroid given dataset and valid neighbors.
data | The whole dataset |
neighbors | Valid neighbors |
distances | Distances to neighbors centroid Store calculated centroid |
void mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Cluster | ( | const MatType & | data, |
arma::Col< size_t > & | assignments, | ||
arma::mat & | centroids, | ||
bool | useSeeds = true |
||
) |
Perform mean shift clustering on the data, returning a list of cluster assignments and centroids.
MatType | Type of matrix. |
data | Dataset to cluster. |
assignments | Vector to store cluster assignments in. |
centroids | Matrix in which centroids are stored. |
double mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::EstimateRadius | ( | const MatType & | data, |
const double | ratio = 0.2 |
||
) |
Give an estimation of radius based on given dataset.
data | Dataset for estimation. |
ratio | Percentage of dataset to use for nearest neighbor search. |
|
private |
To speed up, we can generate some seeds from data set and use them as initial centroids rather than all the points in the data set.
The basic idea here is that we will place our points into hypercube bins of side length binSize, and any bins that contain fewer than minFreq points will be removed as possible seeds. Usually, 1 is a sufficient parameter for minFreq, and the bin size can be set equal to the estimated radius.
data | The reference data set. |
binSize | Width of hypercube bins. |
minFreq | Minimum number of points in bin. |
seed | Matrix to store generated seeds in. |
Referenced by mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Kernel().
|
inline |
Get the kernel.
Definition at line 100 of file mean_shift.hpp.
References mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::kernel.
|
inline |
Modify the kernel.
Definition at line 102 of file mean_shift.hpp.
References mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::CalculateCentroid(), mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::GenSeeds(), and mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::kernel.
|
inline |
Get the maximum number of iterations.
Definition at line 90 of file mean_shift.hpp.
References mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::maxIterations.
|
inline |
Set the maximum number of iterations.
Definition at line 92 of file mean_shift.hpp.
References mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::maxIterations.
|
inline |
Get the radius.
Definition at line 95 of file mean_shift.hpp.
References mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::radius.
void mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Radius | ( | double | radius | ) |
Set the radius.
|
private |
Instantiated kernel.
Definition at line 164 of file mean_shift.hpp.
Referenced by mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Kernel().
|
private |
Maximum number of iterations before giving up.
Definition at line 161 of file mean_shift.hpp.
Referenced by mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::MaxIterations().
|
private |
If distance of two centroids is less than radius, one will be removed.
Points with distance to current centroid less than radius will be used to calculate new centroid.
Definition at line 158 of file mean_shift.hpp.
Referenced by mlpack::meanshift::MeanShift< UseKernel, KernelType, MatType >::Radius().