Comments (3)
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.
library(fastRG)
#> Loading required package: Matrix
library(magrittr)
n <- 1000
pop <- n / 2
a <- .1
b <- .05
B <- matrix(c(a, b, b, a), nrow = 2)
b_model <- sbm(
n = n, k = 2,
B = B, edge_distribution = "bernoulli"
)
A <- sample_sparse(b_model)
mean(rowSums(A)) # double counts undirected edges
#> [1] 156.269
mean(rowSums(triu(A))) # right way to count undirected edges in E[A]
#> [1] 78.194
pop * a + pop * b # expected "undirected edge degree"
#> [1] 75
Created on 2021-06-29 by the reprex package (v2.0.0)
from fastrg.
Crap there's some inconsistency in edge counting. Will resolve.
library(fastRG)
#> Loading required package: Matrix
library(magrittr)
n <- 1000
pop <- n / 2
a <- .1
b <- .05
B <- matrix(c(a, b, b, a), nrow = 2)
b_model <- sbm(
n = n, k = 2,
B = B, edge_distribution = "bernoulli"
)
A <- sample_sparse(b_model)
mean(rowSums(A)) # double counts undirected edges
#> [1] 156.845
mean(rowSums(triu(A))) # right way to count undirected edges in E[A]
#> [1] 78.479
pop * a + pop * b # expected "undirected edge degree"
#> [1] 75
model2 <- sbm(n = n, k = 2, B = B, edge_distribution = "bernoulli", expected_degree = 75)
A2 <- sample_sparse(model2)
mean(rowSums(A2)) # double counts undirected edges
#> [1] 76.393
mean(rowSums(triu(A2))) # right way to count undirected edges in E[A]
#> [1] 38.225
Created on 2021-06-29 by the reprex package (v2.0.0)
from fastrg.
Undirected edge, degree and density counts should now be consistent. Example below.
library(fastRG)
#> Loading required package: Matrix
library(magrittr)
n <- 1000
pop <- n / 2
a <- .1
b <- .05
B <- matrix(c(a, b, b, a), nrow = 2)
b_model <- sbm(
n = n, k = 2,
B = B, edge_distribution = "bernoulli"
)
# model display corrected, both expected degree and density
b_model
#> Undirected Stochastic Blockmodel
#> --------------------------------
#>
#> Nodes (n): 1000 (arranged by block)
#> Blocks (k): 2
#>
#> Traditional SBM parameterization:
#>
#> Block memberships (z): 1000 [factor]
#> Block probabilities (pi): 2 [numeric]
#> Edge distribution: bernoulli
#>
#> Factor model parameterization:
#>
#> X: 1000 x 2 [dgeMatrix]
#> S: 2 x 2 [dsyMatrix]
#>
#> Expected edges: 78329
#> Expected degree: 78.3
#> Expected density: 0.15681
A <- sample_sparse(b_model)
mean(rowSums(A)) # double counts undirected edges
#> [1] 155.641
mean(rowSums(triu(A))) # right way to count undirected edges in E[A]
#> [1] 77.876
sum(triu(A)) / choose(n, 2) # correct "undirected" density
#> [1] 0.1559079
pop * a + pop * b # expected "undirected edge degree"
#> [1] 75
model2 <- sbm(n = n, k = 2, B = B, edge_distribution = "bernoulli", expected_degree = 75)
A2 <- sample_sparse(model2)
mean(rowSums(A2)) # double counts undirected edges
#> [1] 155.995
mean(rowSums(triu(A2))) # right way to count undirected edges in E[A]
#> [1] 78.053
sum(triu(A)) / choose(n, 2) # correct "undirected" density
#> [1] 0.1559079
Created on 2022-06-29 by the reprex package (v2.0.1.9000)
from fastrg.
Related Issues (20)
- Test poisson_edges
- tmp_index is shorter than to_index sometimes, especially in small and degenerate blockmodels HOT 2
- Add blockmodel vignette once requisite models have been implemented
- Test multi-graphness of igraph and tidygraph representations?
- Release fastRG 0.3.0
- Add node contextualized stochastic blockmodel
- Bernoulli graphs can have p>1 HOT 7
- Blockmodels should graciously handle k = 1
- Automatic theta_out generation either not working or not informating user in directed_dcsbm
- Make sure nodes don't go missing as in the following
- Improve population svds/eigs/ASE documentation
- Use identifiable parameterization for overlapping models
- Release fastRG 0.3.1
- Be consistent with Poisson graphs about using weighted graphs versus multigraphs in `igraph` and `tidygraph` samplers
- Document singular value scaling for undirected graphs
- sbm() function not using possion_edges and allow_self_loops parameters
- A trick to compute the svd of the population regularized Laplacian with a single extra line of code
- Recover block memberships with dcsbm? HOT 4
- Release fastRG 0.3.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastrg.