1 Label propagation

A graph has 6 vertices. Vertex “a” has a value, rest vertices do not. The value of “a”" is propagrated to rest vertices.

library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
#---- build W, D, V ----------

W <-  matrix(ncol=6, nrow=6)
W[is.na(W)] <- 0
names <- c("a", "b", "c", "d", "e", "f")
colnames(W) <- names
rownames(W) <- colnames(W)

W["c", "a"] <- W["a", "c"] <- 1
W["b", "a"] <- W["a", "b"] <- 0.5
W["f", "a"] <- W["a", "f"] <- 0.5
W["e", "a"] <- W["a", "e"] <- 0.5
W["e", "b"] <- W["b", "e"] <- 0.4
W["d", "b"] <- W["b", "d"] <- 0.4


g <- graph_from_adjacency_matrix(W, mode =  "undirected", weighted = T)
E(g)$label <- E(g)$weight


# assign values for each vertex
V <- c(7,0,0,0,0,0)

V(g)$label <- paste(names, V)
E(g)$label.color <- "orange"
V(g)$label.color <- "red"
V(g)$color <- "white"
V(g)$frame.color <- "grey"


plot(g)

# create Degree matrix from degree
D <- degree(g)
D
## a b c d e f 
## 4 3 1 1 2 1
D <- diag(D)


#----- label propagration ----------

Y0 <- as.matrix(V)
Y0
##      [,1]
## [1,]    7
## [2,]    0
## [3,]    0
## [4,]    0
## [5,]    0
## [6,]    0
Yt <- Y0
for(i in 1:20){
  Yt_1 <- solve(D) %*% W %*% Yt
  Yt_1[1,1] <- 7
  Yt <- Yt_1
  print(Yt)
  V(g)$label <- paste(names, round(as.vector(Yt), 3))
  plot(g)
}
##          [,1]
## [1,] 7.000000
## [2,] 1.166667
## [3,] 7.000000
## [4,] 0.000000
## [5,] 1.750000
## [6,] 3.500000

##           [,1]
## [1,] 7.0000000
## [2,] 1.4000000
## [3,] 7.0000000
## [4,] 0.4666667
## [5,] 1.9833333
## [6,] 3.5000000

##          [,1]
## [1,] 7.000000
## [2,] 1.493333
## [3,] 7.000000
## [4,] 0.560000
## [5,] 2.030000
## [6,] 3.500000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5120000
## [3,] 7.0000000
## [4,] 0.5973333
## [5,] 2.0486667
## [6,] 3.5000000

##          [,1]
## [1,] 7.000000
## [2,] 1.519467
## [3,] 7.000000
## [4,] 0.604800
## [5,] 2.052400
## [6,] 3.500000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5209600
## [3,] 7.0000000
## [4,] 0.6077867
## [5,] 2.0538933
## [6,] 3.5000000

##          [,1]
## [1,] 7.000000
## [2,] 1.521557
## [3,] 7.000000
## [4,] 0.608384
## [5,] 2.054192
## [6,] 3.500000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5216768
## [3,] 7.0000000
## [4,] 0.6086229
## [5,] 2.0543115
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217246
## [3,] 7.0000000
## [4,] 0.6086707
## [5,] 2.0543354
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217341
## [3,] 7.0000000
## [4,] 0.6086898
## [5,] 2.0543449
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217380
## [3,] 7.0000000
## [4,] 0.6086937
## [5,] 2.0543468
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217387
## [3,] 7.0000000
## [4,] 0.6086952
## [5,] 2.0543476
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217390
## [3,] 7.0000000
## [4,] 0.6086955
## [5,] 2.0543477
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086956
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086956
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086956
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086957
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086957
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086957
## [5,] 2.0543478
## [6,] 3.5000000

##           [,1]
## [1,] 7.0000000
## [2,] 1.5217391
## [3,] 7.0000000
## [4,] 0.6086957
## [5,] 2.0543478
## [6,] 3.5000000

Home Page