R/choose_best_collapse_state.R
choose_best_collapse_state.RdChoose and load best model state from agglomerative collapsing algorithm
choose_best_collapse_state( sbm, use_entropy_value_for_score = FALSE, heuristic = "dev_from_rolling_mean", verbose = FALSE )
| sbm |
|
|---|---|
| use_entropy_value_for_score | If set to |
| heuristic | How the best partitioning is defined. Takes either a
function that takes one/two arguments: an entropy vector and an optional
number of blocks vector with each element corresponding to a given
location, or a string labeling algorithm. Currently only |
| verbose | Should model tell you what step was chosen ( |
An S3 object of class sbm_network. For details see
new_sbm_network section "Class structure."
visualize_collapse_results
Other modeling:
collapse_blocks(),
collapse_run(),
get_block_edge_counts(),
get_entropy(),
get_num_blocks(),
get_state(),
mcmc_sweep()
set.seed(42) # Start with a random network of two blocks with 25 nodes each net <- sim_basic_block_network(n_blocks = 3, n_nodes_per_block = 25) %>% collapse_blocks(sigma = 2) # Choose best result with default heuristic net <- choose_best_collapse_state(net, verbose = TRUE)#> Choosing collapse with 3 blocks and an entropy of 2150.6219.# Score heuristic that fits a nonlinear model to observed values and chooses by # largest negative residual nls_score <- function(e, k){ entropy_model <- nls(e ~ a + b * log(k), start = list(a = max(e), b = -25)) -residuals(entropy_model) } # Choose result using custom heuristic function my_sbm <- choose_best_collapse_state(net, heuristic = nls_score, verbose = TRUE)#> Choosing collapse with 4 blocks and an entropy of 2140.167.