Last active
August 29, 2015 14:05
-
-
Save shirayuca/4af16341509466a9be13 to your computer and use it in GitHub Desktop.
This file contains 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
########## igraphパッケージの watts.strogatz.gameを使って、ランダム性 p の変化を見ていきます。 | |
library(igraph) | |
##### p=0 | |
g0 <- watts.strogatz.game(1, 100, 2, 0, loops=FALSE, multiple=FALSE) | |
# スモールワールド・ネットワークを作成 | |
# 1次元格子, 頂点は100個、2つ先の頂点まで結合, p=0, ループなし, 多重辺なし | |
plot(g0) | |
dev.off() | |
average.path.length(g0) | |
# 平均経路長 | |
shortest.paths(g0) | |
# 最短距離マトリックス | |
get.shortest.paths(g0, 1, to = 30) | |
# 最短経路 | |
# g0のネットワーク, 始点となる頂点ID, 終点となる頂点ID, 有向グラフの場合は mode ="out" | |
g0_t <- transitivity(g0, type="local") | |
# 頂点ごとのクラスター係数算出 | |
g0_t[which(g0_t == "NaN")] <-0 | |
# 次数が0または1の頂点はNaNになるため0に置き換える | |
mean(g0_t) | |
# 頂点ごとのクラスター係数の平均(ネットワーク全体のクラスター係数) | |
##### p=0.2 | |
g1 <- watts.strogatz.game(1, 100, 2, 0.2, loops=FALSE, multiple=FALSE) | |
plot(g1, layout=layout.circle) | |
dev.off() | |
average.path.length(g1) | |
g1_t <- transitivity(g1, type="local") | |
g1_t[which(g1_t == "NaN")] <-0 | |
mean(g1_t) | |
##### p=1 | |
g2 <- watts.strogatz.game(1, 100, 2, 1, loops=FALSE, multiple=FALSE) | |
plot(g2, layout=layout.circle) | |
dev.off() | |
average.path.length(g2) | |
g2_t <- transitivity(g2, type="local") | |
g2_t[which(g2_t == "NaN")] <-0 | |
mean(g2_t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment