Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions R/undirected_sbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ validate_undirected_sbm <- function(x) {
function(x) length(unique(x))
)

if (any(distinct_theta_by_block) > 1) {
if (any(distinct_theta_by_block > 1)) {
stop(
"`theta` must be equal for all nodes in a given block.",
call. = FALSE
Expand Down Expand Up @@ -140,8 +140,7 @@ print.undirected_sbm <- function(x, ...) {

cat("Traditional SBM parameterization:\n\n")
cat("Block memberships (z):", dim_and_class(x$z), "\n")
cat("Block probabilities (pi):", dim_and_class(x$pi), "\n")
cat(glue("Edge distribution: {x$edge_distribution}\n\n", .trim = FALSE))
cat("Block probabilities (pi):", dim_and_class(x$pi), "\n\n")

cat("Factor model parameterization:\n\n")
cat("X:", dim_and_class(x$X), "\n")
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-undirected-sbms.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,30 @@ test_that("rank 1 sbms sample", {

expect_silent(A <- sample_sparse(sbm))
})

test_that("validate_undirected_sbm() rejects theta that varies within a block", {
set.seed(1)
m <- sbm(n = 10, B = diag(2) * 0.5 + 0.1)
expect_identical(validate_undirected_sbm(m), m)

m$theta <- 1:10 + 0
expect_error(
validate_undirected_sbm(m),
"`theta` must be equal for all nodes in a given block.",
fixed = TRUE
)
})

test_that("print.undirected_sbm() separates its sections", {
set.seed(1)
m <- sbm(n = 10, B = diag(2) * 0.5 + 0.1)
out <- paste(capture.output(print(m)), collapse = "\n")

expect_match(
out,
"Block probabilities (pi): 2 [numeric] \n\nFactor model parameterization:",
fixed = TRUE
)
expect_match(out, "Poisson edges: TRUE", fixed = TRUE)
expect_match(out, "Allow self loops: TRUE", fixed = TRUE)
})
Loading