Repository navigation
Store rescaled edge probabilities in Erdős–Rényi and planted partition models - #66
Draft
alexpghayes wants to merge 1 commit into
Draft
alexpghayes wants to merge 1 commit into
alexpghayes wants to merge 1 commit into
Conversation
After rescaling S with `expected_degree`, `expected_density` and so on, erdos_renyi() and directed_erdos_renyi() kept the placeholder `p = 0.5` (or the given `p`), and planted_partition() and directed_planted_partition() kept the given `within_block` and `between_block`, so print() and the stored fields described a different model from the one sampled. Recompute them from the final S, converting back to probabilities for Bernoulli graphs. Since stored values are now Poisson rates after rescaling, the validators only require them to be non-negative (positive for `p`), and at most one for Bernoulli graphs. The user's inputs are checked in the constructors, as before. directed_erdos_renyi() now checks `p` like erdos_renyi(): strictly between zero and one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 18, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Stored parameters went stale after
expected_degree/expected_densityscaling:Same for
directed_planted_partition()anddirected_erdos_renyi().Fix
When a scaling argument (
expected_*) is given, recompute the stored fields from the finalS, converting Bernoulli models back from the Poisson scale with1 - exp(-S):p <- S[1, 1];within_block/between_blockfromS's diagonal and off-diagonal (fork = 1,between_blockis scaled by the same factor).Without scaling, the given values are stored exactly as before. Two small helpers,
edge_scale_S()andis_rescaled(), are inR/utils.R.Both planted partitions now behave the same:
directed_planted_partition()documented the old pre-scaling behavior; its@returndocs now describe the rescaled values, like the undirected one.Validation: after rescaling, Poisson rates can exceed 1 (e.g.
erdos_renyi(n = 10, expected_degree = 50)hasp = 5). So the validators now only require stored values to be non-negative (positive forp), and at most 1 for Bernoulli graphs. The user's inputs are still checked in the constructors:within_block/between_blockin [0, 1] (moved from the undirected validator toplanted_partition(), now with the directed version's "(ora / n)" wording; one existing test's expected message updated), andpstrictly between 0 and 1.Includes bug 16 from the handoff:
directed_erdos_renyi()accepted anyp >= 0, includingp > 1, with a "strictly non-negative" message. It now checkspexactly likeerdos_renyi(): strictly between 0 and 1. This is a small breaking change for directed Poisson ER withp > 1; useexpected_*_degreefor rates above 1. Folded in here because it touches the same validators.Not changed:
overlapping_sbm()'s$B. Its docs (#42) explicitly sayBis the user's matrix, neither symmetrized nor rescaled, and that the matrix used for sampling isS; its validator also checksBin [0, 1] as input probabilities. I left it as documented. Say if you'd rather$Bbe the rescaled matrix too.Tests
New
tests/testthat/test-rescaled-params.R, for Poisson and Bernoulli models. Fails onmain(23 failures, 1 error), passes here. Full suite passes. Docs regenerated with roxygen2 7.3.2.NEWS
Left out to avoid conflicting with #59. Suggested bullets:
Bug fixes
Breaking changes
🤖 Generated with Claude Code