R/choose_best_collapse_state.R
choose_best_collapse_state.Rd
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 )
sbm |
|
---|---|
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 |
use_entropy | Should the score be calculated with the entropy of the
collapse? If |
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()
,
entropy()
,
interblock_edge_counts()
,
mcmc_sweep()
,
n_blocks()
,
state()
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.