Title: | Cross-Entropy Clustering |
---|---|
Description: | Splits data into Gaussian type clusters using the Cross-Entropy Clustering ('CEC') method. This method allows for the simultaneous use of various types of Gaussian mixture models, for performing the reduction of unnecessary clusters, and for discovering new clusters by splitting them. 'CEC' is based on the work of Spurek, P. and Tabor, J. (2014) <doi:10.1016/j.patcog.2014.03.006>. |
Authors: | Kamieniecki Konrad [aut], Spurek Przemyslaw [ctb], Simon Garnier [cre, ctb] |
Maintainer: | Simon Garnier <[email protected]> |
License: | GPL-3 |
Version: | 0.11.2 |
Built: | 2024-11-10 06:44:24 UTC |
Source: | CRAN |
cec
performs Cross-Entropy Clustering on a data matrix.
See Details
for an explanation of Cross-Entropy Clustering.
cec( x, centers, type = c("covariance", "fixedr", "spherical", "diagonal", "eigenvalues", "mean", "all"), iter.max = 25, nstart = 1, param, centers.init = c("kmeans++", "random"), card.min = "5%", keep.removed = FALSE, interactive = FALSE, threads = 1, split = FALSE, split.depth = 8, split.tries = 5, split.limit = 100, split.initial.starts = 1, readline = TRUE )
cec( x, centers, type = c("covariance", "fixedr", "spherical", "diagonal", "eigenvalues", "mean", "all"), iter.max = 25, nstart = 1, param, centers.init = c("kmeans++", "random"), card.min = "5%", keep.removed = FALSE, interactive = FALSE, threads = 1, split = FALSE, split.depth = 8, split.tries = 5, split.limit = 100, split.initial.starts = 1, readline = TRUE )
x |
A numeric matrix of data. Each row corresponds to a distinct
observation; each column corresponds to a distinct variable/dimension. It
must not contain |
centers |
Either a matrix of initial centers or the number of initial
centers ( If If |
type |
The type (or types) of clustering (density family). This can be either a single value or a vector of length equal to the number of centers. Possible values are: "covariance", "fixedr", "spherical", "diagonal", "eigenvalues", "all" (default). Currently, if the |
iter.max |
The maximum number of iterations of the clustering algorithm. |
nstart |
The number of clusterings to perform (with different initial
centers). Only the best clustering (with the lowest cost) will be returned.
A value grater than 1 is valid only if the If the If the split mode is on ( |
param |
The parameter (or parameters) specific to a particular type of clustering. Not all types of clustering require parameters. The types that require parameter are: "covariance" (matrix parameter), "fixedr" (numeric parameter), "eigenvalues" (vector parameter). This can be a vector or a list (when one of the parameters is a matrix or a vector). |
centers.init |
The method used to automatically initialize the centers. Possible values are: "kmeans++" (default) and "random". |
card.min |
The minimal cluster cardinality. If the number of observations in a cluster becomes lower than card.min, the cluster is removed. This argument can be either an integer number or a string ending with a percent sign (e.g. "5%"). |
keep.removed |
If this parameter is TRUE, the removed clusters will be visible in the results as NA in the "centers" matrix (as well as the corresponding values in the list of covariances). |
interactive |
If |
threads |
The number of threads to use or "auto" to use the default
number of threads (usually the number of available processing units/cores)
when performing multiple starts ( The execution of a single start is always performed by a single thread, thus
for |
split |
If For each start ( |
split.depth |
The cluster subdivision depth used in split mode. Usually,
a value lower than 10 is sufficient (when after each splitting, new clusters
have similar sizes). For some data, splitting may often produce clusters
that will not be split further, in that case a higher value of
|
split.tries |
The number of attempts that are made when trying to split a cluster in split mode. |
split.limit |
The maximum number of centers to be discovered in split mode. |
split.initial.starts |
The number of 'standard' starts performed before starting the splitting process. |
readline |
Used only in the interactive mode. If |
Cross-Entropy Clustering (CEC) aims to partition m points into k clusters so as to minimize the cost function (energy E of the clustering) by switching the points between clusters. The presented method is based on the Hartigan approach, where we remove clusters which cardinalities decreased below some small prefixed level.
The energy function E is given by:
where Yi denotes the i-th cluster, p(Yi) is the ratio of the number of points in i-th cluster to the total number points, H(Yi|Fi) is the value of cross-entropy, which represents the internal cluster energy function of data Yi defined with respect to a certain Gaussian density family Fi, which encodes the type of clustering we consider.
The value of the internal energy function H depends on the covariance matrix (computed using maximum-likelihood) and the mean (in case of the mean model) of the points in the cluster. Seven implementations of H have been proposed (expressed as a type - model - of the clustering):
All Gaussian densities. Data will form ellipsoids with arbitrary radiuses.
Gaussian densities with a fixed given covariance. The shapes of clusters depend on the given covariance matrix (additional parameter).
Special case of 'covariance', where the covariance matrix equals rI for the given r (additional parameter). The clustering will have a tendency to divide data into balls with approximate radius proportional to the square root of r.
Spherical (radial) Gaussian densities (covariance proportional to the identity). Clusters will have a tendency to form balls of arbitrary sizes.
Gaussian densities with diagonal covariane. Data will form ellipsoids with radiuses parallel to the coordinate axes.
Gaussian densities with covariance matrix having fixed eigenvalues (additional parameter). The clustering will try to divide the data into fixed-shaped ellipsoids rotated by an arbitrary angle.
Gaussian densities with a fixed mean. Data will be covered with ellipsoids with fixed centers.
The implementation of cec
function allows mixing of clustering types.
An object of class cec
with the following attributes:
data
, cluster
, probability
, centers
,
cost.function
, nclusters
, iterations
, cost
,
covariances
, covariances.model
, time
.
Spurek, P. and Tabor, J. (2014) Cross-Entropy Clustering Pattern Recognition 47, 9 3046–3059
CEC-package
, plot.cec
,
print.cec
## Example of clustering a random data set of 3 Gaussians, with 10 random ## initial centers and a minimal cluster size of 7% of the total data set. m1 <- matrix(rnorm(2000, sd = 1), ncol = 2) m2 <- matrix(rnorm(2000, mean = 3, sd = 1.5), ncol = 2) m3 <- matrix(rnorm(2000, mean = 3, sd = 1), ncol = 2) m3[,2] <- m3[, 2] - 5 m <- rbind(m1, m2, m3) plot(m, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(m, 10, iter.max = 100, card.min = "7%") plot(Z) # Result: Z ## Example of clustering mouse-like set using spherical Gaussian densities. m <- mouseset(n = 7000, r.head = 2, r.left.ear = 1.1, r.right.ear = 1.1, left.ear.dist = 2.5, right.ear.dist = 2.5, dim = 2) plot(m, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(m, 3, type = 'sp', iter.max = 100, nstart = 4, card.min = '5%') plot(Z) # Result: Z ## Example of clustering data set 'Tset' using 'eigenvalues' clustering type. data(Tset) plot(Tset, cex = 0.5, pch = 19) centers <- init.centers(Tset, 2) ## Clustering result: Z <- cec(Tset, 5, 'eigenvalues', param = c(0.02, 0.002), nstart = 4) plot(Z) # Result: Z ## Example of using cec split method starting with a single cluster. data(mixShapes) plot(mixShapes, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(mixShapes, 1, split = TRUE) plot(Z) # Result: Z
## Example of clustering a random data set of 3 Gaussians, with 10 random ## initial centers and a minimal cluster size of 7% of the total data set. m1 <- matrix(rnorm(2000, sd = 1), ncol = 2) m2 <- matrix(rnorm(2000, mean = 3, sd = 1.5), ncol = 2) m3 <- matrix(rnorm(2000, mean = 3, sd = 1), ncol = 2) m3[,2] <- m3[, 2] - 5 m <- rbind(m1, m2, m3) plot(m, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(m, 10, iter.max = 100, card.min = "7%") plot(Z) # Result: Z ## Example of clustering mouse-like set using spherical Gaussian densities. m <- mouseset(n = 7000, r.head = 2, r.left.ear = 1.1, r.right.ear = 1.1, left.ear.dist = 2.5, right.ear.dist = 2.5, dim = 2) plot(m, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(m, 3, type = 'sp', iter.max = 100, nstart = 4, card.min = '5%') plot(Z) # Result: Z ## Example of clustering data set 'Tset' using 'eigenvalues' clustering type. data(Tset) plot(Tset, cex = 0.5, pch = 19) centers <- init.centers(Tset, 2) ## Clustering result: Z <- cec(Tset, 5, 'eigenvalues', param = c(0.02, 0.002), nstart = 4) plot(Z) # Result: Z ## Example of using cec split method starting with a single cluster. data(mixShapes) plot(mixShapes, cex = 0.5, pch = 19) ## Clustering result: Z <- cec(mixShapes, 1, split = TRUE) plot(Z) # Result: Z
Matrix of 2-dimensional points forming four Gaussian clusters.
data(fourGaussians) plot(fourGaussians, cex = 0.5, pch = 19);
data(fourGaussians) plot(fourGaussians, cex = 0.5, pch = 19);
init.centers
automatically initializes the centers of the
clusters before running the Cross-Entropy Clustering algorithm.
init.centers(x, k, method = c("kmeans++", "random"))
init.centers(x, k, method = c("kmeans++", "random"))
x |
A numeric matrix of data. Each row corresponds to a distinct
observation; each column corresponds to a distinct variable/dimension. It
must not contain |
k |
An integer indicating the number of cluster centers to initialize. |
method |
A character string indicating the initialization method to use. It can take the following values:
|
A matrix with k
rows and ncol(x)
columns.
Arthur, D., & Vassilvitskii, S. (2007). k-means++: the advantages of careful seeding. Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, 1027–1035.
## See the examples provided with the cec() function.
## See the examples provided with the cec() function.
Matrix of 2-dimensional points that form circular and elliptical patterns.
data(mixShapes) plot(mixShapes, cex = 0.5, pch = 19);
data(mixShapes) plot(mixShapes, cex = 0.5, pch = 19);
mouseset
generates a cluster of points uniformly
distributed inside a "mouse head" shape.
mouseset( n = 4000, r.head = 2, r.left.ear = 1.1, r.right.ear = 1.1, left.ear.dist = 2.5, right.ear.dist = 2.5, dim = 2 )
mouseset( n = 4000, r.head = 2, r.left.ear = 1.1, r.right.ear = 1.1, left.ear.dist = 2.5, right.ear.dist = 2.5, dim = 2 )
n |
The number of points (default: 4000). |
r.head |
The radius of the mouse's head (default: 2). |
r.left.ear , r.right.ear
|
The radii of the left and right ear of the mouse's head (default: 1.1). |
left.ear.dist , right.ear.dist
|
The distance between the center of the mouse's head and the center of the left and right ear (default: 2.5). |
dim |
The dimensionality of the mouse's head (default: 2). |
A matrix with n
rows and dim
columns.
plot(mouseset())
plot(mouseset())
plot.cec
presents the results from the cec
function in the form of a plot. The colors of the data points represent the
cluster they belong to. Ellipses are drawn to represent the covariance
(of either the model or the sample) of each cluster.
## S3 method for class 'cec' plot( x, col, cex = 0.5, pch = 19, cex.centers = 1, pch.centers = 8, ellipses = TRUE, ellipses.lwd = 4, ellipses.lty = 2, model = TRUE, xlab, ylab, ... )
## S3 method for class 'cec' plot( x, col, cex = 0.5, pch = 19, cex.centers = 1, pch.centers = 8, ellipses = TRUE, ellipses.lwd = 4, ellipses.lty = 2, model = TRUE, xlab, ylab, ... )
x |
|
col |
A specification for the default plotting color of the points in
the clusters. See |
cex |
A numerical value giving the amount by which plotting text and
symbols should be magnified relative to the default. See |
pch |
Either an integer specifying a symbol or a single character to be
used as the default in plotting points. See |
cex.centers |
The same as |
pch.centers |
The same as |
ellipses |
If this parameter is TRUE, covariance ellipses will be drawn. |
ellipses.lwd |
The line width of the covariance ellipses. See |
ellipses.lty |
The line type of the covariance ellipses. See |
model |
If this parameter is TRUE, the model (expected) covariance will be used for each cluster instead of the sample covariance (MLE) of the points in the cluster, when drawing the covariance ellipses. |
xlab |
A label for the x axis. See plot for more details. |
ylab |
A label for the y axis. See plot for more details. |
... |
Additional arguments passed to |
This function returns nothing.
## See the examples provided with the cec() function.
## See the examples provided with the cec() function.
Print objects of class cec
.
## S3 method for class 'cec' print(x, ...)
## S3 method for class 'cec' print(x, ...)
x |
An object produced by |
... |
Ignored. |
This function returns nothing.
## See the examples provided with the cec() function.
## See the examples provided with the cec() function.
Matrix of 2-dimensional points forming three Gaussian clusters.
data(threeGaussians) plot(threeGaussians, cex = 0.5, pch = 19);
data(threeGaussians) plot(threeGaussians, cex = 0.5, pch = 19);
Matrix of 2-dimensional points that form the letter T.
data(Tset) plot(Tset, cex = 0.5, pch = 19);
data(Tset) plot(Tset, cex = 0.5, pch = 19);