Skip to content

Validate block_sizes and reject pi with block_sizes in dcsbm() - #64

Draft
alexpghayes wants to merge 1 commit into
mainfrom
fix/dcsbm-block-sizes-pi
Draft

alexpghayes wants to merge 1 commit into
mainfrom
fix/dcsbm-block-sizes-pi

Conversation

@alexpghayes

Copy link
Copy Markdown
Collaborator

Bug

dcsbm(theta = rep(1, 10), B = diag(2), block_sizes = c(5, 5), pi = c(.9, .1))  # pi silently ignored
dcsbm(theta = 1:5 + 0, B = diag(2), block_sizes = c(2.5, 2.5))                 # builds n = 4, drops a theta
dcsbm(theta = rep(1, 10), B = diag(2), block_sizes = c(3, 3, 4))               # "invalid 'times' argument"

In dcsbm(), the !is.null(block_sizes) branch came before the "both given" check, so that check (and the final else) was unreachable, and its error message was wrong. block_sizes was only checked for its sum. This affects sbm() and planted_partition() too, since they call dcsbm().

Fix

  • Check "both given" first: "Must specify only one of block_sizesandpi, not both.", matching the wording for B / k.
  • Validate block_sizes with check_block_sizes() from R/directed_dcsbm.R: non-negative integers, length k, sum n.
  • Use balanced_block_sizes() for the default instead of an inline copy.

Docs

  • The "Block memberships" details described sampling from pi, but fixed balanced sizes have been the default since 0.4.0. They now describe both.
  • pi no longer says block_sizes "takes precedence"; specifying both is an error.
  • B symmetrization formula: B := (B + t(B)) / 2, not B + t(B) / 2 (shared with sbm(), planted_partition(), mmsbm() docs).

Docs regenerated with roxygen2 7.3.2.

Tests

New tests/testthat/test-dcsbm-block-sizes.R. Fails on main (3 failures, 1 error), passes here. Full suite passes.

NEWS

Left out to avoid conflicting with #59. Suggested bullet under Bug fixes:

  • dcsbm(), sbm() and planted_partition() now error when both pi and block_sizes are given (previously pi was silently ignored), and validate block_sizes: it must be non-negative integers, one per block, summing to n. Previously non-integer sizes silently dropped nodes.

🤖 Generated with Claude Code

The block membership branches in dcsbm() were ordered so that the
"both given" check was unreachable: with `block_sizes` set, `pi` was
silently ignored. `block_sizes` was only checked for its sum, so
non-integer sizes silently dropped nodes and the wrong length failed
inside rep(). Check "both given" first and validate `block_sizes` with
check_block_sizes(), as directed_dcsbm() does.

Also update the docs: block sizes are fixed by default (since 0.4.0),
and fix the symmetrization formula for `B`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant