Repository navigation
Keep from == to edges in rectangular models with allow_self_loops = FALSE - #67
Draft
alexpghayes wants to merge 1 commit into
Draft
alexpghayes wants to merge 1 commit into
alexpghayes wants to merge 1 commit into
Conversation
…ALSE In rectangular directed models (n != d) rows and columns are different sets of nodes, so an edge from row i to column i is not a self-loop. sample_edgelist() dropped those edges anyway, undersampling the graph. Only drop self-loops when n == d, and document that allow_self_loops is ignored for rectangular graphs. The existing directed allow_self_loops test used a rectangular model and locked in the bug; make it square. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
In rectangular directed models (
n != d), rows and columns are different sets of nodes, so an edge from rowito columniis not a self-loop.sample_edgelist.matrix()(R/sample_edgelist.R) droppedfrom == toedges anyway. This affectssample_sparse(),sample_igraph()andsample_tidygraph()too.Fix
Only drop
from == toedges whenn == d. Theallow_self_loopsdocs fordirected_factor_model()(and the directed models that inherit it) and forsample_edgelist.matrix()now say that it is ignored for rectangular graphs. Undirected models get their own copy of the old wording, so their docs don't mention rectangular graphs.Tests
tests/testthat/test-allow_self_loops.R: for the 3 × 5 model above, the mean edge count over 500 samples matchesexpected_edges(m) = 30and the mean count offrom == toedges matches 6. Both checks use Poisson z-scores below 5. Square models still drop self-loops. Fails onmain, passes here.Full suite passes. Docs regenerated with roxygen2 7.3.2.
#60's
test-sampler-agreement.Rassertsexpect_false(any(el$from == el$to))underif (!loops)for every model, including the rectangular ones, so it will fail once this is merged. It needs to be restricted to square models, e.g.if (!loops && !rectangular). The!rectangularblock that follows is already fine.NEWS
Left out to avoid conflicting with #59. Suggested bullet under Bug fixes:
🤖 Generated with Claude Code