Lloyd's algorithm
   HOME

TheInfoList



OR:

In
electrical engineering Electrical engineering is an engineering discipline concerned with the study, design, and application of equipment, devices, and systems which use electricity, electronics, and electromagnetism. It emerged as an identifiable occupation in the l ...
and
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, Lloyd's algorithm, also known as Voronoi iteration or relaxation, is an algorithm named after Stuart P. Lloyd for finding evenly spaced sets of points in subsets of
Euclidean space Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidea ...
s and partitions of these subsets into well-shaped and uniformly sized convex cells. Like the closely related ''k''-means clustering algorithm, it repeatedly finds the
centroid In mathematics and physics, the centroid, also known as geometric center or center of figure, of a plane figure or solid figure is the arithmetic mean position of all the points in the surface of the figure. The same definition extends to any ...
of each set in the partition and then re-partitions the input according to which of these centroids is closest. In this setting, the mean operation is an integral over a region of space, and the nearest centroid operation results in
Voronoi diagram In mathematics, a Voronoi diagram is a partition of a plane into regions close to each of a given set of objects. In the simplest case, these objects are just finitely many points in the plane (called seeds, sites, or generators). For each seed ...
s. Although the algorithm may be applied most directly to the
Euclidean plane In mathematics, the Euclidean plane is a Euclidean space of dimension two. That is, a geometric setting in which two real quantities are required to determine the position of each point ( element of the plane), which includes affine notions ...
, similar algorithms may also be applied to higher-dimensional spaces or to spaces with other non-Euclidean metrics. Lloyd's algorithm can be used to construct close approximations to
centroidal Voronoi tessellation In geometry, a centroidal Voronoi tessellation (CVT) is a special type of Voronoi tessellation in which the generating point of each Voronoi cell is also its centroid (center of mass). It can be viewed as an optimal partition corresponding to an ...
s of the input, which can be used for quantization,
dithering Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is often ...
, and
stippling Stippling is the creation of a pattern simulating varying degrees of solidity or shading by using small dots. Such a pattern may occur in nature and these effects are frequently emulated by artists. Art In printmaking, stipple engraving is ...
. Other applications of Lloyd's algorithm include smoothing of triangle meshes in the
finite element method The finite element method (FEM) is a popular method for numerically solving differential equations arising in engineering and mathematical modeling. Typical problem areas of interest include the traditional fields of structural analysis, heat ...
.


History

The algorithm was first proposed by Stuart P. Lloyd of
Bell Labs Nokia Bell Labs, originally named Bell Telephone Laboratories (1925–1984), then AT&T Bell Laboratories (1984–1996) and Bell Labs Innovations (1996–2007), is an American industrial research and scientific development company owned by mul ...
in 1957 as a technique for
pulse-code modulation Pulse-code modulation (PCM) is a method used to digitally represent sampled analog signals. It is the standard form of digital audio in computers, compact discs, digital telephony and other digital audio applications. In a PCM stream, the ...
. Lloyd's work became widely circulated but remained unpublished until 1982. A similar algorithm was developed independently by Joel Max and published in 1960, which is why the algorithm is sometimes referred as the Lloyd-Max algorithm.


Algorithm description

Lloyd's algorithm starts by an initial placement of some number ''k'' of point sites in the input domain. In mesh-smoothing applications, these would be the vertices of the mesh to be smoothed; in other applications they may be placed at random or by intersecting a uniform triangular mesh of the appropriate size with the input domain. It then repeatedly executes the following relaxation step: * The
Voronoi diagram In mathematics, a Voronoi diagram is a partition of a plane into regions close to each of a given set of objects. In the simplest case, these objects are just finitely many points in the plane (called seeds, sites, or generators). For each seed ...
of the ''k'' sites is computed. * Each cell of the Voronoi diagram is integrated, and the centroid is computed. * Each site is then moved to the centroid of its Voronoi cell.


Integration and centroid computation

Because Voronoi diagram construction algorithms can be highly non-trivial, especially for inputs of dimension higher than two, the steps of calculating this diagram and finding the exact centroids of its cells may be replaced by an approximation.


Approximation

A common simplification is to employ a suitable discretization of space like a fine pixel-grid, e.g. the texture buffer in graphics hardware. Cells are materialized as pixels, labeled with their corresponding site-ID. A cell's new center is approximated by averaging the positions of all pixels assigned with the same label. Alternatively, Monte Carlo methods may be used, in which random sample points are generated according to some fixed underlying probability distribution, assigned to the closest site, and averaged to approximate the centroid for each site.


Exact computation

Although embedding in other spaces is also possible, this elaboration assumes
Euclidean space Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidea ...
using the ''L2'' norm and discusses the two most relevant scenarios, which are two, and respectively three dimensions. Since a Voronoi cell is of convex shape and always encloses its site, there exist trivial decompositions into easy integratable simplices: * In two dimensions, the edges of the polygonal cell are connected with its site, creating an umbrella-shaped set of triangles. * In three dimensions, the cell is enclosed by several planar polygons which have to be triangulated first: ** Compute a center for the polygon face, e.g. the average of all its vertices. ** Connecting the vertices of a polygon face with its center gives a planar umbrella-shaped triangulation. ** Trivially, a set of
tetrahedra In geometry, a tetrahedron (plural: tetrahedra or tetrahedrons), also known as a triangular pyramid, is a polyhedron composed of four triangular faces, six straight edges, and four vertex corners. The tetrahedron is the simplest of all th ...
is obtained by connecting triangles of the cell's hull with the cell's site. Integration of a cell and computation of its
centroid In mathematics and physics, the centroid, also known as geometric center or center of figure, of a plane figure or solid figure is the arithmetic mean position of all the points in the surface of the figure. The same definition extends to any ...
(center of mass) is now given as a weighted combination of its simplices' centroids (in the following called \mathbf_i). * Two dimensions: ** For a triangle the centroid can be easily computed, e.g. using
cartesian coordinates A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in ...
. ** Weighting computes as simplex-to-cell area ratios. * Three dimensions: ** The centroid of a tetrahedron is found as the intersection of three bisector planes and can be expressed as a matrix-vector product. ** Weighting computes as simplex-to-cell volume ratios. For a 2D cell with triangular simplices and an accumulated area A_C = \sum_^n a_i (where a_i is the
area of a triangle A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. A triangle with vertices ''A'', ''B'', and ''C'' is denoted \triangle ABC. In Euclidean geometry, any three points, when non-collinear ...
simplex), the new cell centroid computes as: : C = \frac\sum_^\mathbf_i a_i Analogously, for a 3D cell with a volume of V_C = \sum_^n v_i (where v_i is the volume of a tetrahedron simplex), the centroid computes as: : C = \frac\sum_^\mathbf_i v_i


Convergence

Each time a relaxation step is performed, the points are left in a slightly more even distribution: closely spaced points move farther apart, and widely spaced points move closer together. In one dimension, this algorithm has been shown to converge to a centroidal Voronoi diagram, also named a
centroidal Voronoi tessellation In geometry, a centroidal Voronoi tessellation (CVT) is a special type of Voronoi tessellation in which the generating point of each Voronoi cell is also its centroid (center of mass). It can be viewed as an optimal partition corresponding to an ...
. In higher dimensions, some slightly weaker convergence results are known. The algorithm converges slowly or, due to limitations in numerical precision, may not converge. Therefore, real-world applications of Lloyd's algorithm typically stop once the distribution is "good enough." One common termination criterion is to stop when the maximum distance moved by any site in an iteration falls below a preset threshold. Convergence can be accelerated by over-relaxing the points, which is done by moving each point ω times the distance to the center of mass, typically using a value slightly less than 2 for ω.Xiao, Xiao. "Over-relaxation Lloyd method for computing centroidal Voronoi tessellations." (2010).


Applications

Lloyd's method was originally used for scalar quantization, but it is clear that the method extends for vector quantization as well. As such, it is extensively used in
data compression In information theory, data compression, source coding, or bit-rate reduction is the process of encoding information using fewer bits than the original representation. Any particular compression is either lossy or lossless. Lossless compressio ...
techniques in
information theory Information theory is the scientific study of the quantification, storage, and communication of information. The field was originally established by the works of Harry Nyquist and Ralph Hartley, in the 1920s, and Claude Shannon in the 1940s. ...
. Lloyd's method is used in computer graphics because the resulting distribution has blue noise characteristics (see also
Colors of noise In audio engineering, electronics, physics, and many other fields, the color of noise or noise spectrum refers to the power spectrum of a noise signal (a signal produced by a stochastic process). Different colors of noise have significantly ...
), meaning there are few low-frequency components that could be interpreted as artifacts. It is particularly well-suited to picking sample positions for
dithering Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is often ...
. Lloyd's algorithm is also used to generate dot drawings in the style of
stippling Stippling is the creation of a pattern simulating varying degrees of solidity or shading by using small dots. Such a pattern may occur in nature and these effects are frequently emulated by artists. Art In printmaking, stipple engraving is ...
. In this application, the centroids can be weighted based on a reference image to produce stipple illustrations matching an input image. In the
finite element method The finite element method (FEM) is a popular method for numerically solving differential equations arising in engineering and mathematical modeling. Typical problem areas of interest include the traditional fields of structural analysis, heat ...
, an input domain with a complex geometry is partitioned into elements with simpler shapes; for instance, two-dimensional domains (either subsets of the Euclidean plane or surfaces in three dimensions) are often partitioned into triangles. It is important for the convergence of the finite element methods that these elements be well shaped; in the case of triangles, often elements that are nearly equilateral triangles are preferred. Lloyd's algorithm can be used to smooth a mesh generated by some other algorithm, moving its vertices and changing the connection pattern among its elements in order to produce triangles that are more closely equilateral. These applications typically use a smaller number of iterations of Lloyd's algorithm, stopping it to convergence, in order to preserve other features of the mesh such as differences in element size in different parts of the mesh. In contrast to a different smoothing method,
Laplacian smoothing Laplacian smoothing is an algorithm to smooth a polygonal mesh In 3D computer graphics and solid modeling, a polygon mesh is a collection of , s and s that defines the shape of a polyhedral object. The faces usually consist of triangles (tr ...
(in which mesh vertices are moved to the average of their neighbors' positions), Lloyd's algorithm can change the topology of the mesh, leading to more nearly equilateral elements as well as avoiding the problems with tangling that can arise with Laplacian smoothing. However, Laplacian smoothing can be applied more generally to meshes with non-triangular elements.


Different distances

Lloyd's algorithm is usually used in a
Euclidean space Euclidean space is the fundamental space of geometry, intended to represent physical space. Originally, that is, in Euclid's ''Elements'', it was the three-dimensional space of Euclidean geometry, but in modern mathematics there are Euclidea ...
. The Euclidean distance plays two roles in the algorithm: it is used to define the Voronoi cells, but it also corresponds to the choice of the centroid as the representative point of each cell, since the centroid is the point that minimizes the average squared Euclidean distance to the points in its cell. Alternative distances, and alternative central points than the centroid, may be used instead. For example, used a variant of the
Manhattan metric A taxicab geometry or a Manhattan geometry is a geometry whose usual distance function or metric of Euclidean geometry is replaced by a new metric in which the distance between two points is the sum of the absolute differences of their Cartesian co ...
(with locally varying orientations) to find a tiling of an image by approximately square tiles whose orientation aligns with features of an image, which he used to simulate the construction of tiled
mosaic A mosaic is a pattern or image made of small regular or irregular pieces of colored stone, glass or ceramic, held in place by plaster/mortar, and covering a surface. Mosaics are often used as floor and wall decoration, and were particularly pop ...
s. In this application, despite varying the metric, Hausner continued to use centroids as the representative points of their Voronoi cells. However, for metrics that differ more significantly from Euclidean, it may be appropriate to choose the minimizer of average squared distance as the representative point, in place of the centroid.


See also

* The
Linde–Buzo–Gray algorithm The Linde–Buzo–Gray algorithm (introduced by Yoseph Linde, Andrés Buzo and Robert M. Gray in 1980) is a vector quantization algorithm to derive a good codebook A codebook is a type of document used for gathering and storing cryptography ...
, a generalization of this algorithm for vector quantization * Farthest-first traversal, a different method for generating evenly spaced points in geometric spaces *
Mean shift Mean shift is a non-parametric feature-space mathematical analysis technique for locating the maxima of a density function, a so-called mode-seeking algorithm. Application domains include cluster analysis in computer vision and image processing. ...
, a related method for finding maxima of a density function * K-means++


References

{{reflist, refs= {{citation , last1 = Deussen , first1 = Oliver , last2 = Hiller , first2 = Stefan , last3 = van Overveld , first3 = Cornelius , last4 = Strothotte , first4 = Thomas , doi = 10.1111/1467-8659.00396 , id = Proceedings of
Eurographics Eurographics is a Europe-wide professional computer graphics association. The association supports its members in advancing the state of the art in computer graphics and related fields such as multimedia, scientific visualization and human–compu ...
, issue = 3 , journal = Computer Graphics Forum , pages = 41–50 , title = Floating points: a method for computing stipple drawings , volume = 19 , year = 2000, s2cid = 142991 .
{{citation , last1 = Dickerson , first1 = Matthew T. , author1-link = Matthew T. Dickerson , last2 = Eppstein , first2 = David , author2-link = David Eppstein , last3 = Wortman , first3 = Kevin A. , arxiv = 0812.0607 , contribution = Planar Voronoi diagrams for sums of convex functions, smoothed distance and dilation , doi = 10.1109/ISVD.2010.12 , pages = 13–22 , title = Proc. 7th International Symposium on Voronoi Diagrams in Science and Engineering (ISVD 2010) , year = 2010, s2cid = 15971504 . {{citation , last1 = Du , first1 = Qiang , author1-link = Qiang Du , last2 = Emelianenko , first2 = Maria , author2-link = Maria Emelianenko , last3 = Ju , first3 = Lili , doi = 10.1137/040617364 , journal = SIAM Journal on Numerical Analysis , pages = 102–119 , title = Convergence of the Lloyd algorithm for computing centroidal Voronoi tessellations , volume = 44 , year = 2006, citeseerx = 10.1.1.591.9903. {{citation , last1 = Du , first1 = Qiang , author1-link = Qiang Du , last2 = Faber , first2 = Vance , last3 = Gunzburger , first3 = Max , doi = 10.1137/S0036144599352836 , issue = 4 , journal = SIAM Review , pages = 637–676 , title = Centroidal Voronoi tessellations: applications and algorithms , volume = 41 , year = 1999, bibcode = 1999SIAMR..41..637D. {{citation , last1 = Du , first1 = Qiang , author1-link = Qiang Du , last2 = Gunzburger , first2 = Max , doi = 10.1016/S0096-3003(01)00260-0 , issue = 2–3 , journal = Applied Mathematics and Computation , pages = 591–607 , title = Grid generation and optimization based on centroidal Voronoi tessellations , volume = 133 , year = 2002, citeseerx = 10.1.1.324.5020 . {{citation , last1 = Emelianenko , first1 = Maria , last2 = Ju , first2 = Lili , last3 = Rand , first3 = Alexander , journal = SIAM Journal on Numerical Analysis , pages = 1423–1441 , title = Nondegeneracy and Weak Global Convergence of the Lloyd Algorithm in Rd , volume = 46 , year = 2009 , doi=10.1137/070691334. {{citation , last = Lloyd , first = Stuart P. , doi = 10.1109/TIT.1982.1056489 , issue = 2 , journal = IEEE Transactions on Information Theory , pages = 129–137 , title = Least squares quantization in PCM , volume = 28 , year = 1982. {{citation , last1 = Sabin , first1 = M. J. , last2 = Gray , first2 = R. M. , doi = 10.1109/TIT.1986.1057168 , issue = 2 , journal = IEEE Transactions on Information Theory , pages = 148–155 , title = Global convergence and empirical consistency of the generalized Lloyd algorithm , volume = 32 , year = 1986. {{citation , last = Secord , first = Adrian , contribution = Weighted Voronoi stippling , doi = 10.1145/508530.508537 , pages = 37–43 , publisher = ACM SIGGRAPH , title = Proceedings of the Symposium on Non-Photorealistic Animation and Rendering (NPAR) , year = 2002, s2cid = 12153589 . {{citation , last = Hausner, first = Alejo , doi = 10.1145/383259.383327 , publisher = ACM SIGGRAPH , title = Proceedings of the 28th annual conference on Computer graphics and interactive techniques , pages = 573–580 , contribution = Simulating decorative mosaics , year = 2001, s2cid = 7188986 . {{citation , last = Max, first = Joel , doi = 10.1109/TIT.1960.1057548 , title = Quantizing for minimum distortion , journal = IRE Transactions on Information Theory , pages = 7–12 , volume = 6 , issue = 1 , year = 1960.


External links


DemoGNG.js
Graphical Javascript simulator for LBG algorithm and other models, includes display of Voronoi regions Geometric algorithms Optimization algorithms and methods