Skip to content

fastRG

0.4.0Package record

Sample Generalized Random Dot Product Graphs in Linear Time

0packages dependsuggested by 1
3.3Kdownloads / year
43.9%test coverage
13/13flavors OK

Overview

About

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.

Changes in 0.4.0

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 k and B in dcsbm() and sbm() 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 subclasses sbm() and planted_partition()) via the block_sizes argument. 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 using fastRG for 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

CRAN checks
13OK
Slowest check: 4.5 min · r-oldrel-windows-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK13 OK2026-06-09
  • ERROR12 OK, 1 ERROR2026-06-08
  • OK14 OK2026-03-10
Advisories

none known

Documentation

In release 0.4.0
READMEYes · 675 wordsVignettesYes · 1 · dynamicNEWSYes · 100% structured · mentions 0.4.0Citation fileNoWebsiteYes · pkgdown
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%
Vignettes (1)

Downloads

3.3K
CRAN downloads in the past year
Rank #10,702 · ~9/day · ~276/mo
Daily download trend is not available in this view yet.
40430 days
96390 days
3.3K1 year
Compare downloads with other packages →
Also on80 r2u8 autocran

Repository

5Stars
0Forks
8Open issues
0Open PRs
4Releases
222Commits
4Commit identities
graph-samplinglatent-factorsadjacency-matrix
222 commits · Last activity 2025-12-05 · 0% stars, 30d
Responsiveness
How these are sampled
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

2023-08-02 · 52026-07-07 · 5
PracticesBeta

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.

Continuous integration (2)
GitHub ActionsR CMD check workflow

The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel

Docs source (4)
README.Rmdpkgdown

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)

Coverage (1)
Coverage reporting (Codecov)
CRAN release process (1)
cran-comments.md
Show all practicesHide 1 practice
Lint, format, editor (1)
RStudio project
How this is detected·Detection ruleset v3 (2026-09-26)

Dependencies

Declared dependencies
17 external dependencies (excludes base and recommended)

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.

Depends (1)
Matrix
LinkingTo (0)
none
Enhances (0)
none
Reverse dependencies
0direct
0indirect
Suggested by 1
Suggests, most downloaded first

People & History

People (5)
Author, Maintainer since 0.3.0 (2021), Copyright holder
Author, Copyright holder
Author
Releases (5)

Pick two releases to compare their code metrics.

  • R
    R 4.6.0 released · 2026-04-24
  • 0.4.0Latest
    record
    2025-12-06 · current release · diff ↗
  • 0.3.3
    record
    2025-07-24 · diff ↗
  • R
    R 4.5.0 released · 2025-04-11
  • R
    R 4.4.0 released · 2024-04-24
  • 0.3.2
    record
    2023-08-21 · diff ↗ ·
    added 4 exports
    expectation, plot_dense_matrix, plot_expectation, plot_sparse_matrix
  • R
    R 4.3.0 released · 2023-04-21
  • 0.3.1
    record
    2022-06-30 · diff ↗ ·
    added 4 exports
    chung_lu, directed_dcsbm, mmsbm, overlapping_sbm
  • R
    R 4.2.0 released · 2022-04-22
  • R
    R 4.1.0 released · 2021-05-18
  • 0.3.0
    record
    2021-02-26
  • R
    R 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")
Hayes, A., Binkiewicz, N., Han, X., Rohe, K., & Tao, J. (2025). fastRG: Sample Generalized Random Dot Product Graphs in Linear Time (Version 0.4.0) [Computer software]. https://doi.org/10.32614/CRAN.package.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.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for fastRG version 0.4.0 [Data set]. HJJB, LLC. Data release v2026-10-20. https://doi.org/10.5281/zenodo.21843040

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.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy