-
Notifications
You must be signed in to change notification settings - Fork 0
MeanShift
MeanShift is a centroid-based cluster analysis algorithm. MeanShift works by adjusting each point towards a convergence point by taking influence from the set of points. This influence is determined by a kernel, which defines the falloff of influence from any point based on its distance. The influencing points do not shift. These influencing points are referred to as the field. The convergence point is mathematically defined as the nearest local maxima given a graph of the sum of each kernel around the points in the field. MeanShift is calculating these local maxima.
The code below will use MeanShift to cluster the points {0, 1, 8, 10, 12, 22, 24}
with a uniform kernel with a window size of 2
.
using ClusterF_ck.Shapes;
using ClusterF_ck.Kernels;
// Make an alias "MS" for the static class MeanShift, which contains the MeanShift clustering methods.
using MS = ClusterF_ck.MeanShift.MeanShift;
double[] points = new double[] {0, 1, 8, 10, 12, 22, 24};
UniformKernel kernel = new UniformKernel(2);
MeanShiftCluster<double>[] clusters = MS.Cluster<double, DoubleShape>(points, kernel);
The value of clusters
will be 3 clusters with centroids {0.5, 10, 23}
and weights {2, 3, 2}
indicating how many points make that cluster. The currently implementation will not track which points make up those cluster.
The namespace ClusterF_ck.Shapes
is included because it contains a collection of ISpace<T>
implementations that can be used to compare points. Currently, it only contains definitions of Euclidean space for float
, double
, Vector2
, Vector3
, and Vector4
. If you want to cluster over a different type or in a Non-Euclidean space, you can always define your own ISpace<T>
.
The namespace ClusterF_ck.Kernel
is included because it contains a collection of IKernel
implementations that can be used to adjust a value according to a distribution. Currently, it contains a UniformKernel
, Linear Kernel
, and GuassianKernel
.