Sample Generalized Random Dot Product Graphs in Linear Time
Overview
Samples generalized random product graphs, a generalization of a broad class of network models. Given matrices X, S, and Y with with non-negative entries, samples a matrix with expectation X S Y^T and independent Poisson or Bernoulli entries using the fastRG algorithm of Rohe et al. (2017) https://www.jmlr.org/papers/v19/17-128.html. The algorithm first samples the number of edges and then puts them down one-by-one. As a result it is O(m) where m is the number of edges, a dramatic improvement over element-wise algorithms that which require O(n^2) operations to sample a random graph, where n is the number of nodes.
Major changes
- This release fixes a long-standing inconsistency in how degrees are counted, which resulted in sampling twice as many edges as desired in
undirected_factor_model(). See below for details (#19). This also caused population singular values for undirected factors models to be off by a factor of 2 (#31).
Breaking changes
- Specifying both
kandBindcsbm()andsbm()now results in an error. You should only specify one of these arguments. - It is now possible to specify the precise number of nodes in each block of a
dcsbm()(and subclassessbm()andplanted_partition()) via theblock_sizesargument. This makes it easier to construct blockmodels with exactly repeated eigenvalues. Additionally, the default behavior is now to use this argument and to balance block sizes as evenly as possible. Previously, the default behavior was to sample blocks memberships with equal probability.
Non-breaking changes
- Added
vignette("consistency")demonstrating how to check consistency of spectral estimators usingfastRGfor sampling and population spectra computations (#33, #43)
Details about degree over-sampling bug and the fix
The fastRG sampling algorithm, as implemented in sample_edgelist.matrix(), is fundamentally a sampler for asymmetric, directed networks with conditional expectation $\mathbb E[A \mid X, S, Y] = X S Y^\top \in \mathbb R^{n_1 \times n_2}$. That is, you can think of the sampler as a very efficient procedure for iterating through $i = 1, ..., n_1$ and $j = 1, ..., n_2$ and sampling from a Poisson with rate $(X S Y^\top)_{ij}$.
However, we would also like to use this same sampler to sample from undirected networks. In an undirected networks, the conditional expectation $\mathbb E[A \mid X, S] = X S X^\top \in \mathbb R^{n \times n}$ is a square matrix with $(X S X^\top)_{ij} = (X S X^\top)_{ji}$. To sample from this matrix, it's typical to sample the upper triangle of $A$ from a Poisson with rate $(X S X^\top)_{ij}$ for all $1 \le i \le j \le n$, and then fill the lower triangle of $A$ to make $A$ symmetric.
Since the fastRG algorithm samples $A_{ij}$ for all $i, j$, not just the upper triangle of $A$, we use a trick to sample from undirected networks. First, we force the conditional expectation to be symmetric by symmetrizing $S$. Then, we still sample for all $i, j$. That is, to set $A_{ij}$ we sample once from a Poisson with rate $(X S X^\top)_{ij}$ and once from a Poisson with rate $(X S X^\top)_{ji}$ (these rates are equal by symmetry!). Then we set $A_{ij} = A_{ji}$ to the sum of these Poisson random variables. The issue is that this doubles the expected value of $A_{ij} = A_{ji}$ and so we sample twice as many edges as we should. Up until this release of fastRG, we've unfortunately been doing this double sampling in undirected networks (#19).
In this release, we fix this over-sampling. The key is that we divide $S$ by two at sampling time. We do not modify $S$ at all in the undirected_factor_model()! You can always use $X S X^\top$ to compute the expected value of $A$. This new change *only affects sampling*.
Show all changes in 0.4.0Hide the rest of the changes in 0.4.0
That is, instead of passing the $S$ from an undirected_factor_model() to the sampler sample_edgelist.matrix(), we pass $S / 2$ (see sample_edgelist.undirected_factor_model()). This fixes double sampling on the off-diagonal of $A$. The downside is that we're now undersampling by half the diagonal of $A$. I'm assuming that for most use cases this doesn't matter. We could correct for this undersampling of the diagonal of $A$, so please open an issue if self-loops are important to your project.
As a consequence of this change, $A$ and $\mathbb E[A | X, S]$ show now be on the same scale, rather than off by a factor of 2. Importantly, the spectrums should match up now, so you can now use fastRG to check how closely you're recovering the spectrum of the your model. See vignette("consistency") for a quick demonstration showing consistency of spectral estimates.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
- ERROR12 OK, 1 ERROR2026-06-08
- OK14 OK2026-03-10
Documentation
- Help pages
- 23 (1 internal)
- Examples that run
- 100%18 run in a plain check
- Exported functions with examples
- 89%
- Documented parameters
- 100%
- Return-value docs
- 95%
- Help pages citing references
- 30%
- consistency HTML
Downloads
Repository
- PRs merged (all time)
- 100%
- Median days to close, 50 most recently updated closed issues
- 133
- Median days to close, 50 most recently updated closed PRs
- 0
Stars over time
Releases over time
Issues over time
PRs over time
9 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/rohelab/fastrg on 2026-10-18.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2025-12-05 · The repository has a site deploy workflow
pkgdown site last built 2025-12-05, before release 0.4.0 (2025-12-06)
Show all practicesHide 1 practice
Dependencies
Installing fastRG adds 34 packages (20 with compiled code, 37 MB of source tarballs). Heaviest: stringi 11 MB, ggplot2 6.0 MB, igraph 4.8 MB.
Code & Tests
People & History
Pick two releases to compare their code metrics.
- RR 4.6.0 released · 2026-04-24
- 0.4.0Latest
- 0.3.32025-07-24 · diff ↗
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 0.3.22023-08-21 · diff ↗ ·
added 4 exports
expectation, plot_dense_matrix, plot_expectation, plot_sparse_matrix - RR 4.3.0 released · 2023-04-21
- 0.3.1
- RR 4.2.0 released · 2022-04-22
- RR 4.1.0 released · 2021-05-18
- 0.3.02021-02-26
- RR 4.0.0 released · 2020-04-24
Package metadata
- First published
- 2021-02-26
- Total releases
- 5 / 5 yrs
- License
- MIT + file LICENSE OSI
- Download size
- 317 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("fastRG")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-20, which the citation names so these numbers can be found later. More on citing and the projects behind them.