Reputation: 1
I want to sample a bipartite graph on a given set of vertices rather than just giving the number of vertices of each type like in sample_bipartite(n1, n2, p). To be more precise, I want to simulate a graph with two groups of vertices and create a graph by sampling vertices within each group and across those groups of vertices. My current code is:
gw1 = sample_gnp(n1, p1, directed = FALSE, loops = FALSE)
n_e11=gsize(gw1)
E(gw1)$group <- rep(1,n_e11)
gw2 = sample_gnp(n2, p2, directed = FALSE, loops = FALSE)
n_e22=gsize(gw2)
E(gw2)$group <- rep(2,n_e22)
Next, I want to sample a bipartite graph between the vertices of gw1
and gw2
. Currently, I have written the following code to achieve this goal.
gb12 = sample_bipartite(g_n[1], g_n[2], p = p[1,2])
n_e12=gsize(gb12)
E(gb12)$group <- rep(12,n_e12)
gw12 = gw1 + gw2
gg12 <- gb12 %u% gw12
E(gg12)$group_1[is.na(E(gg12)$group_1)] <- 0
E(gg12)$group_2[is.na(E(gg12)$group_2)] <- 0
E(gg12)$group <- E(gg12)$group_1 + E(gg12)$group_2
This gives me a graph I desire somehow, but I am not sure I am doing the right thing technically. If I could use the vertex set from the first two graphs to sample a bipartite graph, it would be technically what I want. I would appreciate if I can get some guidance on this.
Upvotes: 0
Views: 49
Reputation: 25703
I want to simulate a graph with two groups of vertices and create a graph by sampling vertices within each group and across those groups of vertices
A graph that contains connections within the two groups as well is not bipartite, by definition.
You seem to be looking for sample_sbm()
, which is like sample_gnp()
, but we can specify a different p
for each pair of groups, as well as within each group. You can have any number of groups.
Recommended reading: https://en.wikipedia.org/wiki/Stochastic_block_model
Upvotes: 0