fastRG quickly samples a broad class of network models known as generalized random product graphs. In particular, for matrices X, S and Y, fastRG samples a matrix A with expectation X S Y^T where individual entries are Poisson distributed. We recommend that you think of A as the adjacency matrix for a graph (or a multi-graph). Crucially, the sampling is O(m), where m is the number of the edges in graph. Other algorithms are O(n^2), where n is the number of nodes in the network. For additional details, see the paper.

## Installation

fastRG is not yet on CRAN. You can install the development version with:

# install.package("devtools")
devtools::install_github("RoheLab/fastRG")

## Example Usage

The easiest way to use fastRG is to use wrapper functions that sample from popular graph models. For example, to sample from an Erdos-Renyi graph n = 1,000,000 nodes and expected degree of five, we can use the erdos_renyi() function.

We strongly advise that you always set avg_deg, as it is easy to request very large and dense graphs without this scaling.

library(fastRG)

A <- erdos_renyi(n = 10^6, avg_deg = 5)

By default we always get a Matrix::sparseMatrix(), but we can also ask for the graph as an edgelist as well.

el <- erdos_renyi(n = 1000, avg_deg = 5, return_edge_list = TRUE)
#>      from  to
#> [1,]  207 798
#> [2,]  446 639
#> [3,]   78 133
#> [4,]  548 457
#> [5,]  320 785
#> [6,]  414 183

This results in a fast way to create igraph objects using igraph::graph_from_edgelist().

g <- igraph::graph_from_edgelist(el)
g
#> IGRAPH 92fba58 D--- 1000 4978 --
#> + edges from 92fba58:
#>  [1] 207-> 798 446-> 639  78-> 133 548-> 457 320-> 785 414-> 183 242-> 750
#>  [8] 328-> 416 264-> 212 787-> 724 824-> 840 973-> 330 529-> 344 636-> 730
#> [15] 658-> 161 330-> 377 881-> 665  64-> 312 807-> 253 478-> 336  26-> 403
#> [22] 948-> 750 749-> 170 329-> 774 943-> 942 223-> 179 463-> 768 628-> 576
#> [29] 428-> 638 206-> 983 244-> 148 145-> 369 777->  24 777-> 323 436-> 636
#> [36] 853-> 735 595-> 111  35-> 823 376-> 234   7-> 526 329->1000 770-> 593
#> [43] 118-> 924 294-> 752 157-> 677 319-> 661 124-> 884 673-> 614 220-> 265
#> [50] 523-> 617 280->  78 520-> 363 564-> 350 876->  64 448-> 631 248-> 186
#> [57] 396-> 989 643-> 703 552-> 964 789->  53 111-> 535 393-> 917 507->  22
#> + ... omitted several edges

## Other languages

The fastRG sampler has been implemented in Python here.