## simulated data
set.seed(1)
x.coord = seq(0,1,0.01)
x <- matrix(ncol = length(x.coord), nrow = 100)
labels <- matrix(ncol = 100, nrow = 1)
centers <- matrix(ncol = length(x.coord), nrow = 4)
centers[1, ] <- abs(x.coord)-0.5
centers[2, ] <- (abs(x.coord-0.5))^2 - 0.8
centers[3, ] <- -(abs(x.coord-0.5))^2 + 0.7
centers[4, ] <- 0.75*sin(8*pi*abs(x.coord))
for(i in 1:4){
for(j in 1:25){
labels[25*(i-1) + j] <- i
if(i == 1){x[25*(i-1) + j, ] <- abs(x.coord)-0.5 +
rnorm(length(x.coord),0,1.5)}
if(i == 2){x[25*(i-1) + j, ] <- (abs(x.coord-0.5))^2 - 0.8 +
rnorm(length(x.coord),0,1.5)}
if(i == 3){x[25*(i-1) + j, ] <- -(abs(x.coord-0.5))^2 + 0.7 +
rnorm(length(x.coord),0,1.5)}
if(i == 4){x[25*(i-1) + j, ] <- 0.75*sin(8*pi*abs(x.coord)) +
rnorm(length(x.coord),0,1.5)}
}
}
plotKmeansClustering(x, kmeans(x,4))
plotKmeansClustering(x, brik(x,4)$km)
plotKmeansClustering(x, fabrik(x,4)$km)
plotKmeansClustering(x, fabrik(x,4,degFr=10)$km)
Run the code above in your browser using DataLab