ååã®è¨äºã«å¼ãç¶ã主ã«{igraph}ã®åé¢æ°ã§éã³ãªããã°ã©ãçè«ã»ãããã¯ã¼ã¯åæãå¦ã¶ãã®ã·ãªã¼ãºã§ãããä»åã¯æ§ã ãªãã¼ãéã®ç¹å¾´éã«ã¤ãã¦è¦ã¦ã¿ã¾ãããã¡ããä»åãåèæç®ã¯ãã¡ãã
ãããã¯ã¼ã¯åæ (Rã§å¦ã¶ãã¼ã¿ãµã¤ã¨ã³ã¹ 8)
- ä½è : é´æ¨åª,éæå²
- åºç社/ã¡ã¼ã«ã¼: å ±ç«åºç
- çºå£²æ¥: 2009/09/25
- ã¡ãã£ã¢: åè¡æ¬
- è³¼å ¥: 5人 ã¯ãªãã¯: 62å
- ãã®ååãå«ãããã° (9件) ãè¦ã
ãã¼ã¿ã»ããã¯ååé©å½ã«çæããã°ã©ãã®ãã®ã¨ãC elegansã¨ãããã«ä»¥å使ã£ããã¬ã»ãã¼ã©ãã«ãã®äººç©ç¸é¢å³ã対æ¯ã®ããã«ä½µç¨ãããã¨æãã¾ãã
æççµè·¯é·ã¨ãã¤ã¯ã¹ãã©æ³
ååé©å½ã«çæããã°ã©ããä»åã使ã£ã¦ã¿ã¾ãããã
> d [,1] [,2] [1,] 1 8 [2,] 3 1 [3,] 1 2 [4,] 6 2 [5,] 3 8 [6,] 5 3 [7,] 6 3 [8,] 8 3 [9,] 3 4 [10,] 8 4 [11,] 2 5 [12,] 4 5 [13,] 8 5 [14,] 1 6 [15,] 2 6 [16,] 4 6 [17,] 5 6 [18,] 4 7 [19,] 6 7 > library(igraph) > g0<-graph.edgelist(as.matrix(d),directed=T) > set.seed(71) > plot(g0,layout=layout.fruchterman.reingold) # ããã±ã¼ã¸ãã¢ãããã¼ãããã®ã§é è²ãååã¨éã
ãããªæãã«ãªãã¾ããã§ãæåã®ãé¡ã¯ãæççµè·¯é·ã(shortest path length)ãä¸ã®ãããããè¦ãã°ä¸ç®çç¶ã ã¨æãã¾ãããä¾ãã°ãã¼ã1ãã2ã¸ã®æççµè·¯é·ã¯ã©ãè¦ã¦ã1ã§ããï¼1ã¨ãã¸ã§å°éããï¼ãä¸æ¹ã§ããã¼ã2ãã8ã¯3ãããã¾ãï¼3ã¨ãã¸ãããï¼ãæåã°ã©ãã ã¨å½ç¶ãªããè¿åãããããªå½¢ã§ãããããã¼ãããå¥ã®ãã¼ãã¸ã¨å°éã§ããªããã¨ãããã®ã§ãã°ã©ãã大è¦æ¨¡ã«ãªã£ãå ´åã®ãã®è¨ç®ã¯ã¡ãã£ã¨åä»ã§ãã
ããã§ãæççµè·¯é·ã®ç®åºæ³ã¨ãã¦ããç¨ããããã®ããã¤ã¯ã¹ãã©æ³ãWikipedia日本語版記事ã§ã¯ãããªã¢ããã¸ã¼ã§èª¬æããã¦ãã¾ãã
ç°¡åã®çºãG=(V,E)ã®åé ç¹v,wâVã«å¯¾ããvã¨wãçµã¶è¾ºã¯æ大ä¸ã¤ãããªãã¨ããã vã¨wãçµã¶è¾ºãããã°ããã®è¾ºã(v,w)ã¨æ¸ãã
æççµè·¯åé¡ã¯ããã¼çã¨ç´ãç¨ãã¦è§£ããã¨ãåºæ¥ãã ã¾ããã¼çãé ç¹ãç´ã辺ã«ããã°ã©ããå·¥ä½ããã ã°ã©ããæ¿ã®ä¸ã«ç½®ããã¹ã¿ã¼ãã®é ç¹ã«ããããã¼çã ããã¤ã¾ãã ã°ã©ããç½®ããã¦ããæ¿ãåãé¤ãã¨ãã°ã©ãã¯èªç±è½ä¸ãå§ãããã ã¹ã¿ã¼ãã«ããããã¼çãæã£ã¦ããã®ã§ãã¹ã¿ã¼ãå°ç¹ããè¿ããã¼çããé ã«è½ä¸ãæ¢ã¾ãã ã´ã¼ã«ã«ããããã¼çãæ¢ã¾ã£ãã¨ããã´ã¼ã«ã«ããããã¼çã¯ã¹ã¿ã¼ãã«ããããã¼çã¾ã§ç´ã§ä¸ç´ç·ã§çµã°ãã¦ããã ãã®ç´ç·ãæççµè·¯ã§ããã
è½ä¸ãæ¢ã¾ã£ãé ç¹vã«å¯¾ããvãæ¯ãã¦ããé ç¹wãåå¨ããã wãvã®ãç´åã®é ç¹ãã¨å¼ã¶ãã¨ã«ããã 以ä¸ç°¡åã®ãããç´åã®é ç¹ã¯1ã¤ãããªãã¨ä»®å®ãã¦è©±ãé²ãããã ä¸è¬ã®å ´åãåæ§ã§ããã
ãã¤ã¯ã¹ãã©ã®ã¢ã«ã´ãªãºã ã¯ãä¸è¿°ã®è§£æ³ãã³ã³ãã¥ã¼ã¿ä¸ã§ã·ãã¥ã¬ã¼ããããã®ã§ããã ã°ã©ãG=(V,E)ãã¹ã¿ã¼ãã¨ãªãé ç¹sãããã³å辺eã®é·ãlength(e)ãå ¥åã¨ãã¦ä¸ããããã¨ã ãã®ã¢ã«ã´ãªãºã ã¯ä¸è¿°ã®è§£æ³ãã·ãã¥ã¬ã¼ããããè½ä¸ããåæ¢ããé ç¹ããé ã«ããã®é ç¹ã®ç´åã®é ç¹ãä½ã§ããããåºåããã ã´ã¼ã«ã¨ãªãé ç¹ã®ãè½ä¸ããåæ¢ããã¨ããã§ããã¤ã¯ã¹ãã©ã®ã¢ã«ã´ãªãºã ãæ¢ããã°ã ãã¨ã¯ã´ã¼ã«ããé ã«ãç´åã®é ç¹ãããã«ãã®ç´åã®é ç¹ã¨ãã©ã£ã¦ãããã¨ã§ã ã´ã¼ã«ã¨ã¹ã¿ã¼ããã¤ãªãæççµè·¯(ã®ä¸ã¤)ãæ±ãããã¨ãã§ããã
ããããã¯ã¼ã¯åæãpp.22-25ã«ã¯ãã®ã¢ã«ã´ãªãºã ã追ã£ãRã¹ã¯ãªãããè¼ã£ã¦ããã®ã§ããã®ã¾ã¾åçµãã¦å®è¡ãã¦ã¿ã¾ãã
> dijkstra<-function(matrix,vertex){ + L<-matrix + L[which(L==0)]<-Inf + diag(L)<-0 + n<-nrow(matrix) + d<-rep(Inf,n) + d[vertex]<-0 + M<-1:n + M<-M[-vertex] + i<-vertex + while(length(M)>0){ + for (j in 1:n) + d[j]<-min(d[j],d[i]+L[i,j]) + i<-M[which(d[M]==min(d[M]))[1]] + M<-M[-which(M==i)] + } + d + } > A0<-get.adjacency(g0) > dijkstra(as.matrix(A0),1) # ãã¼ã1ããã®è·é¢ [1] 0 1 2 2 2 1 2 1 > dijkstra(as.matrix(A0),8) # ãã¼ã8ããã®è·é¢ [1] 2 3 1 1 1 2 2 0
ããããã§è¦ãéãã®çµæã«ãªã£ã¦ãããã¨ãåããã¾ãããã¤ã¯ã¹ãã©æ³ã¯ã¨ãã¸ã®éã¿ä»ããéè² ã®æã«ã®ã¿ä½¿ããï¼ãã®ä¾ã§ã¯å
¨é¨éã¿ãçããå
¨ã¦1ã¨ãã¦ã¾ããï¼æ¹æ³ã§ããã®ä»ã®å ´åã«ã¯ãããã対å¿ããã¢ã«ã´ãªãºã ãããã¾ãã{igraph}ã®shortest.pathsé¢æ°ã¯ããããã®æ¡ä»¶ã«åããã¦æé©ã®ã¢ã«ã´ãªãºã ãèªåçã«é¸æããæççµè·¯é·ã®ç®åºã«ç¨ãã¾ãã
> gs0<-shortest.paths(g0,mode="out") # æåã°ã©ãã®å ´åã¯modeå¼æ°ã¯outãæå®ãã > gs0 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 0 1 2 2 2 1 2 1 [2,] 3 0 2 3 1 1 2 3 [3,] 1 2 0 1 2 2 2 1 [4,] 3 2 2 0 1 1 1 3 [5,] 2 2 1 2 0 1 2 2 [6,] 2 1 1 2 2 0 1 2 [7,] Inf Inf Inf Inf Inf Inf 0 Inf [8,] 2 3 1 1 1 2 2 0
èªåããåºã¦è¡ãã¨ãã¸ãæããªããã¼ã7ããã®æççµè·¯é·ãå
¨ã¦Infã«ãªã£ã¦ããç¹ã«æ³¨æãã¾ã1è¡ç®ã¨8è¡ç®ãä¸è¨ã®dijkstraé¢æ°ã¨åãçµæãä¸ãã¦ãããã¨ãåããã¾ãã
æççµè·¯é·ã¨å¯è¦å
ã¨ããã§ãååã®è¨äºã§ããã¤ãåæåã°ã©ãæç»ã¢ã«ã´ãªãºã ãåãä¸ãã¾ãããããã®ä¸ã§ä¾ãã°Fruchterman - Reingoldã¢ã«ã´ãªãºã ãªã©ã¯ããã¼ãéã®è·é¢ã«é¢é£ããããã«é
ç½®ãããã¨ãã話ããããã¨æãã¾ãããã®ãè·é¢ãã¯ãã¡ããæççµè·¯é·ã§ãã£ã¦ãä¾ãã°ãã¼ã1ããè¿ããªãã»ã©ãã¼ãã表ãåã大ãããªãããã«æç»ããã¨ãããªæãã«ãªãã¾ãã
> set.seed(71) > plot(g0,vertex.size=50/(gs0[1,]+0.5))
å¤å°ããã¾ãã§ãããæ¦ãããããä¸ã§ã®ãã¼ã1ã¾ã§ã®è·é¢ãè¿ããã¼ãã»ã©å¤§ããæç»ããã¦ããã®ãåãããã¨æãã¾ããåããã¨ãC elegansããã¬ã»ãã¼ã©ãã«ãã®ãã¼ã¿ã§ããã£ã¦ã¿ã¾ãããã
> g1<-read.graph("celegansneural.gml",format="GML") > g2<-read.graph("lesmis.gml",format="GML") > gs1<-shortest.paths(g1,mode="out") > gs2<-shortest.paths(g2,mode="out") > set.seed(71) > plot(g1,vertex.size=50/(gs1[1,]+0.5)) > set.seed(71) > plot(g2,vertex.size=50/(gs2[1,]+0.5))
ãã¼ã1ï¼æã大ããªåï¼ããããããä¸ã§è¦ã¦é¢ãã¦ããã»ã©ãæ¦ãã©ã®ãã¼ããå°ãããªã£ã¦ããã®ãåãããã¨æãã¾ããã¨ãããã¨ã§ãããã§ã¤ãã§ã«Fruchterman - Reingoldã¢ã«ã´ãªãºã ã®ç¹æ§ãä½ã¨ãªãåããã¾ãããã¨ãããã¨ã§ï¼ç¬ï¼ã