Adding colSBM script
This commit is contained in:
parent
6bb74565b6
commit
a74aa46788
1 changed files with 47 additions and 0 deletions
47
colSBM-on-HMC.R
Normal file
47
colSBM-on-HMC.R
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
library(colSBM)
|
||||||
|
library(here)
|
||||||
|
library(tidyverse)
|
||||||
|
library(future.apply)
|
||||||
|
|
||||||
|
read.csv(here("data", "projects_supinfo.csv.gz")) -> projects_supinfo
|
||||||
|
|
||||||
|
projects_supinfo %>%
|
||||||
|
group_by(country, project) %>%
|
||||||
|
distinct() %>%
|
||||||
|
count() %>%
|
||||||
|
View()
|
||||||
|
|
||||||
|
|
||||||
|
list_matrices <- readRDS(here("data", "list_matrices.rds"))
|
||||||
|
|
||||||
|
names(list_matrices)
|
||||||
|
|
||||||
|
portuguese_projects <- projects_supinfo %>%
|
||||||
|
filter(country == "Portugal") %>%
|
||||||
|
select(project) %>%
|
||||||
|
distinct() %>%
|
||||||
|
pull() %>%
|
||||||
|
as.vector()
|
||||||
|
|
||||||
|
portuguese_matrices <- list_matrices[portuguese_projects]
|
||||||
|
|
||||||
|
rm(list_matrices)
|
||||||
|
|
||||||
|
binary_portuguese_matrices <- lapply(portuguese_matrices, function(x) {
|
||||||
|
x[x > 0] <- 1
|
||||||
|
x
|
||||||
|
})
|
||||||
|
options(future.globals.maxSize = Inf)
|
||||||
|
plan(multisession, workers = 3L)
|
||||||
|
set.seed(123)
|
||||||
|
fit_portuguese <- estimate_colBiSBM(
|
||||||
|
netlist = binary_portuguese_matrices,
|
||||||
|
colsbm_model = "iid",
|
||||||
|
net_id = names(binary_portuguese_matrices),
|
||||||
|
global_opts = list(backend = "no_mc")
|
||||||
|
)
|
||||||
|
save_path <- here("results", "colSBM")
|
||||||
|
if (!dir.exists(save_path)) {
|
||||||
|
dir.create(save_path, recursive = TRUE)
|
||||||
|
}
|
||||||
|
saveRDS(fit_portuguese, file = here(save_path, "colSBM_portuguese.rds"))
|
||||||
Loading…
Add table
Reference in a new issue