Skip to content

Commit

Permalink
optimise .sim_network_bp by moving contact distribution density outsi…
Browse files Browse the repository at this point in the history
…de loop
  • Loading branch information
joshwlambert committed Feb 23, 2024
1 parent bf89eb7 commit 018f9dd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions R/sim_network_bp.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
ancestor_idx <- 1L
prev_ancestors <- 1L

if (config$network == "adjusted") {
# sample contact distribution (excess degree distribution)
q <- contact_distribution(0:1e4 + 1) * (0:1e4 + 1)
q <- q / sum(q)
} else {
q <- contact_distribution(0:1e4)
}

# run loop until no more individuals are sampled
while (next_gen_size > 0) {
if (config$network == "adjusted") {
# sample contact distribution (excess degree distribution)
q <- contact_distribution(0:1e4 + 1) * (0:1e4 + 1)
q <- q / sum(q)
} else {
q <- contact_distribution(0:1e4)
}
contacts <- sample(0:1e4, size = next_gen_size, replace = TRUE, prob = q)

# add contacts if sampled
if (sum(contacts) > 0L) {
chain_size <- chain_size + sum(contacts)
Expand Down

0 comments on commit 018f9dd

Please sign in to comment.