Added weboflife app files
This commit is contained in:
parent
f34d8e33c6
commit
48cafa1b0f
2 changed files with 78 additions and 0 deletions
8
code/applications/weboflife/01_weboflife_prepare_data.R
Normal file
8
code/applications/weboflife/01_weboflife_prepare_data.R
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
library(here)
|
||||
|
||||
data_folder <- file.path(here(), "code", "data", "weboflife")
|
||||
data_path <- file.path(data_folder, "web_of_life.rda")
|
||||
load(data_path)
|
||||
|
||||
netlist <- lapply(web_of_life, function(web) web[["net"]])
|
||||
names(netlist) <- sapply(web_of_life, function(web) web[["id"]])
|
||||
70
code/applications/weboflife/02_weboflife_clustering.R
Normal file
70
code/applications/weboflife/02_weboflife_clustering.R
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
library(colSBM)
|
||||
library(dplyr)
|
||||
library(tidyr)
|
||||
library(here)
|
||||
|
||||
application_name <- "weboflife"
|
||||
|
||||
application_folder <- file.path(here(), "code", "applications", application_name)
|
||||
prepare_data_script_path <- file.path(
|
||||
application_folder,
|
||||
sprintf("01_%s_prepare_data.R", application_name)
|
||||
)
|
||||
|
||||
source(prepare_data_script_path)
|
||||
|
||||
# Arguments
|
||||
arg <- commandArgs(trailingOnly = TRUE)
|
||||
|
||||
model <- "iid"
|
||||
|
||||
if (length(arg) == 0L) {
|
||||
message("No arguments provided, using default.")
|
||||
} else {
|
||||
if ("--model" %in% arg) {
|
||||
model <- arg[(which(arg == "--model") + 1L)]
|
||||
} else {
|
||||
message("No model provided, defaulting to iid.")
|
||||
}
|
||||
}
|
||||
|
||||
# Arguments checks
|
||||
allowed_model <- c("iid", "pi", "rho", "pirho")
|
||||
stopifnot(
|
||||
"Unknown model, should be : iid, pi, rho or pirho" = (model %in% allowed_model)
|
||||
)
|
||||
|
||||
message(sprintf("Début du clustering des données %s avec le modèle ", application_name), model)
|
||||
|
||||
set.seed(1234, "L'Ecuyer-CMRG")
|
||||
base_data_folder <- file.path(here(), "code", "data", application_name)
|
||||
save_folder <- file.path(here(), "code", "results", "applications", application_name)
|
||||
|
||||
if (!dir.exists(save_folder)) {
|
||||
dir.create(save_folder, recursive = TRUE)
|
||||
}
|
||||
|
||||
start_time <- format(Sys.time(), "%d-%m-%y_%H-%M-%S")
|
||||
|
||||
list_collection <- clusterize_bipartite_networks(
|
||||
netlist = netlist,
|
||||
net_id = names(netlist),
|
||||
colsbm_model = model,
|
||||
nb_run = 3L,
|
||||
global_opts = list(
|
||||
nb_cores = parallelly::availableCores(omit = 1L),
|
||||
verbosity = 2L,
|
||||
plot_details = 0L,
|
||||
backend = "parallel"
|
||||
)
|
||||
)
|
||||
|
||||
save_file <- file.path(
|
||||
save_folder, paste0(
|
||||
sprintf("%s_collection_", application_name),
|
||||
model, "_", start_time, ".Rds"
|
||||
)
|
||||
)
|
||||
|
||||
message("Clustering saved.")
|
||||
saveRDS(list_collection, file = save_file)
|
||||
Loading…
Add table
Reference in a new issue