# NOT RUN {
# loading flame dataset
data(flame)
# segmentation of the flame dataset in k = 2 partitions
# the 'plot.internals' says to the program do not plot the graphs about
# genetic evolution search and silhouette index
gama.obj <- gama(flame, k = 4, plot.internals = FALSE, generations = 30)
# ** use at least 100 generations for simple datasets and 500 for complex datasets
# it draws the partitions to which each element belongs
gama.plot.partitions(gama.obj)
# }
# NOT RUN {
# loads data about CPU execution metrics of a distributed
# version of Alternating Least Squares (ALS) algorithm
data(cpu.als)
# a user-defined function to calculate penalties for CPU execution metrics
# whose does not allow the sum of loads above 100%
my.penalty <- function(m.individual,...) {
penalty <- 0
# counts how many centroids results in overflow (inequality > 100)
sums <- apply(m.individual, 1, sum)
overflow <- which(sums > 100)
num_constraints = length(overflow)
# if there are overflows, subtract each dimension
# by the maximum proportion of the excess x the number of overflows
if (num_constraints > 0) {
penalty <- num_constraints * max(abs(sums[overflow] -100)/sums[overflow])
}
return (penalty)
}
# call the gama clustering to maximize Dunn index criterion
# by using 500 generations and delegates to GAMA to choose the best k value
gama.obj <- gama(data = cpu.als, fitness.criterion = "DI",
generations = 500, penalty.function = my.penalty)
print(gama.obj)
# }
Run the code above in your browser using DataLab