simulations : netclustering adding missing here library
This commit is contained in:
parent
dcacfb1676
commit
358dd3eb7f
1 changed files with 29 additions and 17 deletions
|
|
@ -1,4 +1,5 @@
|
|||
necessary_packages <- c("remotes", "colSBM")
|
||||
library(here)
|
||||
|
||||
if (!all(necessary_packages %in% installed.packages())) {
|
||||
install.packages(necessary_packages[-length(necessary_packages)])
|
||||
|
|
@ -19,6 +20,27 @@ repetitions <- seq.int(30)
|
|||
epsilons <- seq(0.1, 0.4, by = 0.1)
|
||||
models <- c("iid", "pi", "rho", "pirho")
|
||||
|
||||
save_folder <- here(
|
||||
"code", "results", "simulations", "clustering",
|
||||
"9collection"
|
||||
)
|
||||
|
||||
if (!dir.exists(save_folder)) {
|
||||
dir.create(save_folder)
|
||||
}
|
||||
|
||||
save_filename <- paste0(
|
||||
"9collection_data_clustering_",
|
||||
format(Sys.time(), "%d-%m-%y-%H-%M-%S"),
|
||||
".Rds"
|
||||
)
|
||||
|
||||
temp_folder <- file.path(save_folder, paste0("tmp", format(Sys.time(), "%d-%m-%y-%H-%M-%S")))
|
||||
|
||||
if (!dir.exists(temp_folder)) {
|
||||
dir.create(temp_folder)
|
||||
}
|
||||
|
||||
conditions <- tidyr::crossing(epsilons, repetitions, models)
|
||||
results <- future.apply::future_lapply(
|
||||
seq_len(nrow(conditions)), function(s) {
|
||||
|
|
@ -197,30 +219,20 @@ results <- future.apply::future_lapply(
|
|||
# ARI computation
|
||||
clustering <- clustering[order(names(clustering))]
|
||||
ari <- aricode::ARI(rep(c(1, 2, 3), each = 3), clustering)
|
||||
out <- data.frame(epsilon = eps, model = current_model, ARI = ari)
|
||||
|
||||
return(
|
||||
data.frame(epsilon = eps, model = current_model, ARI = ari)
|
||||
)
|
||||
saveRDS(out, file = file.path(
|
||||
temp_folder,
|
||||
paste0("condition_", s, "_on_", nrow(conditions), ".Rds")
|
||||
))
|
||||
|
||||
return(out)
|
||||
},
|
||||
future.seed = NULL
|
||||
)
|
||||
|
||||
data_frame_result <- do.call("rbind", results)
|
||||
|
||||
save_folder <- here(
|
||||
"code", "results", "simulations", "clustering",
|
||||
"9collection"
|
||||
)
|
||||
|
||||
if (!dir.exists(save_folder)) {
|
||||
dir.create(save_folder)
|
||||
}
|
||||
save_filename <- paste0(
|
||||
"9collection_data_clustering_",
|
||||
format(Sys.time(), "%d-%m-%y-%H-%M-%S"),
|
||||
".Rds"
|
||||
)
|
||||
|
||||
saveRDS(data_frame_result, file = file.path(
|
||||
save_folder,
|
||||
save_filename
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue