require(graphstats)
require(mclust)
require(ggplot2)

Here, we present the lse function, used for representing graphs in lower-dimensions.

Stochastic Blockmodel via Random Dot-Product Graph

We will apply LSE to a core-periphery SBM constructed from an RDPG. We start with latent vectors [0.85, 0] and [0.3, 0.4]. These make edge probability within block 1 approximately 0.75 (the core), and other edge probabilities approximately 0.25. The Adjacency Matrix is plotted below.

# Create latent vectors, and edge probability matrix.
block1 <- as.matrix(c(0.85, 0), nrow = 2)
block2 <- as.matrix(c(0.3, 0.4), nrow = 2)
block_probs <- matrix(c(t(block1) %*% block1,
                        t(block1) %*% block2,
                        t(block2) %*% block1,
                        t(block2) %*% block2), ncol = 2)

# Create SBM. Use higher edge probability if nodes are from same block.
set.seed(456)
n <- 100
block.sizes <- c(n/2, n/2)
blocks <- rep(c(1, 2), block.sizes)
g <- igraph::sample_sbm(n, block_probs, block.sizes)
gs.plot.plot_matrix(igraph::as_adjacency_matrix(g, sparse = FALSE),
                    legend.name="Connection",
                    ffactor = TRUE)

Embedding the Graph

Now, we call the function to embed the Laplacian matrix in R^2. Returned is an nx2 matrix. By plotting the data, we observe that the core-periphery structure translates well to Euclidean space.

# Embed graph into R^2.
dim <- 2
X <- lse(g, dim)
dat <- as.data.frame(X)

# Display.
p <- ggplot(dat) + geom_point(aes(x = V1, y = V2), color=blocks)
p + xlab("PC Score 1") + ylab("PC Score 2")


neurodata/graphstats documentation built on May 14, 2019, 5:19 p.m.