You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fastRG::sbm without setting expected_degree is doubling the number of edges that should be there. #19
library(fastRG)
library(magrittr)
n = 1000
pop = n/2
a = .1
b = .05
B = matrix(c(a,b,b,a), nrow = 2)
b_model = fastRG::sbm(n = n, k =2,
B = B, edge_distribution = "bernoulli")
b_model %>%
sample_sparse(poisson_edges = F) %>%
rowSums %>% mean
pop*a + pop*b # this should be average degree
Dividing B by two fixes the problem:
b_model = fastRG::sbm(n = n, k =2,
B = B/2, edge_distribution = "bernoulli")
b_model %>%
sample_sparse(poisson_edges = F) %>%
rowSums %>% mean
Perhaps we are symmetrizing the edges at some point... this would double the number of edges.
This is an intentional choice. If you want to count "undirected" edges you should just consider the upper triangle here. That is, the edge count is based on the actual edges in the graph rather the elements in the sparse matrix representation of the graph. I spent a lot longer than I anticipated running into confusing inconsistencies between the undirected and directed samplers until I settled on this convention, and am pretty convinced it is the right way to implement things.
If you want to specify E[A] for an undirected SBM according to row means, we can consider adding an option for that, but I don't think we should call rowMeans(E[A]) the average degree.
Activity
alexpghayes commentedon Jun 29, 2021
This is an intentional choice. If you want to count "undirected" edges you should just consider the upper triangle here. That is, the edge count is based on the actual edges in the graph rather the elements in the sparse matrix representation of the graph. I spent a lot longer than I anticipated running into confusing inconsistencies between the undirected and directed samplers until I settled on this convention, and am pretty convinced it is the right way to implement things.
If you want to specify E[A] for an undirected SBM according to row means, we can consider adding an option for that, but I don't think we should call rowMeans(E[A]) the average degree.
Created on 2021-06-29 by the reprex package (v2.0.0)
alexpghayes commentedon Jun 29, 2021
Crap there's some inconsistency in edge counting. Will resolve.
Created on 2021-06-29 by the reprex package (v2.0.0)
Correctly count possible undirected edges
alexpghayes commentedon Jun 29, 2022
Undirected edge, degree and density counts should now be consistent. Example below.
Created on 2022-06-29 by the reprex package (v2.0.1.9000)
More consistency with degree/density scaling for undirected graphs (#27)
alexpghayes commentedon Nov 10, 2025
Okay, so I had a moment of confusion about upper triangles the last time I tried to sort this out. I think the confusion arose because:
are all slightly different computations that need to be considered slightly differently when thinking about directed vs undirected edges.
alexpghayes commentedon Nov 10, 2025
Fix coming in #44. TL;DR: population spectrums and edge counts have been off by a factor of two for a while
Fixes #19 for real. Closes #43. Closes #33. Closes #31.
Fix #19 for real and document extensively