norm.sim.ksc: K-means algorithm based on cosine distance

Description Usage Arguments Value Author(s) Examples

View source: R/norm.sim.ksc.R

Description

On the assumption that the two samples are already normalized to have L2 norm as 1, cosine distance is defined as 1 - inner product of the two samples.

Usage

1
norm.sim.ksc(A, k, init.cen = NULL, init.mem = NULL, iter.max = 100)

Arguments

A

n by p matrix, each row is a sample

k

the number of clusters

init.cen

initial cluster centers

init.mem

initial cluster member assignment

iter.max

the maximum number of iteration

Value

A list will be returned with components : cluster: A vector of integers indicating the cluster to which each point is allocated. centers: A matrix of cluster centres size: The number of points in each cluster

Author(s)

Jungsuk Kwac

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
###############
## test code
## 4 classes: a1,a2,a3,a4
## for each class, 20 samples
###############
n = 20; p = 32
a1 = 10*sin(0.1*(1:p))
a2 = 10*cos(0.1*(1:p))+10
a3 = c(1:(p/2),(p/2):1)
a4 = c((p/2):1,1:(p/2))
A = c()
for (i in 1:n){
  A = rbind(A,a1+rnorm(p),a2+rnorm(p),a3+rnorm(p),a4+rnorm(p))
}
res = norm.sim.ksc(quick.norm(A,1),4)

Example output



akmeans documentation built on May 2, 2019, 2:40 a.m.