Runs a single Metropolis Hastings MCMC sweep across all nodes at specified level (For algorithm details see Piexoto, 2018). Each node is given a chance to move blocks or stay in current block and all nodes are processed in random order. Takes the level that the sweep should take place on (int) and if new blocks blocks can be proposed and empty blocks removed (boolean).

mcmc_sweep(
  sbm,
  num_sweeps = 1,
  eps = 0.1,
  variable_n_blocks = TRUE,
  track_pairs = FALSE,
  level = 0,
  verbose = FALSE
)

Arguments

sbm

sbm_network object as created by new_sbm_network.

num_sweeps

Number of times all nodes are passed through for move proposals.

eps

Controls randomness of move proposals. Effects both the block merging and mcmc sweeps.

variable_n_blocks

Should the model allow new blocks to be created or empty blocks removed while sweeping or should number of blocks remain constant?

track_pairs

Return a dataframe with all pairs of nodes along with the number of sweeps they shared the same group?

level

Level of nodes who's blocks will have their block membership run through MCMC proposal-accept routine.

verbose

If set to TRUE then each proposed move for all sweeps will have information given on entropy delta, probability of moving, and if the move were accepted printed to the console.

Value

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

See also

Examples

set.seed(42) # Start with a small simulated network with random block assignments net <- sim_basic_block_network(n_blocks = 4, n_nodes_per_block = 15) %>% initialize_blocks(n_blocks = 4) # Calculate entropy with random blocks entropy(net)
#> [1] 1285.001
# Run some MCMC sweeps net <- mcmc_sweep(net, num_sweeps = 25, variable_n_blocks = FALSE) # Entropy after sweeps entropy(net)
#> [1] 1243.098
# Per-sweep level information get_sweep_results(net)
#> $nodes_moved #> [1] "g2_5" "g1_6" "g1_15" "g1_11" "g4_1" "g2_4" "g2_12" "g1_9" "g2_3" #> [10] "g1_3" "g3_12" "g4_2" "g1_12" "g2_8" "g3_14" "g4_9" "g3_4" "g1_5" #> [19] "g2_6" "g1_8" "g4_7" "g2_13" "g1_4" "g1_7" "g2_2" "g3_2" "g3_9" #> [28] "g1_10" "g3_6" "g3_7" "g4_15" "g3_10" "g3_3" "g3_15" "g2_9" "g3_8" #> [37] "g4_6" "g2_7" "g2_14" "g4_13" "g3_2" "g2_3" "g4_11" "g4_12" "g3_10" #> [46] "g2_1" "g4_4" "g1_2" "g1_13" "g4_9" "g4_6" "g3_12" "g2_9" "g4_15" #> [55] "g1_6" "g1_15" "g2_2" "g1_8" "g3_11" "g1_11" "g2_4" "g3_6" "g2_8" #> [64] "g2_10" "g2_13" "g4_8" "g1_10" "g4_10" "g3_3" "g4_2" "g3_8" "g1_14" #> [73] "g3_15" "g3_14" "g4_13" "g2_12" "g4_5" "g3_1" "g4_7" "g2_6" "g1_7" #> [82] "g3_10" "g2_3" "g2_2" "g1_9" "g3_6" "g3_3" "g1_2" "g3_13" "g2_10" #> [91] "g1_6" "g1_15" "g1_5" "g2_11" "g3_8" "g4_3" "g4_5" "g2_9" "g4_8" #> [100] "g4_9" "g3_7" "g4_6" "g1_1" "g3_4" "g1_4" "g1_14" "g4_1" "g1_8" #> [109] "g2_1" "g4_4" "g2_4" "g2_5" "g2_15" "g1_6" "g2_7" "g2_13" "g1_1" #> [118] "g2_3" "g4_12" "g3_7" "g3_9" "g2_11" "g1_7" "g2_2" "g1_10" "g3_11" #> [127] "g2_15" "g4_11" "g4_6" "g4_7" "g1_5" "g3_12" "g1_8" "g1_4" "g2_5" #> [136] "g3_8" "g3_10" "g3_15" "g4_1" "g3_13" "g1_12" "g4_2" "g2_7" "g3_3" #> [145] "g4_3" "g1_11" "g4_2" "g4_10" "g3_14" "g1_4" "g4_13" "g2_3" "g3_5" #> [154] "g1_2" "g2_14" "g1_5" "g3_4" "g4_4" "g3_12" "g4_8" "g4_12" "g2_13" #> [163] "g4_11" "g3_1" "g2_2" "g1_7" "g4_1" "g3_13" "g2_6" "g2_12" "g1_3" #> [172] "g4_15" "g4_14" "g1_5" "g4_3" "g1_11" "g3_9" "g4_14" "g2_10" "g3_3" #> [181] "g3_5" "g2_9" "g1_7" "g4_8" "g4_1" "g3_8" "g1_3" "g3_14" "g4_11" #> [190] "g2_15" "g2_4" "g4_6" "g4_12" "g3_15" "g4_5" "g4_9" "g3_6" "g3_12" #> [199] "g3_15" "g4_3" "g2_3" "g4_4" "g4_8" "g4_6" "g3_5" "g3_9" "g2_10" #> [208] "g2_13" "g4_13" "g2_14" "g4_14" "g3_2" "g3_1" "g2_5" "g4_5" "g3_11" #> [217] "g1_5" "g2_6" "g2_12" "g4_7" "g4_15" "g2_14" "g1_4" "g2_4" "g3_9" #> [226] "g2_1" "g2_11" "g1_8" "g4_9" "g1_7" "g3_4" "g3_10" "g3_15" "g4_1" #> [235] "g1_10" "g1_12" "g2_13" "g3_7" "g3_15" "g4_15" "g4_13" "g1_12" "g1_10" #> [244] "g3_6" "g4_5" "g4_12" "g1_8" "g1_5" "g4_2" "g1_4" "g3_5" "g3_7" #> [253] "g3_1" "g2_14" "g1_3" "g2_13" "g2_5" "g2_1" "g4_7" "g4_8" "g2_11" #> [262] "g4_6" "g2_10" "g1_12" "g4_6" "g3_11" "g2_2" "g2_14" "g3_7" "g4_2" #> [271] "g4_11" "g2_11" "g2_6" "g4_7" "g3_15" "g1_7" "g2_7" "g2_3" "g4_14" #> [280] "g2_5" "g4_15" "g2_8" "g4_4" "g3_10" "g4_8" "g3_3" "g4_9" "g3_5" #> [289] "g4_12" "g4_11" "g3_12" "g3_2" "g2_6" "g3_14" "g1_10" "g3_10" "g4_4" #> [298] "g2_12" "g2_5" "g2_1" "g2_2" "g2_9" "g3_8" "g3_1" "g2_11" "g1_3" #> [307] "g2_2" "g4_12" "g2_11" "g3_5" "g4_4" "g2_5" "g3_15" "g4_8" "g3_8" #> [316] "g1_4" "g4_2" "g2_9" "g4_15" "g4_7" "g1_7" "g2_1" "g3_12" "g3_10" #> [325] "g2_7" "g4_11" "g4_1" "g4_5" "g4_8" "g1_4" "g4_2" "g2_2" "g4_3" #> [334] "g2_8" "g2_15" "g2_11" "g4_15" "g1_7" "g4_7" "g3_13" "g4_6" "g2_9" #> [343] "g4_12" "g4_9" "g4_14" "g2_4" "g3_15" "g3_15" "g4_7" "g3_2" "g2_10" #> [352] "g3_11" "g4_13" "g4_1" "g2_8" "g4_3" "g3_13" "g3_6" "g3_10" "g2_12" #> [361] "g3_3" "g2_14" "g2_9" "g4_7" "g3_6" "g3_12" "g3_1" "g3_7" "g4_4" #> [370] "g1_1" "g2_7" "g2_3" "g3_5" "g2_11" "g4_13" "g4_14" "g2_8" "g4_15" #> [379] "g2_10" "g2_1" "g2_4" "g4_1" "g2_6" "g4_12" "g1_7" "g4_3" "g4_9" #> [388] "g3_15" "g1_13" "g3_9" "g2_10" "g4_4" "g4_8" "g3_10" "g1_1" "g3_3" #> [397] "g4_7" "g3_13" "g4_5" "g2_8" "g1_7" "g2_5" "g4_14" "g4_15" "g3_8" #> [406] "g3_14" "g2_13" "g1_1" "g4_7" "g2_10" "g2_15" "g3_3" "g3_10" "g2_14" #> [415] "g2_2" "g3_12" "g2_8" "g2_6" "g2_11" "g4_14" "g1_13" "g4_10" "g4_5" #> [424] "g3_14" "g1_7" "g4_12" "g3_8" "g2_4" "g3_2" "g4_13" "g3_6" "g2_7" #> [433] "g1_6" "g4_6" "g4_7" "g2_1" "g2_4" "g1_7" "g3_9" "g2_2" "g3_11" #> [442] "g4_12" "g4_14" "g3_4" "g3_8" "g4_13" "g2_15" "g3_7" "g1_13" "g3_15" #> [451] "g4_13" "g3_1" "g2_7" "g2_3" "g4_6" "g2_9" "g4_7" "g3_15" "g4_2" #> [460] "g3_6" "g4_11" "g1_6" "g2_11" "g1_7" "g2_4" "g3_7" "g3_13" "g3_12" #> [469] "g4_10" "g2_5" "g1_13" "g3_10" "g4_5" "g3_6" "g3_2" "g4_3" "g2_15" #> [478] "g2_10" "g3_7" "g1_1" "g2_7" "g4_8" "g3_3" "g2_14" "g4_12" "g3_4" #> [487] "g3_9" "g2_9" "g4_6" "g2_7" "g3_12" "g4_8" "g4_14" "g1_1" "g2_3" #> [496] "g3_1" "g3_2" "g4_4" "g4_9" "g3_15" "g2_12" "g3_6" "g2_14" "g3_10" #> [505] "g1_1" "g3_14" "g4_14" "g3_13" "g4_13" "g4_3" "g2_1" "g2_13" "g3_4" #> [514] "g2_10" "g2_4" "g4_4" "g3_9" "g3_12" "g1_13" "g4_12" "g4_8" "g4_2" #> [523] "g4_4" "g3_12" "g4_13" "g2_10" "g3_11" "g2_6" "g3_1" "g3_14" "g4_11" #> [532] "g4_10" "g2_6" "g3_1" "g3_11" "g3_14" "g2_15" "g3_2" "g4_6" "g4_4" #> [541] "g1_7" "g1_13" "g2_2" "g4_8" "g4_3" "g4_11" "g4_7" "g2_13" "g2_3" #> [550] "g4_15" "g2_6" "g2_8" "g1_1" "g2_10" "g3_4" "g2_4" "g4_5" "g3_15" #> [559] "g4_8" "g3_10" "g2_14" "g3_3" "g4_12" "g3_5" "g2_3" #> #> $sweep_info #> entropy_delta n_nodes_moved #> 1 -2.6878071 40 #> 2 0.1449707 37 #> 3 -3.8020052 36 #> 4 -2.7273255 29 #> 5 -10.1095123 31 #> 6 -6.9638134 24 #> 7 0.1198805 21 #> 8 -0.2779975 20 #> 9 2.5827224 24 #> 10 -3.6357949 23 #> 11 -7.9324498 21 #> 12 0.9834024 19 #> 13 -2.5335536 22 #> 14 -3.8254326 13 #> 15 1.3318307 26 #> 16 2.8169539 20 #> 17 1.0895534 28 #> 18 1.0087116 16 #> 19 -5.9299634 22 #> 20 3.5626661 13 #> 21 -2.3412071 16 #> 22 0.2691374 17 #> 23 3.2296993 14 #> 24 -3.2852847 17 #> 25 -2.9912529 16 #>
# Use track_pairs = TRUE to get an idea of node-pair similarity by looking at # how often every pair of nodes is connected over sweeps net %>% mcmc_sweep(num_sweeps = 25, track_pairs = TRUE) %>% get_sweep_pair_counts()
#> node_a node_b times_connected proportion_connected type #> 1 g3_12 g2_15 9 0.36 node #> 2 g4_9 g3_9 11 0.44 node #> 3 g3_12 g1_15 0 0.00 node #> 4 g4_9 g1_15 0 0.00 node #> 5 g4_14 g3_12 20 0.80 node #> 6 g4_14 g3_9 7 0.28 node #> 7 g4_9 g4_14 13 0.52 node #> 8 g4_14 g1_15 0 0.00 node #> 9 g3_4 g2_15 11 0.44 node #> 10 g3_9 g3_4 14 0.56 node #> 11 g4_9 g3_4 10 0.40 node #> 12 g3_4 g1_15 0 0.00 node #> 13 g4_14 g3_4 21 0.84 node #> 14 g4_13 g3_9 8 0.32 node #> 15 g4_13 g2_2 13 0.52 node #> 16 g4_14 g4_13 20 0.80 node #> 17 g4_13 g3_4 5 0.20 node #> 18 g2_15 g2_1 12 0.48 node #> 19 g3_9 g2_1 13 0.52 node #> 20 g3_4 g2_1 16 0.64 node #> 21 g4_13 g2_1 10 0.40 node #> 22 g2_9 g2_15 11 0.44 node #> 23 g3_9 g2_9 10 0.40 node #> 24 g4_9 g2_9 11 0.44 node #> 25 g2_9 g1_15 0 0.00 node #> 26 g4_14 g2_9 15 0.60 node #> 27 g4_13 g2_9 5 0.20 node #> 28 g3_12 g1_7 1 0.04 node #> 29 g2_15 g1_7 1 0.04 node #> 30 g3_9 g1_7 0 0.00 node #> 31 g4_9 g1_7 0 0.00 node #> 32 g1_7 g1_15 24 0.96 node #> 33 g4_13 g1_7 1 0.04 node #> 34 g2_1 g1_7 0 0.00 node #> 35 g2_9 g1_7 0 0.00 node #> 36 g3_7 g3_12 13 0.52 node #> 37 g3_7 g2_15 8 0.32 node #> 38 g3_7 g2_2 9 0.36 node #> 39 g3_7 g1_15 0 0.00 node #> 40 g3_7 g3_4 10 0.40 node #> 41 g4_13 g3_7 11 0.44 node #> 42 g3_7 g2_9 10 0.40 node #> 43 g3_7 g1_7 1 0.04 node #> 44 g3_9 g2_12 8 0.32 node #> 45 g4_9 g2_12 8 0.32 node #> 46 g2_12 g1_15 0 0.00 node #> 47 g3_4 g2_12 11 0.44 node #> 48 g4_13 g2_12 10 0.40 node #> 49 g2_12 g2_1 14 0.56 node #> 50 g2_9 g2_12 11 0.44 node #> 51 g2_12 g1_7 1 0.04 node #> 52 g3_7 g2_12 10 0.40 node #> 53 g4_2 g3_12 8 0.32 node #> 54 g2_15 g2_12 7 0.28 node #> 55 g4_2 g2_15 14 0.56 node #> 56 g4_2 g3_9 8 0.32 node #> 57 g4_9 g4_2 13 0.52 node #> 58 g4_2 g2_2 19 0.76 node #> 59 g4_2 g1_15 0 0.00 node #> 60 g4_2 g4_13 12 0.48 node #> 61 g4_2 g2_9 7 0.28 node #> 62 g4_2 g1_7 0 0.00 node #> 63 g4_2 g3_7 11 0.44 node #> 64 g4_2 g2_12 11 0.44 node #> 65 g4_10 g3_12 6 0.24 node #> 66 g4_9 g4_10 15 0.60 node #> 67 g4_10 g2_2 6 0.24 node #> 68 g4_10 g1_15 0 0.00 node #> 69 g4_13 g4_10 4 0.16 node #> 70 g4_10 g2_1 12 0.48 node #> 71 g4_10 g2_9 16 0.64 node #> 72 g4_10 g1_7 0 0.00 node #> 73 g4_10 g2_12 12 0.48 node #> 74 g4_2 g4_10 13 0.52 node #> 75 g3_12 g2_11 15 0.60 node #> 76 g4_9 g2_11 6 0.24 node #> 77 g2_2 g2_11 8 0.32 node #> 78 g4_13 g2_11 12 0.48 node #> 79 g2_11 g2_1 11 0.44 node #> 80 g2_9 g2_11 11 0.44 node #> 81 g2_11 g1_7 1 0.04 node #> 82 g3_7 g2_11 13 0.52 node #> 83 g1_2 g1_15 25 1.00 node #> 84 g4_14 g1_2 0 0.00 node #> 85 g3_12 g2_1 16 0.64 node #> 86 g3_4 g1_2 0 0.00 node #> 87 g2_9 g1_2 0 0.00 node #> 88 g1_7 g1_2 24 0.96 node #> 89 g3_7 g1_2 0 0.00 node #> 90 g2_2 g2_15 19 0.76 node #> 91 g2_12 g1_2 0 0.00 node #> 92 g4_10 g1_2 0 0.00 node #> 93 g2_11 g1_2 0 0.00 node #> 94 g3_12 g2_3 16 0.64 node #> 95 g3_9 g2_3 11 0.44 node #> 96 g4_9 g2_3 16 0.64 node #> 97 g2_3 g2_2 11 0.44 node #> 98 g2_3 g1_15 0 0.00 node #> 99 g2_9 g2_3 15 0.60 node #> 100 g4_2 g2_3 10 0.40 node #> 101 g4_10 g2_3 7 0.28 node #> 102 g2_3 g1_2 0 0.00 node #> 103 g3_12 g1_13 0 0.00 node #> 104 g2_15 g1_13 0 0.00 node #> 105 g2_12 g1_5 0 0.00 node #> 106 g4_13 g1_13 0 0.00 node #> 107 g3_7 g1_13 0 0.00 node #> 108 g2_7 g2_10 11 0.44 node #> 109 g4_3 g3_7 9 0.36 node #> 110 g2_9 g1_14 0 0.00 node #> 111 g2_15 g1_4 0 0.00 node #> 112 g1_12 g1_1 10 0.40 node #> 113 g1_4 g1_15 25 1.00 node #> 114 g4_14 g1_4 0 0.00 node #> 115 g3_4 g1_4 0 0.00 node #> 116 g2_1 g1_4 0 0.00 node #> 117 g2_9 g1_4 0 0.00 node #> 118 g2_12 g1_4 0 0.00 node #> 119 g4_2 g1_4 0 0.00 node #> 120 g2_11 g1_4 0 0.00 node #> 121 g4_8 g1_10 0 0.00 node #> 122 g3_6 g2_11 15 0.60 node #> 123 g3_3 g2_11 11 0.44 node #> 124 g4_8 g2_15 8 0.32 node #> 125 g4_8 g2_2 2 0.08 node #> 126 g3_2 g2_15 14 0.56 node #> 127 g4_8 g2_1 5 0.20 node #> 128 g4_8 g1_7 0 0.00 node #> 129 g4_8 g2_12 13 0.52 node #> 130 g4_11 g1_9 0 0.00 node #> 131 g4_8 g4_10 14 0.56 node #> 132 g4_11 g2_4 4 0.16 node #> 133 g4_8 g2_11 5 0.20 node #> 134 g4_8 g1_2 0 0.00 node #> 135 g3_12 g3_10 9 0.36 node #> 136 g3_9 g3_10 10 0.40 node #> 137 g2_5 g2_10 16 0.64 node #> 138 g4_9 g3_10 7 0.28 node #> 139 g4_4 g2_8 8 0.32 node #> 140 g4_14 g3_10 9 0.36 node #> 141 g2_1 g1_8 0 0.00 node #> 142 g3_4 g3_10 9 0.36 node #> 143 g4_3 g3_5 13 0.52 node #> 144 g3_10 g2_1 14 0.56 node #> 145 g3_7 g3_10 15 0.60 node #> 146 g3_10 g2_12 11 0.44 node #> 147 g3_10 g2_11 11 0.44 node #> 148 g3_10 g1_2 0 0.00 node #> 149 g3_10 g1_13 0 0.00 node #> 150 g3_13 g2_13 7 0.28 node #> 151 g3_10 g1_4 0 0.00 node #> 152 g3_2 g1_12 0 0.00 node #> 153 g4_6 g4_13 8 0.32 node #> 154 g4_6 g2_9 12 0.48 node #> 155 g4_6 g3_7 7 0.28 node #> 156 g4_6 g3_12 11 0.44 node #> 157 g4_6 g2_12 13 0.52 node #> 158 g4_7 g3_5 7 0.28 node #> 159 g4_6 g4_10 20 0.80 node #> 160 g4_3 g2_3 16 0.64 node #> 161 g4_6 g2_11 12 0.48 node #> 162 g4_6 g1_2 0 0.00 node #> 163 g4_6 g2_3 10 0.40 node #> 164 g4_9 g2_14 9 0.36 node #> 165 g4_6 g3_10 7 0.28 node #> 166 g2_15 g1_10 0 0.00 node #> 167 g4_12 g1_6 6 0.24 node #> 168 g2_2 g1_10 0 0.00 node #> 169 g1_15 g1_10 25 1.00 node #> 170 g3_4 g1_10 0 0.00 node #> 171 g2_11 g1_13 0 0.00 node #> 172 g1_7 g1_10 24 0.96 node #> 173 g4_2 g1_10 0 0.00 node #> 174 g4_2 g1_8 0 0.00 node #> 175 g1_4 g1_10 25 1.00 node #> 176 g3_10 g1_10 0 0.00 node #> 177 g3_3 g1_12 4 0.16 node #> 178 g4_15 g3_13 12 0.48 node #> 179 g4_14 g1_6 0 0.00 node #> 180 g4_6 g1_10 0 0.00 node #> 181 g3_8 g2_15 12 0.48 node #> 182 g4_9 g3_8 6 0.24 node #> 183 g4_13 g3_8 11 0.44 node #> 184 g4_13 g1_10 0 0.00 node #> 185 g3_10 g2_3 12 0.48 node #> 186 g2_3 g1_1 5 0.20 node #> 187 g3_8 g2_1 11 0.44 node #> 188 g4_2 g3_8 10 0.40 node #> 189 g4_13 g3_5 13 0.52 node #> 190 g2_10 g1_7 2 0.08 node #> 191 g3_8 g1_2 0 0.00 node #> 192 g4_6 g3_8 13 0.52 node #> 193 g2_5 g2_15 13 0.52 node #> 194 g3_9 g2_5 15 0.60 node #> 195 g3_14 g1_7 1 0.04 node #> 196 g1_15 g1_14 25 1.00 node #> 197 g4_10 g3_8 18 0.72 node #> 198 g2_14 g1_3 0 0.00 node #> 199 g2_5 g1_15 0 0.00 node #> 200 g2_5 g2_1 8 0.32 node #> [ reached 'max' / getOption("max.print") -- omitted 1570 rows ]