Click or drag to resize
Accord.NET (logo)

VoronoiIterationT Class

k-Medoids clustering using Voronoi iteration algorithm.
Inheritance Hierarchy

Namespace:  Accord.MachineLearning
Assembly:  Accord.MachineLearning (in Accord.MachineLearning.dll) Version: 3.8.0
public class VoronoiIteration<T> : KMedoids<T>
Request Example View Source

Type Parameters


The VoronoiIterationT type exposes the following members.

Public propertyClusters
Gets the clusters found by k-Medoids.
(Inherited from KMedoidsT.)
Public propertyComputeError
Gets or sets whether the clustering distortion error (the average distance between all data points and the cluster centroids) should be computed at the end of the algorithm. The result will be stored in Error. Default is true.
(Inherited from KMedoidsT.)
Public propertyDimension
Gets the dimensionality of the data space.
(Inherited from KMedoidsT.)
Public propertyDistance
Gets or sets the distance function used as a distance metric between data points.
(Inherited from KMedoidsT.)
Public propertyError
Gets the cluster distortion error (the average distance between data points and the cluster centroids) after the last call to this class' Compute methods.
(Inherited from KMedoidsT.)
Public propertyInitialization
Gets or sets the strategy used to initialize the centroids of the clustering algorithm. Default is PamBuild.
(Inherited from KMedoidsT.)
Public propertyIterations
Gets the number of iterations performed in the last call to this class' Compute methods.
(Inherited from KMedoidsT.)
Public propertyK
Gets the number of clusters.
(Inherited from KMedoidsT.)
Public propertyMaxIterations
Gets or sets the maximum number of iterations to be performed by the method. If set to zero, no iteration limit will be imposed. Default is 0.
(Inherited from KMedoidsT.)
Public propertyParallelOptions
Gets or sets the parallelization options for this algorithm.
(Inherited from ParallelLearningBase.)
Public propertyToken
Gets or sets a cancellation token that can be used to cancel the algorithm while it is running.
(Inherited from ParallelLearningBase.)
Public propertyTolerance
Gets or sets the relative convergence threshold for stopping the algorithm. Default is 1e-5.
(Inherited from KMedoidsT.)
Protected methodCompute
Implementation of the Voronoi Iteration algorithm.
(Overrides KMedoidsTCompute(T, Int32, Int32).)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodLearn
Learns a model that can map the given inputs to the desired outputs.
(Inherited from KMedoidsT.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Extension Methods
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)

From Wikipedia:

The k-medoids algorithm is a clustering algorithm related to the k-means algorithm and the medoidshift algorithm. Both the k-means and k-medoids algorithms are partitional (breaking the dataset up into groups) and both attempt to minimize the distance between points labeled to be in a cluster and a point designated as the center of that cluster. In contrast to the k-means algorithm, k-medoids chooses datapoints as centers (medoids or exemplars) and works with a generalization of the Manhattan Norm to define distance between datapoints instead of L2. This method was proposed in 1987[1] for the work with L1 norm and other distances.

Voronoi iteration algorithm (or Lloyd algorithm) is one of possible implementations of the k-medoids clustering. It was suggested in the [2] and [3].

[1] Kaufman, L. and Rousseeuw, P.J. (1987), Clustering by means of Medoids, in Statistical Data Analysis Based on the L1–Norm and Related Methods, edited by Y. Dodge, North-Holland, 405–416. [2] T. Hastie, R. Tibshirani, and J.Friedman.The Elements of Statistical Learning, Springer (2001), 468–469. [3] H.S.Park , C.H.Jun, A simple and fast algorithm for K-medoids clustering, Expert Systems with Applications, 36, (2) (2009), 3336–3341.

How to perform K-Medoids clustering with Voronoi iteration algorithm.
Accord.Math.Random.Generator.Seed = 0;

// Declare some observations
int[][] observations = new int[][]
    new[] { 2, 6 }, // a
    new[] { 3, 4 }, // a
    new[] { 3, 8 }, // a
    new[] { 4, 7 }, // a
    new[] { 6, 2 }, // b
    new[] { 6, 4 }, // b
    new[] { 7, 3 }, // b
    new[] { 7, 4 }, // b
    new[] { 8, 5 }, // b
    new[] { 7, 6 }  // b

// Create a new 2-Medoids algorithm.
var kmedoidsVi = new VoronoiIteration<int>(2, new Manhattan());
kmedoidsVi.MaxIterations = 100;

// Set initial medoids
kmedoidsVi.Clusters.Centroids[0] = observations[1];
kmedoidsVi.Clusters.Centroids[1] = observations[7];

// Compute and retrieve the data centroids
var clusters = kmedoidsVi.Learn(observations);

// Use the centroids to parition all the data
int[] labels = clusters.Decide(observations);
See Also