Choose and load best model state from agglomerative collapsing algorithm

choose_best_collapse_state(
  sbm,
  heuristic = "dev_from_rolling_mean",
  use_entropy = FALSE,
  verbose = FALSE
)

Arguments

sbm

sbm_network object as created by new_sbm_network.

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.

use_entropy

Should the score be calculated with the entropy of the collapse? If FALSE, the entropy delta will be used. The full entropy is needed to make comparisons across separate collapses in the case of collapse_run.

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(), entropy(), interblock_edge_counts(), mcmc_sweep(), n_blocks(), state()

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 = 1.4) # Choose best result with default heuristic net <- choose_best_collapse_state(net, verbose = TRUE)
#> Choosing collapse with 3 blocks and an entropy of 11.0434.
# 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 26 blocks and an entropy of 203.3675.