Description Usage Arguments Details Value References See Also Examples

View source: R/sample_tidygraph.R

There are two steps to using the `fastRG`

package. First,
you must parameterize a random dot product graph by
sampling the latent factors. Use functions such as
`dcsbm()`

, `sbm()`

, etc, to perform this specification.
Then, use `sample_*()`

functions to generate a random graph
in your preferred format.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ```
## S3 method for class 'directed_erdos_renyi'
sample_tidygraph(factor_model, ..., allow_self_loops = TRUE)
sample_tidygraph(
factor_model,
...,
poisson_edges = TRUE,
allow_self_loops = TRUE
)
## S3 method for class 'undirected_factor_model'
sample_tidygraph(
factor_model,
...,
poisson_edges = TRUE,
allow_self_loops = TRUE
)
## S3 method for class 'directed_factor_model'
sample_tidygraph(
factor_model,
...,
poisson_edges = TRUE,
allow_self_loops = TRUE
)
## S3 method for class 'undirected_erdos_renyi'
sample_tidygraph(
factor_model,
...,
poisson_edges = FALSE,
allow_self_loops = TRUE
)
## S3 method for class 'undirected_erdos_renyi'
sample_tidygraph(
factor_model,
...,
poisson_edges = FALSE,
allow_self_loops = TRUE
)
``` |

`factor_model` |
A |

`...` |
Ignored. Do not use. |

`allow_self_loops` |
Logical indicating whether or not
nodes should be allowed to form edges with themselves.
Defaults to |

`poisson_edges` |
Logical indicating whether or not
multiple edges are allowed to form between a pair of
nodes. Defaults to |

This function implements the `fastRG`

algorithm as
described in Rohe et al (2017). Please see the paper
(which is short and open access!!) for details.

A `tidygraph::tbl_graph()`

object that is possibly a
multigraph (that is, we take there to be multiple edges
rather than weighted edges).

When `factor_model`

is **undirected**:

1 | ```
- the graph is undirected and one-mode.
``` |

When `factor_model`

is **directed** and **square**:

1 | ```
- the graph is directed and one-mode.
``` |

When `factor_model`

is **directed** and **rectangular**:

1 | ```
- the graph is undirected and bipartite.
``` |

Note that working with bipartite graphs in `tidygraph`

is more
complex than working with one-mode graphs.

Rohe, Karl, Jun Tao, Xintian Han, and Norbert Binkiewicz. 2017. "A Note on Quickly Sampling a Sparse Matrix with Low Rank Expectation." Journal of Machine Learning Research; 19(77):1-13, 2018. https://www.jmlr.org/papers/v19/17-128.html

Other samplers:
`sample_edgelist.directed_erdos_renyi()`

,
`sample_edgelist.matrix()`

,
`sample_igraph.directed_erdos_renyi()`

,
`sample_sparse.directed_erdos_renyi()`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | ```
library(igraph)
library(tidygraph)
set.seed(27)
##### undirected examples ----------------------------
n <- 100
k <- 5
X <- matrix(rpois(n = n * k, 1), nrow = n)
S <- matrix(runif(n = k * k, 0, .1), nrow = k)
# S will be symmetrized internal here, or left unchanged if
# it is already symmetric
ufm <- undirected_factor_model(
X, S,
expected_density = 0.1
)
ufm
### sampling graphs as edgelists ----------------------
edgelist <- sample_edgelist(ufm)
edgelist
### sampling graphs as sparse matrices ----------------
A <- sample_sparse(ufm)
inherits(A, "dsCMatrix")
isSymmetric(A)
dim(A)
B <- sample_sparse(ufm, poisson_edges = FALSE)
inherits(B, "dsCMatrix")
isSymmetric(B)
dim(B)
### sampling graphs as igraph graphs ------------------
sample_igraph(ufm)
### sampling graphs as tidygraph graphs ---------------
sample_tidygraph(ufm)
sample_tidygraph(ufm, poisson_edges = FALSE)
##### directed examples ----------------------------
n2 <- 100
k1 <- 5
k2 <- 3
d <- 50
X <- matrix(rpois(n = n2 * k1, 1), nrow = n2)
S <- matrix(runif(n = k1 * k2, 0, .1), nrow = k1, ncol = k2)
Y <- matrix(rexp(n = k2 * d, 1), nrow = d)
fm <- directed_factor_model(X, S, Y, expected_in_degree = 2)
fm
### sampling graphs as edgelists ----------------------
edgelist2 <- sample_edgelist(fm)
edgelist2
### sampling graphs as sparse matrices ----------------
A2 <- sample_sparse(fm)
inherits(A2, "dgCMatrix")
isSymmetric(A2)
dim(A2)
B2 <- sample_sparse(fm, poisson_edges = FALSE)
inherits(B2, "dgCMatrix")
isSymmetric(B2)
dim(B2)
### sampling graphs as igraph graphs ------------------
# since the number of rows and the number of columns
# in `fm` differ, we will get a bipartite igraph here
# creating the bipartite igraph is slow relative to other
# sampling -- if this is a blocker for
# you please open an issue and we can investigate speedups
dig <- sample_igraph(fm)
is_bipartite(dig)
### sampling graphs as tidygraph graphs ---------------
sample_tidygraph(fm, poisson_edges = FALSE)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.