Created
March 26, 2013 01:43
-
-
Save pedroj/5242440 to your computer and use it in GitHub Desktop.
watts_strogatz_SW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# Illustration of the Small-world property in the Watts-Strogatz model. | |
#------------------------------------------------------------------------------- | |
library(igraph) | |
set.seed(1) | |
avg.stat <- function(nei, p) { | |
result <- replicate(1000, { | |
wsg <- watts.strogatz.game(1, 100, nei, p) | |
c(average.path.length(wsg), | |
transitivity(wsg)) | |
}) | |
apply(result, 1, quantile, probs = c(0.5, 0.05, 0.95)) | |
} | |
nei <- 6 | |
p <- 2 ^ -seq(0, 10, len = 21) | |
result <- sapply(p, avg.stat, nei = nei) | |
result <- t(result / rep(avg.stat(nei, 0)[1,], each = 3)) | |
par(mar=c(3.2, 2, 0.2, 0.2), mgp=c(2, 1, 0)) | |
matplot(p, result, type = "l", log = "x", xaxt = "n", ylab = "", | |
lty = rep(c(1,2,2),2), col=rep(c(1,2), each=3)) | |
axis(1, at = 2 ^ -(0:10), | |
labels = c(1, parse(text = paste(2, 1:10, sep = "^-", | |
collapse = ";")))) | |
legend("bottomleft", c("average path length", "clustering coefficient"), | |
lty = 1, col = c(1, 2)) | |
#------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment