Choose 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
)

Arguments

sbm

sbm_network object as created by new_sbm_network.

use_entropy_value_for_score

If set to TRUE then instead of the merge results entropy delta being used for the score function the entropy will be. Typically the heuristics work better on entropy delta values.

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 "lowest", "dev_from_rolling_mean", "delta_ratio", "trend_deviation", and "nls_residual" are supported.

verbose

Should model tell you what step was chosen (TRUE or FALSE)?

Value

An S3 object of class sbm_network. For details see new_sbm_network section "Class structure."

See also

visualize_collapse_results

Other modeling: collapse_blocks(), collapse_run(), get_block_edge_counts(), get_entropy(), get_num_blocks(), get_state(), mcmc_sweep()

Examples

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.