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
15 changes: 7 additions & 8 deletions R/undirected_chung_lu.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#' @inheritParams undirected_factor_model
#' @inheritParams dcsbm
#'
#' @return An `undirected_chung_lu` S3 object, a subclass of [dcsbm()].
#' @return An `undirected_chung_lu` S3 object, a subclass of the
#' `undirected_dcsbm` object returned by [dcsbm()], with a single block.
#'
#' @export
#' @family undirected graphs
Expand Down Expand Up @@ -95,7 +96,8 @@ chung_lu <- function(
poisson_edges = poisson_edges,
force_identifiability = force_identifiability,
allow_self_loops = allow_self_loops,
...
...,
subclass = "undirected_chung_lu"
)

# don't validate the chung-ln-ness because there is no low level
Expand All @@ -107,17 +109,14 @@ chung_lu <- function(
#' @export
print.undirected_chung_lu <- function(x, ...) {
cat(glue("Undirected Chung-Lu Graph\n", .trim = FALSE))
cat(glue(
"-------------------------------------------------\n\n",
.trim = FALSE
))
cat(glue("-------------------------\n\n", .trim = FALSE))

sorted <- if (x$sorted) "arranged by block" else "not arranged by block"

cat(glue("Nodes (n): {x$n} ({sorted})\n", .trim = FALSE))
cat(glue("Nodes (n): {x$n} ({sorted})\n\n", .trim = FALSE))

cat("Traditional Chung-Lu parameterization:\n\n")
cat("Degree heterogeneity (theta):", dim_and_class(x$theta), "\n")
cat("Degree heterogeneity (theta):", dim_and_class(x$theta), "\n\n")

cat("Factor model parameterization:\n\n")
cat("X:", dim_and_class(x$X), "\n")
Expand Down
3 changes: 2 additions & 1 deletion man/chung_lu.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/testthat/test-chung-lu.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test_that("chung_lu() returns an undirected_chung_lu object", {
set.seed(6)
m <- chung_lu(theta = rexp(15) + 0.5)

expect_s3_class(
m,
c("undirected_chung_lu", "undirected_dcsbm", "undirected_factor_model"),
exact = TRUE
)

out <- paste(capture.output(print(m)), collapse = "\n")
expect_match(out, "Undirected Chung-Lu Graph", fixed = TRUE)
expect_match(out, "Degree heterogeneity (theta): 15 [numeric]", fixed = TRUE)
expect_no_match(out, "Degree-Corrected", fixed = TRUE)
})
Loading