1 | Calc_Kmeans(n_x, loc_orig, nstart=100, iter.max=1000, DirPath=NULL, Save_Results=TRUE)
|
n_x |
|
Kmeans_Config |
|
Data_Geostat |
|
Data_Extrap |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (n_x, Kmeans_Config, Data_Geostat, Data_Extrap)
{
old.options <- options()
options(warn = -1)
on.exit(options(old.options))
if (paste0("Kmeans-", n_x, ".RData") %in% list.files(getwd())) {
load(file = paste(DateFile, "Kmeans.RData", sep = ""))
}
else {
Kmeans = list(tot.withinss = Inf)
for (i in 1:Kmeans_Config[["nstart"]]) {
if (Kmeans_Config[["Locs"]] == "Samples") {
Tmp = kmeans(x = Data_Geostat[, c("E_km", "N_km")],
centers = n_x, iter.max = Kmeans_Config[["iter.max"]],
nstart = 1, trace = 0)
}
if (Kmeans_Config[["Locs"]] == "Domain") {
Tmp = kmeans(x = Data_Extrap[, c("E_km", "N_km")],
centers = n_x, iter.max = Kmeans_Config[["iter.max"]],
nstart = 1, trace = 0)
}
print(paste0("Num=", i, " Current_Best=", round(Kmeans$tot.withinss,
1), " New=", round(Tmp$tot.withinss, 1)))
if (Tmp$tot.withinss < Kmeans$tot.withinss) {
Kmeans = Tmp
}
}
}
return(Kmeans)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.