KMeansW {lsbclust}R Documentation

C++ Function for Weighted K-Means

Description

This function does a weighted K-means clustering.

Usage

ComputeMeans(cm, data, weight, nclust)

AssignCluster(data, weight, M, nclust)

KMeansW(nclust, start, data, weight, eps = 1e-08, IterMax = 100L)

Arguments

cm

Numeric vector of class indicators.

data

The concatenated data, with N rows and M columns. Currently, the columns are clustered.

weight

The vector of length nrows(data) with weights with nonnegative elements.

nclust

The number of clusters.

M

Matrix of cluster means.

start

The current cluster membership vector.

eps

Numerical absolute convergence criteria for the K-means.

IterMax

Integer giving the maximum number of iterations allowed for the K-means.

Value

A list with the folowing values.

centers

the nclust by M matrix centers of cluster means.

cluster

vector of length N with cluster memberships.

loss

vector of length IterMax with the first entries containing the loss.

iterations

the number of iterations used (corresponding to the number of nonzero entries in loss)

Examples

set.seed(1)
clustmem <- sample.int(n = 10, size = 100, replace = TRUE)
mat <- rbind(matrix(rnorm(30*4, mean = 3), nrow = 30), 
             matrix(rnorm(30*4, mean = -2), nrow = 30), 
             matrix(rnorm(40*4, mean = 0), nrow = 40))
wt <- runif(100)
testMeans <- lsbclust:::ComputeMeans(cm = clustmem, data = mat, weight = wt, nclust = 3)
testK <- lsbclust:::KMeansW(start = clustmem, data = mat, weight = wt, nclust = 3)

[Package lsbclust version 1.1 Index]